com.github.wwadge: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
Last Version

Last Version

1.0.3
Release Date

Release Date

Type

Type

jar
Description

Description

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

Download swagger-annotation-processor

How to add to project

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

Dependencies

provided (2)

Group / Artifact Type Version
io.swagger : swagger-codegen jar 2.2.7-eft
ch.qos.logback : logback-classic Optional jar 1.1.3

test (1)

Group / Artifact Type Version
junit : junit jar 4.12

Project Modules

There are no modules declared in this project.

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