swagger-api / swagger-api/swagger-parser
additionalProperties inside ComposedSchema are resolved as null
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 867
- Forks
- 560
- Avg merge
- 2d 21h
- Merged PRs (30d)
- 7
Description
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"
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the issue with the two attached OpenAPI documents and the shown ParseOptions, then inspect ResolverFully.aggregateSchemaCombinators, especially its handling of properties and additionalProperties. Add a regression test covering the direct $ref and allOf request-body schemas; done means resolved additionalProperties is preserved alongside properties.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- api
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100