Skip to content

[BUG] allOf with single $ref element implementation doesn't respect sibling properties like deprecated etc. #17048

Closed

Description

@pinalbaldha

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

allOf can have sibling json properties like deprecated, readOnly, nuallable etc.
allOf with single$ref is treated differently: #16096
allOf with single $ref doesn't respect sibling property behaviour.
Whereas allOf with more than one $ref respects sibling properties.

OpenAPI spec with allOf & single $ref:

"components":{
  "schemas": {
    "AssetFrame": {
      "type": "object",
      "properties": {
        "test": {
          "type": "string",
          "deprecated": true
        },
        "machineDetails": {
          "deprecated": true,
          "allOf": [
            {
              "$ref": "#/components/schemas/MachineDetails"
            }
          ]
        }
      }
    }
  }
}

Generates below java code:
Snippet of AssetFrame.java

  @SerializedName(SERIALIZED_NAME_MACHINE_DETAILS)
  private AssetFrameMachineDetails machineDetails;

OpenAPI spec with allOf & more man one $ref

"components":{
  "schemas": {
    "AssetFrame": {
      "type": "object",
      "properties": {
        "test": {
          "type": "string",
          "deprecated": true
        },
        "machineDetails": {
          "deprecated": true,
          "allOf": [
            {
              "$ref": "#/components/schemas/MachineDetails"
            },
            {
              "$ref": "#/components/schemas/Shelf"
            }
          ]
        }
      }
    }
  }
}

Snippet of AssetFrame.java

  @Deprecated
  @SerializedName(SERIALIZED_NAME_MACHINE_DETAILS)
  private AssetFrameMachineDetails machineDetails;
openapi-generator version

3.0.0

Expectation

allOf with single $ref should respect deprecated property and should have @Deprecated annotation.

Steps to reproduce

java -jar ./modules/openapi-generator-cli/target/openapi-generator-cli.jar generate -i ./library_openapi.json -g java -o ~/Documents/library/

Related issues/PRs

None found

Suggest a fix

Probably fix will be in [modules/openapi-generator/src/main/java/org/openapitools/codegen/InlineModelResolver.java#L235](

block.
Need to set properties before/after execution.
need go through the code to find the code fix location.

Activity

  1. wing328 commented on Nov 13, 2023

    @wing328
    Member

    thanks for reporting the issue. I've filed #17056 to fix it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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