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

Nested oneOf Schema #195

Open
zbuckley opened this issue Oct 5, 2017 · 2 comments
Open

Nested oneOf Schema #195

zbuckley opened this issue Oct 5, 2017 · 2 comments
Assignees

Comments

@zbuckley
Copy link

zbuckley commented Oct 5, 2017

Love how clean this thing looks when generating a requestBody with a complicated schema, but we ran into one particular case that didn't seem supported.

There doesn't seem to be support for nesting multiple layers of oneOf.

If you render the example below you'll see that only the oneOf at the top-level (in /example's schema object), is toggled through the "Option 1", "Option 2" drop-down for the Request Body section. The Example Request, also has a oneOf on requestBody, which isn't being presented to the user.

I'm assuming this probably isn't a quick fix, but it would be a great feature to add... Would it be possible to nest the Option 1, Option 2 concept for additional anyOf layers?

I've put together an example that tries to illustrate the issue:

{
  "openapi": "3.0.0",
  "info": {
    "description": "Example Description",
    "version": "EXAMPLE",
    "title": "EXAMPLE TITLE",
  },
  "paths": {
    "/example": {
      "post": {
        "tags": [
          "Example Request"
        ],
        "summary": "/example summary",
        "description": "/example description",
        "requestBody": {
          "description": "Generic Request to be submitted",
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "request",
                  "userID"
                ],
                "properties": {
                  "request": {
                    "oneOf": [
                      "$ref": "#/components/schemas/ExampleRequest",
                      "$ref": "#/components/schemas/InfoRequest"
                    ]
                  },
                  "userID": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "ExampleRequest": {
        "type": "object",
        "description": "Describe Request A or B",
        "required": [
          "requestBody"
        ],
        "properties": {
          "requestBody": {
            "oneOf": [
              "$ref": "#/components/schemas/RequestA",
              "$ref": "#/components/schemas/RequestB"
            ]
          }
        }
      },
      "RequestA": {
        "type": "object",
        "description": "Description for Request A",
        "required": [
          "fieldA",
          "fieldB"
        ],
        "properties": {
          "fieldA": {
            "type": "string"
          },
          "fieldB": {
            "type": "string"
          }
        }
      },
      "RequestB": {
        "type": "object",
        "description": "Description for Request B",
        "required": [
          "fieldC",
          "fieldD"
        ],
        "properties": {
          "fieldC": {
            "type": "string"
          },
          "fieldD": {
            "type": "string"
          }
        }
      },
      "InfoRequest": {
        "type": "object",
        "description": "Description for Info Request",
        "required": [
          "fieldE",
          "fieldF"
        ],
        "properties": {
          "fieldE": {
            "type": "string"
          },
          "fieldF": {
            "type": "string"
          }
        }
      }
    }
  }
}
@brendo
Copy link
Contributor

brendo commented Oct 18, 2017

Hey! Sorry for the delay. Can confirm that doesn't produce an ideal result. If I'm following correctly there should be 3 possible options?

  • ExampleRequest with Request A
  • ExampleRequest with Request B
  • InfoRequest

I thought that the nested scenario was handled, but I must of messed something up in the oneOfResolver. Let me try to take a look over the next week and see if I can figure it out!

@quangkhoa actually proposed your idea early in the roadmap as an alternate UI! I couldn't find out how to pull it off back then, but maybe it's something worth revisiting now as it's a nicer experience.

@quangkhoa quangkhoa self-assigned this Oct 30, 2017
@zbuckley
Copy link
Author

zbuckley commented Nov 8, 2017

Sorry I didn't get back to you guys sooner. Your 3 possible options are definitely what I had in mind.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants