Skip to content
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

additionalProperties inside ComposedSchema are resolved as null #2157

Open
terzicaglar opened this issue Jan 24, 2025 · 0 comments
Open

additionalProperties inside ComposedSchema are resolved as null #2157

terzicaglar opened this issue Jan 24, 2025 · 0 comments

Comments

@terzicaglar
Copy link

I am using swagger-parser 2.1.25 and when I parse an OpenAPI document openapi-properties-additionalProperties.json using these ParseOptions:

ParseOptions parseOptions = new ParseOptions();
parseOptions.setResolve(true);
parseOptions.setResolveRequestBody(true);
parseOptions.setResolveFully(true);

OpenAPI openAPI = new OpenAPIV3Parser().read("src/main/resources/openapi-properties-additionalProperties.json", null,
    parseOptions);

It works perfect without any issues. swagger-parser can parse both properties and additionalProperties. However, when I change the requestBody structure from

"requestBody": {
  "description": "Update an existent pet in the store",
  "content": {
    "application/json": {
      "schema": {
        "$ref": "#/components/schemas/Pet"
      }
    }
  }
}

to

"requestBody": {
  "description": "Update an existent pet in the store",
  "content": {
    "application/json": {
      "schema": {
        "allOf": [
          {
            "$ref": "#/components/schemas/Pet"
          }
        ]
      }
    }
  }
}

as in openapi-allOf-properties-additionalProperties.json, where Pet schema has both properties and additionalProperties like this in both documents:

"Pet": {
  "type": "object",
  "properties": {
    "id": {
      "type": "integer",
      "format": "int64",
      "example": 10
    },
    "name": {
      "type": "string",
      "example": "doggie"
    }
  },
  "additionalProperties": {
    "type": "string"
  }
}

Resolved Schema has additionalProperties as null, where properties is resolved correctly. I believe that ResolverFully.aggregateSchemaCombinators method does not handle additionalProperties like it handles properties. In order to solve this issue, I added the following code before the line Map<String, Schema> properties = resolved.getProperties(); in aggregateSchemaCombinators method, knowing that it is not the perfect fix that handles all of the scenarios:

targetSchema.setAdditionalProperties(resolved.getAdditionalProperties());

It solved my issue, but probably it may not work in a more complex structure. Do you have any suggestions?

When I try to test these two OpenAPI documents from https://editor.swagger.io/ I can see both properties and additionalProperties in both files are resolved correctly. Example Value:

{
  "id": 10,
  "name": "doggie",
  "additionalProp1": "string",
  "additionalProp2": "string",
  "additionalProp3": "string"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant