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
16.73k stars 6.02k forks source link

[maven-plugin] Prevent always re-generating code #10313

Open ancoron opened 4 years ago

ancoron commented 4 years ago
Description

The codegen plugin currently always re-generates code, even though neither the plugin configuration nor the input specification file changed. This results in later Maven build steps to be also re-executed for no reason, which finally make build times much longer than necessary for rebuilds.

Swagger-codegen version

3.0.18

Swagger declaration file content or url

not relevant

Command line used for generation

Plugin configuration:

<plugin>
    <groupId>io.swagger.codegen.v3</groupId>
    <artifactId>swagger-codegen-maven-plugin</artifactId>
    <version>3.0.18</version>
    <executions>
        <execution>
            <id>generate-api-interfaces</id>
            <goals>
                <goal>generate</goal>
            </goals>
            <configuration>
                <inputSpec>${basedir}/api/openapi.yaml</inputSpec>
                <artifactId>my-service</artifactId>
                <output>${basedir}/target/generated-sources</output>
                <language>spring</language>
                <apiPackage>com.mycorp.svc.api</apiPackage>
                <modelPackage>com.mycorp.svc.model</modelPackage>
                <generateApis>true</generateApis>
                <generateSupportingFiles>false</generateSupportingFiles>
                <configOptions>
                    <sourceFolder>swagger</sourceFolder>
                    <interfaceOnly>true</interfaceOnly>
                    <library>spring-boot</library>
                    <configPackage>com.mycorp.svc</configPackage>
                    <dateLibrary>legacy</dateLibrary>
                </configOptions>
            </configuration>
        </execution>
    </executions>
</plugin>
Steps to reproduce
mvn clean package
mvn package
Related issues/PRs

none

Suggest a fix/enhancement

The plugin could write out a "stamp" file at a well-known location, containing a hash of the plugin configuration. The timestamp of the file itself serves as a marker for the last generation run and can be compared to the file specified as inputSpec parameter.

The plugin should then only re-generate code if either of the following statements is true:

teleological commented 3 years ago

See also #8539

stodec commented 1 year ago

Related changes from the openapi-generator project: https://github.com/OpenAPITools/openapi-generator/issues/1501 and https://github.com/OpenAPITools/openapi-generator/pull/1502