swap - Swagger Annotation Processor

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

Лицензия

Лицензия

Категории

Категории

Swagger Межпрограммное взаимодействие REST Frameworks
Группа

Группа

com.github.wwadge
Идентификатор

Идентификатор

swagger-annotation-processor-parent
Последняя версия

Последняя версия

1.0.3
Дата

Дата

Тип

Тип

pom
Описание

Описание

swap - Swagger Annotation Processor
Creates swagger classes in the compile phase, i.e. in your IDE, in Maven, etc.
Ссылка на сайт

Ссылка на сайт

https://github.com/wwadge/swagger-annotation-processor
Система контроля версий

Система контроля версий

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

Скачать swagger-annotation-processor-parent

Имя Файла Размер
swagger-annotation-processor-parent-1.0.3.pom 5 KB
Обзор

Как подключить последнюю версию

<!-- 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"]

Зависимости

provided (1)

Идентификатор библиотеки Тип Версия
ch.qos.logback : logback-classic Необязательный jar 1.1.3

test (1)

Идентификатор библиотеки Тип Версия
junit : junit jar 4.12

Модули Проекта

  • 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"
}

Версии библиотеки

Версия
1.0.3
1.0.2
1.0.1
1.0.0