question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItĀ collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Inheritance using 'allOf' seems broken

See original GitHub issue

Problems 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:closed
  • Created 6 years ago
  • Comments:11 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
webroncommented, Sep 17, 2017

@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 for BBANValidationResponse, because you have conflicting enum definitions in all the other allOf instances.

When we render allOfin 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.

1reaction
owenconticommented, Sep 17, 2017

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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found