swagger-api / swagger-api/swagger-codegen
Gradle project static HTML doesn't get generated
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
Given a Gradle project with the following 2 tasks (one generating server code with language spring and the other one the static HTML with language html2). The problem is that nothing gets written in the case of the static HTML task when running the build task. If generate HTML task gets called explicitly it works fine.
Swagger-codegen version
io.swagger:swagger-annotations:1.5.16
io.swagger:swagger-codegen:2.2.3
Swagger declaration file content or url
def generateServerCodeTask(name, swaggerInputFile, swaggerOutputDir, apiPackage, modelPackage) {
return tasks.create("${name}GenerateServerCode") {
doFirst {
io.swagger.parser.SwaggerParser parser = new io.swagger.parser.SwaggerParser()
io.swagger.parser.util.SwaggerDeserializationResult result = parser.readWithInfo(swaggerInputFile, null, true)
if (!result.messages.isEmpty()) {
System.err.println("Swagger validation: " + result.messages.stream().collect(java.util.stream.Collectors.joining("\n")))
}
}
doLast {
def config = new io.swagger.codegen.config.CodegenConfigurator()
config.inputSpec = swaggerInputFile
config.outputDir = swaggerOutputDir
config.lang = 'spring'
config.templateDir = "${rootProject.rootDir}/swagger/templates/server/"
config.apiPackage = apiPackage
config.modelPackage = modelPackage
config.modelNameSuffix = "WS"
config.additionalProperties = [
"dateLibrary" : "java8",
"interfaceOnly" : true,
"useBeanValidation": true
]
config.skipOverwrite = false
config.addSystemProperty("models", "")
config.addSystemProperty("apis", "")
config.addSystemProperty("apiTests", "false")
config.addSystemProperty("apiDocs", "false")
config.addSystemProperty("modelDocs", "false")
config.addSystemProperty("modelTests", "false")
new io.swagger.codegen.DefaultGenerator().opts(config.toClientOptInput()).generate()
}
}
}
def generateServerHtmlDocTask(name, swaggerInputFile, htmlDocOutputDir) {
return tasks.create("${name}GenerateHtmlDoc") {
doFirst {
io.swagger.parser.SwaggerParser parser = new io.swagger.parser.SwaggerParser()
io.swagger.parser.util.SwaggerDeserializationResult result = parser.readWithInfo(swaggerInputFile, null, true)
if (!result.messages.isEmpty()) {
System.err.println("Swagger validation: " + result.messages.stream().collect(java.util.stream.Collectors.joining("\n")))
}
}
doLast {
def config = new io.swagger.codegen.config.CodegenConfigurator()
config.inputSpec = swaggerInputFile
config.outputDir = htmlDocOutputDir
config.lang = 'html2'
new io.swagger.codegen.DefaultGenerator().opts(config.toClientOptInput()).generate()
}
}
}
Attaching both tasks to compileJava.
compileJava {
dependsOn parent.generateServerHtmlDocTask(project.name, "${projectDir}/swagger/api-spec.yml", "${buildDir}/docs"), parent.generateServerCodeTask(project.name, "${projectDir}/swagger/api-spec.yml", "${buildDir}/swagger-code", "com.company.api", "com.company.api.dto")
}
Command line used for generation
./gradlew clean build
Steps to reproduce
- Setup a multi-module Gradle project with java and spring boot plugins
- include the 2 tasks and an arbitrary YAML input file
- run
./gradlew clean build
Suggest a fix/enhancement
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the compileJava dependency and the two task closures shown in the issue, then inspect the DefaultGenerator().opts(...).generate() entry point for differences between build execution and explicit task execution. Done means ./gradlew clean build generates the html2 output in build/docs as well as the server output.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- groovy, java, spring
- Domain
- build-system, documentation
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100