Skip to content

additionalProperties inside ComposedSchema are resolved as null #2157

@terzicaglar

Description

@terzicaglar

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"
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions