OpenAPITools / OpenAPITools/openapi-generator

[BUG] [JAVA] order of required constructor parameters is swapped after refactoring with allOf composition

Open
#21,945 7 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Description

I have described

      type: object
      required: 
        - name
        - type
      allOf: 
        - properties:
            name:
              $ref: '#/components/schemas/AssetName'
        - $ref: '#/components/schemas/CocDbAssetDataDTO'

and (re)generated Java Spring Boot project from it.

All generated and compiled but unit tests started to fail. It has showed that adding allOf
instead of inlining/duplicating properties swapped name and type
parameters in generated constructor.

  /**
   * Constructor with only required parameters
   */
  public CocDbAssetDTO(String type, String name) {

while without allOf, inlining/duplicating properties, it was:

 /**
   * Constructor with only required parameters
   */
  public CocDbAssetDTO(String name, String type) {
openapi-generator version

Generator version: 7.11.0

@Generated(value = "org.openapitools.codegen.languages.SpringCodegen", date = "2025-09-10T15:15:48.681116300+02:00[Europe/Luxembourg]", comments = "Generator version: 7.11.0")
public class CocDbAssetDTO
OpenAPI declaration file content or url
      type: object
      required: 
        - name
        - type
      allOf: 
        - properties:
            name:
              $ref: '#/components/schemas/AssetName'
        - $ref: '#/components/schemas/CocDbAssetDataDTO'
Generation Details
 <build>
    <plugins>
      <plugin>
        <groupId>org.openapitools</groupId>
        <artifactId>openapi-generator-maven-plugin</artifactId>
        <version>7.11.0</version>
        <executions>
          <execution>
            <goals>
              <goal>generate</goal>
            </goals>
            <configuration>
              <inputSpec>${project.basedir}/../openapi.yaml</inputSpec>
              <generatorName>spring</generatorName>
              <output>${project.basedir}/target/generated-spring/module</output>
              <packageName>com.eurofins.middleware.cmdb</packageName>
              <apiPackage>com.eurofins.middleware.cmdb.openapi</apiPackage>
              <modelPackage>com.eurofins.middleware.cmdb.openapi.dto</modelPackage>
              <groupId>com.eurofins.middleware</groupId>
              <artifactId>cmdb-openapi-spring</artifactId>
              <artifactVersion>${project.version}</artifactVersion>
              <configOptions>
                <interfaceOnly>true</interfaceOnly>
                <useSpringBoot3>true</useSpringBoot3>
                <skipDefaultInterface>true</skipDefaultInterface>
                <useSwaggerUI>false</useSwaggerUI>
                <annotationLibrary>none</annotationLibrary>
                <documentationProvider>source</documentationProvider>
                <parentGroupId>com.eurofins.middleware</parentGroupId>
                <parentArtifactId>cmdb-openapi-sb3-custom-parent</parentArtifactId>
                <parentVersion>${project.version}</parentVersion>
                <additionalModelTypeAnnotations>
                  @com.fasterxml.jackson.annotation.JsonInclude(com.fasterxml.jackson.annotation.JsonInclude.Include.NON_NULL)
                </additionalModelTypeAnnotations>
              </configOptions>
              <typeMappings>
                <typeMapping>OffsetDateTime=Instant</typeMapping>
              </typeMappings>
              <importMappings>
                <importMapping>java.time.OffsetDateTime=java.time.Instant</importMapping>
              </importMappings>
            </configuration>
          </execution>
        </executions>
      </plugin>
Steps to reproduce

generate project, using maven install.

Related issues/PRs

possibly #17542 [BUG][JAVA] Java generator puts parent properties from allOf last instead of first and skips properties entirely for "middle" references

Suggest a fix

Could not it generate constructor parameters in order from the required list, that is IMHO most deterministic and under full user control, no magic, please?

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 Java Spring generator's handling of schemas using allOf, reproduce the issue with the supplied YAML and Maven generation configuration, and compare constructor parameter order with and without allOf. Done means generated CocDbAssetDTO constructors preserve the required list order (name, type) for this case without regressing related allOf behavior in #17542.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, openapi, spring
Domain
backend, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.