swagger-api / swagger-codegen

swagger-codegen contains a template-driven engine to generate documentation, API clients and server stubs in different languages by parsing your OpenAPI / Swagger definition.
http://swagger.io
Apache License 2.0
17.01k stars 6.03k forks source link

Generating code from YAML without annotations #9004

Open fenders1 opened 5 years ago

fenders1 commented 5 years ago

I am generating Java 8 code from yaml file specifying my REST API. Models generated with some swagger annotations that I want to get rid of. Is it possible somehow? And maybe it will be possible in the nearest future ?

Rest models will be traveling through Camle routes, so I would like to use jaxrs annotations if any..

I am using openapi 3.0.0 version, so I have to use newest swagger maven codegen plugin (which I find 3.0.0-rc1 in maven repository)

I am using: <generateModelDocumentation>false</generateModelDocumentation>

The generated model:

  import io.swagger.annotations.ApiModel; //THIS IS NOT COMPILING and i dont need annotated models, just simple pojo classes or maybe some jackson annotations instead swagger specific..
    import io.swagger.annotations.ApiModelProperty;

    /**
     * The requested data to the service.
     */@ApiModel(description = "The requested data to the service.")
    @javax.annotation.Generated(value = "io.swagger.codegen.languages.java.JavaClientCodegen", date = "*****")
  @JsonProperty("myField")
  private String myField= null;
}

The pom.xml configuration:

<plugin>
                    <groupId>io.swagger</groupId>
                    <artifactId>swagger-codegen-maven-plugin</artifactId>
                    <version>3.0.0-rc1</version>
                    <executions>
                        <execution>
                            <goals>
                                <goal>generate</goal>
                            </goals>
                            <configuration>
<inputSpec>${project.basedir}/swagger/MyCustomSpecification.yaml</inputSpec>
                        <language>java</language>
                        <configOptions>
                            <dateLibrary>java8</dateLibrary>
                            <java8>true</java8>
                            <interfaceOnly>true</interfaceOnly>
                            <useJaxbAnnotations>false</useJaxbAnnotations>
                        </configOptions>
                        <generateApis>false</generateApis>
                        <generateApiTests>false</generateApiTests>
                        <generateModelTests>false</generateModelTests>
                        <generateModelDocumentation>false</generateModelDocumentation>
                        <generateSupportingFiles>false</generateSupportingFiles>
                        <generateApiDocumentation>false</generateApiDocumentation>
                        <modelPackage>${project.groupId}.swagger.model</modelPackage>
                        <apiPackage>${project.groupId}.swagger.api</apiPackage>
                        <invokerPackage>${project.groupId}.swagger.invoker</invokerPackage>
                        <library>resttemplate</library>
                    </configuration>
                </execution>
            </executions>
        </plugin>
ss4852 commented 5 years ago

try to add this to the plugin, it should help you.

ApiClient.java,Authentication.java,OAuth.java,ApiKeyAuth.java,HttpBasicAuth.java,RFC3339DateFormat.java
EvanKnowles commented 5 years ago

I'm trying to do the - looking at the mustache templates, there doesn't seem to be any kind of conditional around the @ApiModel lines so it doesn't look configurable. Think I'll just duplicate the language and remove the lines from the templates.