swagger-api / swagger-api/swagger-codegen

[maven-plugin] Prevent always re-generating code

Open
#10,313 2 comments 8 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

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:

  • the inputSpec file is newer than our marker file
  • the plugin configuration hash does not match

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the Maven plugin's generate goal and reproduce the behavior with the provided mvn clean package and mvn package sequence. Review how the inputSpec and plugin configuration are handled, then verify that unchanged inputs skip regeneration while a newer specification or changed configuration triggers it.

Written by the indexing model from the issue text.

Assessment

Domain
build-system
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.