Skip to content

[BUG] [JAVA] REF_AS_PARENT_IN_ALLOF no longer effective with multiple $ref #22043

@kzander91

Description

@kzander91

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

The REF_AS_PARENT_IN_ALLOF normalizer doesn't work anymore in a case like this:

TestResponse:
  allOf:
    - $ref: '#/components/schemas/ParentType1'
    - $ref: '#/components/schemas/ParentType2'

With 7.15.0, this generated:

public class ParentType1 {
  // ...
  protected String parentProp1;
  // ...
}

public class TestResponse extends ParentType1 {
  // ...
  private String parentProp2;
  // ...
}

With 7.16.0, this now generates:

public class TestResponse { // <-- no longer inherits from ParentType1
  // ...
  private String parentProp1;
  // ...
  private String parentProp2;
  // ...
}
openapi-generator version

7.16.0. It is a regression introduced with this version, it worked with 7.15.0.

OpenAPI declaration file content or url
openapi: 3.0.3
info:
  title: Test
  version: 1.0.0
servers:
  - url: /test

paths:
  /test:
    get:
      responses:
        200:
          description: test
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TestResponse'

components:
  schemas:
    ParentType1:
      type: object
      properties:
        parent_prop1:
          type: string
      required:
        - parent_prop1
    ParentType2:
      type: object
      properties:
        parent_prop2:
          type: string
      required:
        - parent_prop2

    TestResponse:
      allOf:
        - $ref: '#/components/schemas/ParentType1'
        - $ref: '#/components/schemas/ParentType2'
Generation Details

I'm using the Maven plugin:

<build>
    <plugins>
        <plugin>
            <groupId>org.openapitools</groupId>
            <artifactId>openapi-generator-maven-plugin</artifactId>
            <version>7.16.0</version>
            <configuration>
                <generatorName>java</generatorName>
                <library>webclient</library>
                <openapiNormalizer>REF_AS_PARENT_IN_ALLOF=true</openapiNormalizer>
            </configuration>
            <executions>
                <execution>
                    <id>generate-api</id>
                    <goals>
                        <goal>generate</goal>
                    </goals>
                    <configuration>
                        <inputSpec>${project.basedir}/src/main/resources/test-openapi.yaml</inputSpec>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>
Steps to reproduce
Related issues/PRs

Haven't looked too deep into it, but I'm suspecting #21799 as the cause of this regression.

Suggest a fix

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions