Created
March 14, 2021 15:50
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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