allOf merges $ref schemas outside of allOf
See original GitHub issueWhen using allOf combining $ref and inline schemas, all times the $ref is used are also updated to the inline-schema.
| Q | A |
|---|---|
| Bug or feature request? | Bug |
| Which Swagger/OpenAPI version? | 3.0.0 |
| Which Swagger-UI version? | Swaggerhub SmartBear |
| How did you install Swagger-UI? | swaggerhub.com |
| Which browser & version? | Chrome Latest |
| Which operating system? | MacOS |
Demonstration API definition
components:
schemas:
Error:
type: object
properties:
code:
type: integer
format: int32
minimum: 100
maximum: 600
message:
type: string
UnauthorizedError:
allOf:
- $ref: '#/components/schemas/Error'
- type: object
properties:
code:
example: 401
message:
example: "Unauthorized"
NotFoundError:
allOf:
- $ref: '#/components/schemas/Error'
- type: object
properties:
code:
example: 404
message:
example: "Resource Not Found"
Expected Behavior
The example 404 should only appear for the NotFoundError $ref.
components:
responses:
NotFound:
description: The specified resource was not found
content:
application/json:
schema:
$ref: '#/components/schemas/NotFoundError'
Current Behavior
The example 404 also appears for the UnauthorizedError $ref.
components:
responses:
Unauthorized:
description: Unauthorized
content:
application/json:
schema:
$ref: '#/components/schemas/UnauthorizedError'
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Understanding JSON Schema 2020-12 documentation
JSON Schema includes a few keywords for combining schemas together. Note that this doesn't necessarily mean combining schemas from multiple files or JSON ......
Read more >JSON schema : "allof" with "additionalProperties"
This problem is why I have made these two proposals for draft v5: strictProperties ,; merge . Your schema for shipping_address would then...
Read more >Combining schemas - Ajv JSON schema validator
Combining schemas. Combining schemas with $ref; Extending recursive schemas; $data reference; $merge and $patch keywords ...
Read more >Other Internals - react-jsonschema-form documentation
The allOf keyword is supported; it uses json-schema-merge-allof to merge subschemas to render the final combined schema in the form. When these subschemas...
Read more >oneOf, anyOf, allOf, not - Swagger
oneOf – validates the value against exactly one of the subschemas; allOf – validates ... application/json: schema: oneOf: - $ref: '#/components/schemas/Cat' ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Yep, this is a bug!
I was just working in this area of Swagger-Client for https://github.com/swagger-api/swagger-js/pull/1275, so I went ahead and patched this while my memory was fresh.
Locking due to inactivity.
This is done to avoid resurrecting old issues and bumping long threads with new, possibly unrelated content.
If you think you’re experiencing something similar to what you’ve found here: please open a new issue, follow the template, and reference this issue in your report.
Thanks!