Skip to content

oneOf / anyOf usage with form-based content-type schema #7640

@jacobjmarks

Description

@jacobjmarks

Originally posted by @jacobjmarks in #3803 (comment)

I am having a similar issue here. See below an example spec in which I am attempting to describe a form which can accept one of two possible schemas:

openapi: 3.0.1
info:
  title: FooBar
  version: 1.0.0
paths:
  /foobar:
    post:
      summary: Summary
      requestBody:
        content:
          application/x-www-form-urlencoded:
            schema:
              oneOf:
              - type: object
                properties:
                  Foo:
                    type: string
              - type: object
                properties:
                  Bar:
                    type: string
      responses:
        default:
          description: Description

Please note that the same issue occurs when using a requestBody/content type of multipart/form-data

This endpoint should expect to receive a body of either Foo= or Bar=.
This schema causes the following Swagger UI interface to be rendered:

image

This is not correct. It is representing the form as a JSON payload and causes invalid requests to be sent to the endpoint in which the Swagger UI is encoding each character as a separate form value. E.g. sending a value of hi would result in the body 0=h&1=i.

This same issue occurs when using anyOf.

When using allOf, however, a correct representation is rendered as below:

image

Are there any updates here regarding the support for such oneOf and anyOf usage? Alternatively; am I incorrectly defining my schema in some way to achieve such usage?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions