Skip to content

Instantly share code, notes, and snippets.

@d3vAdv3ntur3s
Created March 14, 2021 15:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save d3vAdv3ntur3s/e92483cd9179c98e563448a8314e7611 to your computer and use it in GitHub Desktop.
Save d3vAdv3ntur3s/e92483cd9179c98e563448a8314e7611 to your computer and use it in GitHub Desktop.
openapi code generator v5 example via Gradle using open API specification 3 for Spring Boot, generating WebFlux controller interface and DTOs
// openapi code generator using open api 3 specification
// This will generate the model, api (interfaces only)
// Spring-boot Server application using the SpringFox integration.
// Generator Docs: https://openapi-generator.tech/docs/generators/spring/
// Gradle plugin: https://github.com/OpenAPITools/openapi-generator/tree/master/modules/openapi-generator-gradle-plugin
// Gradle plugin example: https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator-gradle-plugin/samples/local-spec/build.gradle
// templatesDir is to override the generated output, e.g. override method signature: Mono<ResponseEntity<Flux<ContactDTO>>> to Flux<ContactDTO> via mustache templates
openApiGenerate {
// don't try and reuse this variable for sourceSet as reference here is for a directory and generated code will append files to src/main/java under this directory
generatorName.set("spring")
library.set("spring-boot")
outputDir.set("${buildDir}/generated")
inputSpec.set("${projectDir}/oas/openapi-1.0.0.yaml")
//templateDir.set("$projectDir/oas/templates")
modelPackage.set("dev.cloudnative.k8s.contact.store.dto")
apiPackage.set("dev.cloudnative.k8s.contact.store.controller.api")
modelNameSuffix.set("DTO")
configOptions.set([
dateLibrary: "java8",
skipDefaultInterface: "true",
interfaceOnly: "true",
reactive: "true"
])
globalProperties.set([
models: "",
apis: "",
])
}
compileJava.dependsOn tasks.openApiGenerate
// additional source to java compile path
sourceSets.main.java.srcDir(file("${buildDir}/generated/src/main/java"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment