Open nicusX opened 7 years ago
Has this issue been fixed? We're also using the interfaceOnly option but it still generates the pom.xml, README.md and .swagger-codegen-ignore. We don't want these files to be generated for our project. Is there a way we can tell swagger codegen not to generate these files? Currently using swagger-codegen 2.2.3 version
You can use <generateSupportingFiles>false</generateSupportingFiles>
to prevent those files from being generated.
Where do you specify
task generateApi {
inputs.file("$projectDir/$swaggerSourceFile")
outputs.dir("$projectDir/$generatedSources")
doLast {
def config = new CodegenConfigurator()
config.setInputSpec("file:///$projectDir/$swaggerSourceFile")
config.setOutputDir("$projectDir")
config.setLang('spring')
config.setAdditionalProperties([
'interfaceOnly' : 'true',
'dateLibrary' : 'java8',
'apiPackage' : 'net.flitech.land.hotel.api',
'modelPackage' : 'net.flitech.land.hotel.api.model',
'hideGenerationTimestamp' : 'true',
'sourceFolder' : generatedSources
])
new DefaultGenerator().opts(config.toClientOptInput()).generate()
}
}
For gradle, I would recommend using the gradle plugin. See an example conf : https://github.com/jhipster/generator-jhipster/blob/master/generators/server/templates/gradle/_swagger.gradle
we are changing from codegen 2.2.3 to codegen 2.3.1 and now no more pom.xml were generated. We generationg with 'interfaceOnly' : 'true', and after maven build we deploying the builded jar file separatly to our maven registry. this process ist now broken. i think it is necessary to control the generation of pom.xml with an separate parameter, should i implement this and make an pull request ?
thanks andreas
Description
As a best practice for code generation with a CI pipeline driven by maven, it should be able to regenerate every file that depends on Swagger spec file.
Speaking about Spring Boot, these files are:
SwaggerDocumentationConfig.java
(defines API info based on the Swagger specs)Using Maven, these files should be regenerated at every build, into
./target/generated-sources
(usually ignored in VCS).Any other file might be optionally generated, on demand (as opposed as automatically at every build), only on the developer's machine and into
./src
.Currently, this only partially works using the
swagger-codegen-maven-plugin
andspring
language.Specifyng
interfaceOnly=true
, the following files are generated:pom.xml
README.md
.swagger-codegen-ignore
By default,
swagger-codegen-maven-plugin
correctly generates into./target/generated-sources
I see two distinct problems here:
pom.xml
,README.md
,.swagger-codegen-ignore
should not be generated wheninterfaceOnly=true
(and it also doen't make sense generating them into./target/generated-sources
)SwaggerDocumentationConfig.java
The
.swagger-codegen-ignore
file is not useful, as you only may ignore files, not selectively activate their generation.Swagger-codegen version
Verified using Swagger Codegen Maven plugin 2.2.2 (release) and CLI 2.2.2
Swagger declaration file content or url
It does not depend on Swagger specs. I used this for testing: https://github.com/OAI/OpenAPI-Specification/blob/master/examples/v2.0/json/petstore-minimal.json
Command line used for generation
pom.xml
The effect is reproducible with the following CLI, but as the build is controlled by Maven, only the Maven plugin should be used.
using the following config.json:
Steps to reproduce
./src/main/resources/
project subdirectorymvn clean generate-sources
Related issues
None AFAIK
Suggest a Fix
The current
SpringCodegen.java
implementation might be easily modified not to generatepom.xml
,README.md
,.swagger-codegen-ignore
wheninterfaceOnly=true
Selectively regenerating
SwaggerDocumentationConfig.java
might need a separage, language specific option.