Inheritance using 'allOf' seems broken
See original GitHub issueProblems with inheritance and overrides.
Q | A |
---|---|
Bug or feature request? | Bug |
Which Swagger/OpenAPI version? | 2.0 |
Which Swagger-UI version? | Using Swagger-UI 3.X, via https://editor.swagger.io |
How did you install Swagger-UI? | N/A |
Which browser & version? | Google Chrome 60.0.3112.113 (Official Build) (64-bit) |
Which operating system? | macOS |
Demonstration API definition
swagger: "2.0"
info:
version: 1.0.0
title: Test
securityDefinitions:
basicAuth:
type: basic
paths:
/bban/validate:
post:
produces:
- application/json
responses:
200:
description: OK
schema:
allOf:
- $ref: '#/definitions/SwedenBBANValidationResponse'
- $ref: '#/definitions/NorwayBBANValidationResponse'
definitions:
BBANValidationResponse:
description: |
A discriminated object with variants:
- <a href="#SwedenBBANValidationResponse">SwedenBBANValidationResponse</a>
- <a href="#NorwayBBANValidationResponse">NorwayBBANValidationResponse</a>
type: object
properties:
common_property:
type: boolean
enums:
type: string
enum:
- enum_override_1
- enum_override_2
description: Enum override
SwedenBBANValidationResponse:
type: object
description: Specific information for the `Sweden` type of BBANValidationResponse
allOf:
- $ref: "#/definitions/BBANValidationResponse"
- type: object
properties:
sweden_specific_property:
type: string
enums:
type: string
enum:
- sweden_enum_1
- sweden_enum_2
description: Sweden description
NorwayBBANValidationResponse:
type: object
description: Specific information for the `Norway` type of BBANValidationResponse
allOf:
- $ref: "#/definitions/BBANValidationResponse"
- type: object
properties:
norway_specific_property:
type: string
enums:
type: string
enum:
- norway_enum_1
- norway_enum_2
description: Norway description
Expected Behavior
I want āModelā in the API definition to show the enums
fields as a combination of the fields of its inherited definitions (SwedenBBANValidationResponse
and NorwayBBANValidationResponse
).
And allow an enums
specification on the parent to override the children if used.
Current Behavior
Currently, enums
shows values and description only from one of its children, seemingly arbitrarily chosen.
There is no way to override the bleed-through by specifying a values on the parent.
Possible Solution
Context
Issue Analytics
- State:
- Created 6 years ago
- Comments:11 (7 by maintainers)
Top Results From Across the Web
"extends"/"allOf" and schema inheritance - Google Groups
My view is that the "extends"/"allOf" behaviour is completely appropriate, and is inheritance in the purest sense. Any other behaviour added in the...
Read more >JSon schema and Inheritance - java - Stack Overflow
Using allOf would potentially solve my problem, but I am wondering if there is a construct in json schema that I can use...
Read more >REST Builder (OpenAPI) YAML "allOf" inheritance is ... - Liferay
This is quite breaking the inheritance and creates as a composite schema.Have attached allOf.png for your reference; We have a parent class called...
Read more >Understanding JSON Schema
inheritance. Instances must independently be valid against āall ofā the schemas in the allOf. See the section on.
Read more >2.0.0 | AsyncAPI Initiative for event-driven APIs
This object can be extended with Specification Extensions. Composition and Inheritance (Polymorphism). The AsyncAPI Specification allows combining and extendingĀ ...
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
@HaraldNordgren Iām sorry, but @hkosova is right.
allOf
does not merge schemas, it checks each one of those individually. In effect, nothing would validate against any of the schemas you provided in your sample, except forBBANValidationResponse
, because you have conflicting enum definitions in all the otherallOf
instances.When we render
allOf
in Swagger-UI - it is indeed a āmergeā of a sort - this is because itās easier to display and understand, and in most cases, when there are no conflicts, works well. We do have a way of producing a non-merged version of it, even though thatās not exposed right now.Iām afraid thereās nothing to fix here. @owenconti, your PR is not needed unfortunately.
Hi @HaraldNordgren - I believe I have a fix for this issue. The fix is in the
swagger-js
repository. You can track the PR here: https://github.com/swagger-api/swagger-ui/issues/3674