openapi-spec-validator icon indicating copy to clipboard operation
openapi-spec-validator copied to clipboard

oneOf with discriminator on path

Open LienM opened this issue 6 years ago • 1 comments

As all different types of request bodies should be processed by the same function, I was hoping to do something the following minimal example:

  /api/{item_type}:
    post:
      parameters:
        - in: path
          name: item_type
          required: true
          schema:
            type: string  
      requestBody:
        $ref: '#/components/requestBodies/object'
        required: true
      responses:
        '201':
          description: Item created
components:
  requestBodies:
    object:
      content:
        application/json:
          schema:
            oneOf:
              - $ref: '#/components/schemas/Movie'
              - $ref: '#/components/schemas/Program'
            discriminator:
              propertyName: item_type
  schemas:
    Movie:
      type: object
    Program:
      type: object

Essentially, I want one function, to parse all item_types, but still ensure validation based on item_type in the path. However, I can create a Movie with the properties of Program. Is this not the intended use? Or is there no discriminator validation on parameters specified in the path?

Thanks in advance.

LienM avatar Jan 17 '19 16:01 LienM

@LienM Discriminator property is taken from schema. You can't get item_type from path parameter.

p1c2u avatar Feb 25 '19 18:02 p1c2u