Skip to content

[BUG] REF_AS_PARENT_IN_ALLOF=true has no effect for simple inheritance without extra properties #21222

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
5 of 6 tasks
nlbuescher opened this issue May 5, 2025 · 0 comments

Comments

@nlbuescher
Copy link

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • 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

Using the openapiNormalizer option REF_AS_PARENT_IN_ALLOF has no effect for child schema that contains only the parent reference in the allOf.

With the example spec below, it is expected that the generated class FirstChild extends FirstParent, and the generate class SecondChild extends SecondParent. What actually happens is that class SecondChild extends SecondParent but class FirstChild only inherits FirstParent's properties, but does not get the inheritance.

openapi-generator version

7.13.0
I've verified behavior using openapi-generator-maven-plugin, openapi-generator-cli, and using spec v3.0.1 and v2.0.

The last version that this worke

OpenAPI declaration file content or url
# test.yaml
openapi: '3.0.1'
info:
  title: Example
  version: '1.0.0'

paths: {}

components:
  schemas:
    FirstParent:
      type: object
      properties:
        parentProp:
          type: string

    FirstChild:
      allOf:
        - $ref: '#/components/schemas/FirstParent'
    
    SecondParent:
      type: object
      properties:
        parentProp:
          type: string

    SecondChild:
      allOf:
        - $ref: '#/components/schemas/SecondParent'
        - properties:
            childProp:
              type: string
Generation Details

openapi-generator generate -i test.yaml -o out -g java --openapi-normalizer=REF_AS_PARENT_IN_ALLOF=true --global-property models

Steps to reproduce
  1. generate models using the command above.
Related issues/PRs

[BUG] REF_AS_PARENT_IN_ALLOF=true no longer works for allOf combined with properties #16389

Suggest a fix

The regression seems to be caused by the changes in #17426. Skipping an "allOf" list with only one item is causing the FirstParent class not to be marked as x-parent: true by the normalizer, even though the FirstChild includes it in its "allOf" list. SecondParent is being marked as x-parent: true because the extra properties constitute a second entry in the "allOf" list. removing the size() == 1 guard does not seem to cause a regression for #17425 (i.e. the tests still pass)

@nlbuescher nlbuescher changed the title [BUG] REF_AS_PARENT_IN_ALLOF=true has no effect for simple inheritance without extra properties. [BUG] REF_AS_PARENT_IN_ALLOF=true has no effect for simple inheritance without extra properties May 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant