Swagger-codegen: How to specify "--skip-overwrite" parameter for swagger-codegen-maven-plugin

Created on 3 Jun 2016  路  13Comments  路  Source: swagger-api/swagger-codegen

I tried to pass the property in configOptions, but it seems does not work:

<configOptions> <skipOverwrite>false</skipOverwrite> </configOptions>

How to pass "--skip-overwrite" property for plugin?

I checked plugin code, it does not have this property specified, only in swagger-codegen-cli not plugin though. However this property is very important and we need to this to customize the new REST APIs/Models. Thanks,

Swagger Codegen Maven Plugin

Most helpful comment

@smileyogurt You haven't commented on this PR, so I assume you resolved your issues. I just wanted to let you know that I just opened a PR which will allow you to specify the location of a .swagger-codegen-ignore location outside of the generated directory. I think this will better address the issues you were having and give you more control than skipOverwrite.

All 13 comments

@smileyogurt instead of using skipOverwrite, please pull the latest master, which will generate .swagger-codegen-ignore file (similar to .gitignore), and in .swagger-codegen-ignore you can put down files that you want to skip the overwrite.

@wing328 @jimschubert

Referred from statement in wiki: "The .swagger-codegen-ignore file must exist in the root of the output directory." I put the following in api_v3/generated_sources/.swagger-codegen-ignore, but it does not work at all. Anything is missing here?

I wonder .swagger-codegen-ignore is not recognized. How to make it work?

src/io/swagger/api/*.java
src/io/swagger/model/*.java

Here is the structure of my project:

SwaggerCodeGenPrototype:
pom.xml
api_v3\generated_sources\.swagger-codegen-ignore
api_v3\generated_sources\src\* <------------------ Directory for generated files

I also tried to put .swagger-codegen-ignore under SwaggerCodeGenPrototype, or api_v3, none of them work.

@smileyogurt Can you share the relevant parts of the command line you're using to generate?

If you're doing java -jar swagger-codegen.jar generate -i swagger.json -l java -o api_v3\generated_sources\, then .swagger-codegen-ignore would need to be under generated_sources as you have.

You've included a pom.xml. Are you using the maven plugin and not targeting the master branch?

@jimschubert

I am using a pom.xml, and maven plugin. I didn't target master branch.

        <plugin>
            <groupId>io.swagger</groupId>
            <artifactId>swagger-codegen-maven-plugin</artifactId>
            <version>2.1.6</version>
            <executions>
                <execution>
                    <id>generate_service_stub</id>
                    <phase>package</phase>
                    <goals>
                        <goal>generate</goal>
                    </goals>
                    <configuration>
                        <inputSpec>data/test.yaml</inputSpec>
                        <language>spring-mvc</language>
                        <output>apis/generated-sources</output>
                        <configOptions>
                            <sourceFolder>src</sourceFolder>
                            <dateLibrary>java8</dateLibrary>
                            <serializableModel>true</serializableModel>
                        </configOptions>
                    </configuration>
                </execution>
            </executions>
        </plugin>

I also think all features of swagger codegen should be enhanced in plugin for a big project, instead of using CLI as a tool.

@smileyogurt I'd previously refactored the maven plugin to better support codegen options. That should exist in version 2.1.6.

The .swagger-codegen-ignore feature is new (about two weeks old) and only available in master/ branch/SNAPSHOT releases. You won't need to add any configuration options, as the codegen module used by the maven plugin will load the file from the output directory and skip writing according to rules in the file.

The .swagger-codegen-ignore support should be in the 2.2.0 release.

@jimschubert

When can 2.2.0 release be available at mvnrepository? We can wait for the new version and hopefully it can be available soon.

http://mvnrepository.com/artifact/io.swagger/swagger-codegen-maven-plugin

BTW, before that any solution for now by using 2.1.6, or is there a snapshot plugin?

@smileyogurt I don't know about the timelines or whatever. Maybe @wing328 knows?

I looked on maven central and jcentral and there doesn't seem to be a SNAPSHOT plugin publilshed anymore. I seem to recall seeing one for some 2.1.x in the past, but I could be wrong.

However, you can clone the repository and on the master branch run mvn clean package install to get 2.2.0-SNAPSHOT installed locally.

Usually it takes 3 to 4 months for a stable minor release.

Given that the next release is a major release (2.2.0), it may take a bit longer.

@jimschubert @wing328

Thanks for comments. I had built local 2.2.0-SNAPSHOT and verified it worked.

However the rule is applied even when the files don't exist. So different as skip overwrite (skip when fiel exists.) the rule does not check file existence.

Probably it is more convenient if "skipIfExist" can be exposed as one of auto gen configurationOption.

@smileyogurt I didn't look at the plugin's implementation because you had said the option wasn't included. I just verified and the skipOverwrite option exists. I apologize for not looking sooner.

Try moving the skip overwrite option outside of the configOptions node. I hadn't recognized it before, but that configOptions is a confusing name. It currently only supports instantiation-types, import-mappings, type-mappings, language-specific-primitives, and additional-properties. Probably adding to the confusion is that all of the private members with Parameter annotations on the plugin code are options to the plugin. The configOptions node holds a map of dynamic key/value pairs.

I like your suggestion of an option for ignoring only if the file already exists.

@smileyogurt You haven't commented on this PR, so I assume you resolved your issues. I just wanted to let you know that I just opened a PR which will allow you to specify the location of a .swagger-codegen-ignore location outside of the generated directory. I think this will better address the issues you were having and give you more control than skipOverwrite.

Was this page helpful?
0 / 5 - 0 ratings