OpenAPITools / OpenAPITools/openapi-generator
[BUG] InlineModelResolver not ignoring additional properties of $ref fixed field
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Description
When the specification has additional properties next to $ref fixed field (in the example below, $ref has an additional property type: object), OpenAPI Generator produces error:
[main] ERROR o.o.codegen.InlineModelResolver - Illegal schema found with $ref combined with other properties, no properties should be defined alongside a $ref:
However, the specification passes validation https://apidevtools.org/swagger-parser/online/ .
So the spec passes Swagger Parser, but fails on OpenAPI Generator.
Thanks to Richard Whitehouse on OpenAPI Generator Slack for pointing me to the OpenAPI spec https://spec.openapis.org/oas/latest.html#fixed-fields-18 which states
This object cannot be extended with additional properties and any properties added SHALL be ignored.
Which indicates that OpenAPI Generator should actually ignore those additional properties instead of resulting in error.
openapi-generator version
Tested on latest master as of 27 Aug 2022 and also published version 6.0.1 .
OpenAPI declaration file content or url
additionalProperties: false
properties:
all_of:
type: array
items:
type: object
$ref: '#/components/schemas/CatalogsProductGroupFilterKeys'
minItems: 1
The complete specification is available at https://github.com/pinterest/api-description/blob/main/v5/openapi.yaml .
Generation Details
I have a complete build output on GitHub Actions https://github.com/cliffano/pinterest-sdk/runs/7879342459?check_suite_focus=true
Steps to reproduce
-
curl https://github.com/pinterest/api-description/blob/main/v5/openapi.yaml -o myopenapi.yaml
-
docker
run
--rm
-vpwd:/local openapitools/openapi-generator-cli:v6.0.1
generate
--input-spec /local/myopenapi.yaml
--config /local/clients/ruby/conf.json
--generator-name ruby
--output /local/clients/ruby/generated;
Suggest a fix
I think InlineModelResolver conditional check (https://github.com/OpenAPITools/openapi-generator/blob/c135139e3dfba367800a02962f269b57a32ab8d4/modules/openapi-generator/src/main/java/org/openapitools/codegen/InlineModelResolver.java#L224) for additional properties should be removed, allowing the processing to continue.
If this looks correct, I can give it a stab at creating a PR.
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
Start at modules/openapi-generator/src/main/java/org/openapitools/codegen/InlineModelResolver.java around line 224 and reproduce with the supplied Pinterest OpenAPI file and Docker command. Confirm that a $ref with additional fixed-field properties is processed without the current error and that the generated Ruby output remains valid.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100