connexion: `oneOf` does not work on `requestBody` when `oneOf` is nested under `#/components/schemas`

Description

oneOf in schema does not work on requestBody when this oneOf is nested under other schema defined in #/components/schemas/.

Expected behaviour

oneOf shall work when it is nested under other schema defined in #/components/schemas/.

Actual behaviour

The body does not contain the block use oneOf.

Steps to reproduce

The following is python and schema used to reprocedure this issue.

When we send a post request to /bad endpoint with body {"oneof":{"name":"one"}}. The response becomes {} instead of {"oneof":{"name":"one"}}.

The response shall be the same as request because they use the same schema, and the request is not rejected due to schema error.

openapi: 3.0.0
info:
  title: title
  version: 0.0.0
paths:
  /bad:
    post:
      summary: test
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/nested'
      responses:
        200:
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/nested'
      operationId: test.post
components:
  schemas:
    nested:
      type: object
      properties:
        oneof:
          $ref: '#/components/schemas/oneof'
    oneof:
          discriminator:
            propertyName: name
            mapping:
              one: '#/components/schemas/one'
              two: '#/components/schemas/two'
          oneOf:
            - $ref: '#/components/schemas/one'
            - $ref: '#/components/schemas/two'
    one:
      type: object
      required:
        - name
      properties:
        name:
          type: string
          pattern: ^one$
    two:
      type: object
      required:
        - name
      properties:
        name:
          type: string
          pattern: ^two$
import connexion


def post(body):
    print('body = {}'.format(body))
    return body, 200, {}


app = connexion.App(__name__)
app.add_api('test.yml', strict_validation=True, validate_responses=True)
app.run()

Additional info:

Output of the commands:

$ python --version
Python 3.6.4+
$ grep connexion Pipfile
connexion = {git = "https://github.com/zalando/connexion", ref = "62582643cbfca65b0cf0d54755f81f0e1a7d1f82"}

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 6
  • Comments: 21 (4 by maintainers)

Most upvoted comments

@czchen @dtkav @cziebuhr Hm. I guess I find cheap solution:

Just add “type” key along oneOf expression. Like that:

data:
  oneOf:
    - $ref: '#/components/schemas/sportsman_career2'
    - $ref: '#/components/schemas/sportsman_career1'
  type: object

Cheers, luv.

Bug is still unfixed… 😦

@bolmstedt Use the oneOf keyword up in paths section rather the in the components section. This works, for example:

  responses:
    200:
      description: new scrolling result
      content:
        application/json:
          schema:
            oneOf:
              - $ref: '#/components/schemas/ResultsScrollingUsers'
              - $ref: '#/components/schemas/QueryExecution'

I am facing the same issue. Has anyone found a solution to this ?