oneOf with discriminator on path

Open
#52 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Feature
Clarity
Needs clarification
Activity status
Stale
Tech stack
openapi, python

Research direction

Start with the minimal OpenAPI example in the issue and review how discriminator validation is handled for request bodies and path parameters. Check the project's validation entry points and tests for oneOf and discriminator behavior; done should clarify or implement the expected relationship between the path item_type and the selected schema.

Written by the indexing model from the issue text.

Description

resolution/invalid

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.

Dominant language
Python
Stars
409
Forks
73
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from python-openapi/openapi-spec-validator

All issues in python-openapi/openapi-spec-validator

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.