This is a Gradle plugin to generate server code, client code and API document, using Swagger Codegen and Swagger2Markup.
See also following examples:
- Generated API document using Swagger2Markup
- Generated API document using Swagger Codegen HTML2
- Generated Swagger UI
- Example Gradle Projects
Create following build script.
plugins {
id 'org.hidetake.swagger.generator' version '1.5.2'
}
repositories {
jcenter()
}
dependencies {
// define dependency for Swagger Codegen CLI
swaggerCodegen 'io.swagger:swagger-codegen-cli:2.2.1'
}
generateSwaggerCode {
language = 'spring'
inputFile = file('petstore.yaml')
configFile = file('config.json')
components = ['models', 'apis']
}
The task generates source code into build/swagger-code
.
% ./gradlew generateSwaggerCode
:generateSwaggerCode
[main] INFO io.swagger.parser.Swagger20Parser - reading from ...
Run the task with Help
postfix to show available JSON configuration.
% ./gradlew generateSwaggerCodeHelp
:generateSwaggerCodeHelp
Available JSON configuration for task ':generateSwaggerCode':
CONFIG OPTIONS
sortParamsByRequiredFlag
...
Create following build script.
plugins {
id 'org.hidetake.swagger.generator' version '1.5.2'
id 'org.asciidoctor.convert' version '1.5.3'
}
repositories {
jcenter()
}
generateSwaggerDoc {
inputFile = file('petstore.yaml')
}
The task generates an API document as build/swagger-doc/index.html
.
% ./gradlew generateSwaggerDoc
:generateSwaggerDoc_swagger2markup
:generateSwaggerDoc_asciidoctor
:generateSwaggerDoc
Create following build script.
plugins {
id 'org.hidetake.swagger.generator' version '1.5.2'
}
repositories {
jcenter()
}
dependencies {
swaggerUI 'org.webjars:swagger-ui:2.2.6'
}
generateSwaggerUI {
inputFile = file('petstore.yaml')
}
The task generates an API document as build/swagger-ui
.
% ./gradlew generateSwaggerUI
:generateSwaggerUI
Task type GenerateSwaggerCode
accepts below properties.
Key | Type | Value | Default value |
---|---|---|---|
language |
String | Language to generate. | Mandatory |
inputFile |
File | Swagger spec file. | Mandatory |
outputDir |
File | Directory to write generated files. | $buildDir/swagger-code |
library |
String | Library type. | None |
configFile |
File | JSON configuration file. | None |
templateDir |
File | Directory containing the template. | None |
components |
List of Strings | Components to generate that is a list of models , apis and supportingFiles . |
All components |
The task supports a custom generator class by passing classpath
property.
See projects under acceptance-test for more.
Task type GenerateSwaggerDoc
accepts below properties.
Key | Type | Value | Default value |
---|---|---|---|
inputFile |
File | Swagger spec file. | Mandatory |
outputDir |
File | Directory to write the generated file. | $buildDir/swagger-doc |
config |
Map | Configuration for Swagger2Markup. | None |
options |
Map | Options for Asciidoctor Gradle Plugin. | None |
attributes |
Map | Attributes for Asciidoctor Gradle Plugin. | [toc: 'right', sectnums: '', sectanchors: ''] |
Task type GenerateSwaggerUI
accepts below properties.
Key | Type | Value | Default value |
---|---|---|---|
inputFile |
File | Swagger spec file. | Mandatory |
outputDir |
File | Directory to write the generated file. | $buildDir/swagger-ui |
See projects under acceptance-test for more.
This is an open source software licensed under the Apache License Version 2.0. Feel free to open issues or pull requests.
Travis CI builds the plugin continuously. Following variables should be set.
Environment Variable | Purpose |
---|---|
$GRADLE_PUBLISH_KEY |
Publish the plugin to Gradle Plugins |
$GRADLE_PUBLISH_SECRET |
Publish the plugin to Gradle Plugins |
$GITHUB_TOKEN |
Publish the example of API document to GitHub Pages |