swagger-api / swagger-api/swagger-ui

Wrong oneOf value when used with allOf in the same hierarchy

Open
#5,818 1 comment 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
29k
Forks
9.3k
Avg merge
2d 23h
Merged PRs (30d)
25

Description

Q&A (please complete the following information)
  • OS: Windows 7
  • Browser: Firefox 70.0.1
  • Version: Swagger editor (online version)
  • Method of installation: no installation
  • Swagger-UI version: Swagger editor (online version)
  • Swagger/OpenAPI version: OpenAPI 3.0
Content & configuration

Example Swagger/OpenAPI definition:

openapi: 3.0.0
info:
  version: 0.0.0
  title: test

paths: {}

components:
  schemas:
  
    Rich:
      type: object
      properties:
        bank_account:
          type: string

      
    Pet:
      type: object
      properties:
        pet_type:
          type: string
      discriminator:
        propertyName: pet_type
      oneOf:
        - $ref: '#/components/schemas/Cat'
        - $ref: '#/components/schemas/Dog'
        - $ref: '#/components/schemas/RichDog'
        
    RichDog:
      type: object
      allOf:
        - $ref: '#/components/schemas/Rich'
        - $ref: '#/components/schemas/Dog'
        
        
    Dog:
      allOf:
        - $ref: '#/components/schemas/Pet'
        - type: object
          properties:
            breed:
              type: string
              enum: [Dingo, Husky, Retriever, Shepherd]
              
    Cat:
      allOf:
        - $ref: '#/components/schemas/Pet'
        - type: object
          properties:
            age:
              type: integer
Describe the bug you're encountering

When I try to use both anyOf and oneOf, the generated ui mix up the oneOf into a wrong type.

To reproduce...

Steps to reproduce the behavior:
Use the yaml below in the online editor, having 4 types :

  • Rich
  • Dog
  • Cat
  • RichDog (allOf Rich and Dog)
  • Pet (oneOf Dog, Cat and RichDog)

Then the Dog type contains a OneOf with all its sibling types and itself (Cat, Dog and RichDog).

Expected behavior

Not to see a wrong oneOf value in the Dog type.

Screenshots

screenshot

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by loading the supplied OpenAPI 3.0 YAML in the Swagger Editor online version and reproduce the generated Dog schema. Inspect the schema rendering path for the incorrect oneOf value when Pet uses oneOf and RichDog combines Rich and Dog with allOf. Done means Dog no longer displays the unrelated sibling types in its oneOf.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.