Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allowed value not showing for oneOf nested in allOf #2642

Open
hugovanversendaal opened this issue Aug 11, 2024 · 0 comments
Open

Allowed value not showing for oneOf nested in allOf #2642

hugovanversendaal opened this issue Aug 11, 2024 · 0 comments
Labels
p/medium t/bug Something isn't working triaged

Comments

@hugovanversendaal
Copy link

hugovanversendaal commented Aug 11, 2024

When oneOf is nested within allOf, the allowed value of the schema within oneOf is not showing. The title and the description of the nested schemas are fine, just not the allowed value. When a constant value is used within the upper allOf, the allowed value is showing properly

Context

I am using nested schemas in my project, but the allowed values are not visible. The users now have to look directly into openapi.yaml to find the allowed values.

Current Behavior

Allowed values are not shown in Elements when they are part of a schema within oneOf that is nested in allOf.

Screenshot 2024-08-11 at 23-23-08 Elements in HTML

See the contents of the OAS below:

openapi.yaml
openapi: 3.1.0
info:
  title: Sample API
  version: 0.1.9

paths:
  /pets:
    get:
      requestBody:
        content:
          application/json:
            schema:
              oneOf:
                - $ref: "#/components/schemas/Cat"
                - $ref: "#/components/schemas/Dog"
              discriminator:
                propertyName: pet_type

components:
  schemas:
    Pet:
      type: object
      required:
        - pet_type
      properties:
        pet_type:
          type: string
      discriminator:
        propertyName: pet_type
    Dog: # "Dog" is a value for the pet_type property (the discriminator value)
      allOf: # Combines the main `Pet` schema with `Dog`-specific properties
        - $ref: "#/components/schemas/Pet"
        - type: object
          # all other properties specific to a `Dog`
          properties:
            bark:
              type: boolean
            foo:
              type: string
              const: bar
            breed:
              type: string
              # enum: [Dingo, Husky, Retriever, Shepherd]
              oneOf:
                - $ref: "#/components/schemas/Dingo"
                - $ref: "#/components/schemas/Husky"
                - $ref: "#/components/schemas/Retriever"
                - $ref: "#/components/schemas/Shepherd"

    Cat: # "Cat" is a value for the pet_type property (the discriminator value)
      allOf: # Combines the main `Pet` schema with `Cat`-specific properties
        - $ref: "#/components/schemas/Pet"
        - type: object
          # all other properties specific to a `Cat`
          properties:
            hunts:
              type: boolean
            age:
              type: integer

    Dingo:
      title: Dingo
      type: string
      const: Dingo
      description: The dingo is an ancient (basal) lineage of dog found in Australia.
    Husky:
      title: Husky
      type: string
      const: Husky
      description: Husky is a general term for a dog used in the polar regions, primarily and specifically for work as sled dogs.
    Retriever:
      title: Retriever
      type: string
      const: Retriever
      description: A retriever is a type of gun dog that retrieves game for a hunter.
    Shepherd:
      title: Shepherd
      type: string
      const: Shepherd
      description: The German Shepherd, also known in Britain as an Alsatian, is a German breed of working dog of medium to large size.

Expected Behavior

Allowed values are visible in Elements when they are part of a schema within oneOf that is nested in allOf.

Possible Workaround/Solution

Because description is displayed properly, I use description with code markup to simulate the allowed values field. However, this is not the preferred use of the description field.

Steps to Reproduce

  1. Download and unzip attachment: elements-bug-oneof.zip.
  2. run docker compose up.
  3. go to http://localhost:8080/elements.html.
  4. compare openapi.yaml from the html-folder with the Dog-schema in browser.

Environment

  • Version used: 8.3.4
  • Environment name and version (e.g. Chrome 39, node.js 5.4): Firefox 129.0
  • Operating System and version (desktop or mobile): desktop, nginx 1.27.0
@mnaumanali94 mnaumanali94 added t/bug Something isn't working p/medium triaged labels Aug 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
p/medium t/bug Something isn't working triaged
Projects
None yet
Development

No branches or pull requests

2 participants