swap - Swagger Annotation Processor

Creates swagger classes in the compile phase, i.e. in your IDE, in Maven, etc.

License

License

Categories

Categories

Swagger Program Interface REST Frameworks
GroupId

GroupId

com.github.wwadge
ArtifactId

ArtifactId

swagger-annotation-processor-parent
Last Version

Last Version

1.0.3
Release Date

Release Date

Type

Type

pom
Description

Description

swap - Swagger Annotation Processor
Creates swagger classes in the compile phase, i.e. in your IDE, in Maven, etc.
Project URL

Project URL

https://github.com/wwadge/swagger-annotation-processor
Source Code Management

Source Code Management

https://github.com/wwadge/swagger-annotation-processor

Download swagger-annotation-processor-parent

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.wwadge/swagger-annotation-processor-parent/ -->
<dependency>
    <groupId>com.github.wwadge</groupId>
    <artifactId>swagger-annotation-processor-parent</artifactId>
    <version>1.0.3</version>
    <type>pom</type>
</dependency>
// https://jarcasting.com/artifacts/com.github.wwadge/swagger-annotation-processor-parent/
implementation 'com.github.wwadge:swagger-annotation-processor-parent:1.0.3'
// https://jarcasting.com/artifacts/com.github.wwadge/swagger-annotation-processor-parent/
implementation ("com.github.wwadge:swagger-annotation-processor-parent:1.0.3")
'com.github.wwadge:swagger-annotation-processor-parent:pom:1.0.3'
<dependency org="com.github.wwadge" name="swagger-annotation-processor-parent" rev="1.0.3">
  <artifact name="swagger-annotation-processor-parent" type="pom" />
</dependency>
@Grapes(
@Grab(group='com.github.wwadge', module='swagger-annotation-processor-parent', version='1.0.3')
)
libraryDependencies += "com.github.wwadge" % "swagger-annotation-processor-parent" % "1.0.3"
[com.github.wwadge/swagger-annotation-processor-parent "1.0.3"]

Dependencies

provided (1)

Group / Artifact Type Version
ch.qos.logback : logback-classic Optional jar 1.1.3

test (1)

Group / Artifact Type Version
junit : junit jar 4.12

Project Modules

  • impl
  • swagger-annotation-processor-interface

Given an annotation somewhere in your code, this will generate all the swagger classes by means of an APT processor.

How to use?

  • Add to gradle dependencies (see below)

  • Add @EnableSwagger:

    @EnableSwagger(scheme = EnableSwagger.Scheme.APIS)
    package com.foo.account;

    
    import com.github.wwadge.swaggerapt.EnableSwagger;
  • Add swagger.yml and swagger-config.json in src/main/resources. For example you can use this for model objects:
    {
      "dateLibrary": "java8",
      "modelPackage" : "com.foo.model",
      "apiPackage" : "com.foo.account.controller",
      "useBeanValidation": "true",
      "delegatePattern": "true",
      "typeMappings":{"Boolean":"boolean"},
      "modelNamePrefix": "",
      "importMappings": {
        "MonetaryAmount": "org.javamoney.moneta.Money",
        "EntityId": "com.foo.common.entities.EntityId",
        "QueryDslBinder": "com.foo.common.util.QueryDslBinder",
        "YearMonth": "java.time.YearMonth",
        "InetAddress": "java.net.InetAddress",
        "CurrencyUnit": "javax.money.CurrencyUnit",
        "Email": "javax.validation.constraints.Email"
      }
    }

Gradle example that also configures for use with querydsl apt which means you can use @QueryEntity in your swagger template. Every time gradle or Intellij tries to compile, it will generate the swagger files followed by running the Querydsl APT on the resultant files (obviously querydsl is completely optional here).

apply plugin: 'java'
apply plugin: 'idea'


configurations {
    swagger
    querydsl
    testCompile.extendsFrom compile
}

sourceSets {
    swagger {
        java {
            srcDirs = [sourceSets.main.java.srcDirs, swagger.java.outputDir] // look to find the @EnableSwagger annotation
        }
    }
    querydsl {
        java {
            srcDirs = ["$buildDir/classes/java/swagger"] // look at where swagger generated code (+anything else)
        }
    }


    main{
        java {
            srcDirs += [sourceSets.querydsl.java.srcDirs, sourceSets.swagger.java.outputDir]
        }
    }

    sourceSets.swagger.compileClasspath +=   project.configurations.compile
    sourceSets.querydsl.compileClasspath += project.configurations.compile  + sourceSets.swagger.compileClasspath
    sourceSets.main.compileClasspath += sourceSets.querydsl.compileClasspath + sourceSets.swagger.compileClasspath+ swagger.output + querydsl.output
    sourceSets.test.compileClasspath += sourceSets.main.compileClasspath + sourceSets.querydsl.compileClasspath + sourceSets.swagger.compileClasspath+ swagger.output + querydsl.output
}





compileSwaggerJava {
    options.annotationProcessorPath = configurations.swagger
    options.compilerArgs +=  ["-proc:only"]
}

compileQuerydslJava {
    options.annotationProcessorPath = configurations.querydsl
    options.compilerArgs +=  ["-proc:only"]
}
compileJava {
    options.annotationProcessorPath = null
}

compileTestJava {
    options.annotationProcessorPath = null
}

//compileTestJava.dependsOn(compileJava)
compileJava.dependsOn([swaggerClasses, querydslClasses])
querydslClasses.mustRunAfter(swaggerClasses)



idea {
    module {
        // Marks the already(!) added srcDir as "generated"
        generatedSourceDirs += [sourceSets.swagger.java.outputDir, sourceSets.querydsl.java.outputDir]
        sourceDirs += [sourceSets.swagger.java.outputDir, sourceSets.querydsl.java.outputDir]
    }
}

clean{
    delete sourceSets.swagger.java.outputDir
    delete sourceSets.querydsl.java.outputDir

}


dependencies{
    // this little snippet gets the top level folder by asking git to avoid hard-coding paths
    def getTopLevelCode = { ->
        def stdout = new ByteArrayOutputStream()
        exec {
            commandLine 'git', 'rev-parse', '--show-toplevel'
            standardOutput = stdout
        }
        return stdout.toString().trim()
    }


    apply from: "$getTopLevelCode/gradle-common/versions.gradle"


    compile "com.github.wwadge:swagger-annotation-processor-interface:${swaggerAnnotationProcessor}"
    swagger "com.github.wwadge:swagger-annotation-processor:${swaggerAnnotationProcessor}"
    compileOnly "com.github.wwadge:swagger-annotation-processor:${swaggerAnnotationProcessor}"
    compileOnly "io.swagger:swagger-codegen:${swaggerCodegenVersion}"
    swagger "io.swagger:swagger-codegen:${swaggerCodegenVersion}"
    querydsl group: 'com.querydsl', name: 'querydsl-apt', version:'4.1.3'
    querydsl group: 'com.querydsl', name: 'querydsl-apt', version:'4.1.3', classifier: "general"
}

Versions

Version
1.0.3
1.0.2
1.0.1
1.0.0