A simple gradle plugin to integrate SwaggerHub hosting of OpenAPI/Swagger definitions with a gradle build process, using the SwaggerHub API.
json
and yaml
format for API definitions.The pattern of usage is likely to depend on whether a code first or design first approach is followed.
plugins {
id "io.swagger.swaggerhub" version "1.0.1"
}
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "gradle.plugin.io.swagger:swaggerhub:1.0.1"
}
}
apply plugin: "io.swagger.swaggerhub"
swaggerhubDownload {
api 'PetStoreAPI'
owner 'jsfrench'
version '1.0.0'
outputFile 'target/test/petStoreAPI.json'
}
Parameter | Description | Required | Default |
---|---|---|---|
api |
API name | true | - |
owner |
API owner | true | - |
version |
API version | true | - |
outputFile |
API definition is written to this file | true | - |
token |
SwaggerHub API key, required to access private definitions | false | - |
format |
API definition format, json or yaml |
false | json |
host |
URL of SwaggerHub API | false | api.swaggerhub.com |
protocol |
Protocol for SwaggerHub API,http or https |
false | https |
port |
Port to access SwaggerHub API | false | 443 |
oas |
Version of the OpenApi Specification the definition adheres to | false | 2.0 |
swaggerhubUpload {
api 'PetStoreAPI'
owner 'jsfrench'
version '1.0.1-SNAPSHOT'
inputFile 'target/petStoreAPI.json'
token 'duMmyAPiKEy'
}
swagger-gradle-plugin
(code first)swagger-gradle-plugin
) as a public API in SwaggerHub.
plugins {
...
id 'java'
id "io.swagger.core.v3.swagger-gradle-plugin" version '2.0.6'
id "io.swagger.swaggerhub" version "1.0.1"
}
...
resolve {
outputFileName = 'PetStoreAPI'
outputFormat = 'JSON'
prettyPrint = 'TRUE'
classpath = sourceSets.main.runtimeClasspath
resourcePackages = ['test.petstore']
outputPath = 'target'
}
swaggerhubUpload {
dependsOn resolve
api 'PetStoreAPI'
owner 'jsfrench'
version '1.0.1-SNAPSHOT'
inputFile 'target/petStoreAPI.json'
token 'duMmyAPiKEy'
}
Parameter | Description | Required | Default |
---|---|---|---|
api |
API name | true | - |
owner |
API owner | true | - |
version |
API version | true | - |
inputFile |
Local file containing the API definition in json or yaml format | true | - |
token |
SwaggerHub API key | true | - |
format |
API definition format, json or yaml |
false | json |
isPrivate |
Defines whether the API should be private on SwaggerHub (using true requires a paid plan) |
false | false |
host |
URL of SwaggerHub API | false | api.swaggerhub.com |
protocol |
Protocol for SwaggerHub API,http or https |
false | https |
port |
Port to access SwaggerHub API | false | 443 |