openapi-core
openapi-core copied to clipboard
Does openapi-core include support for discriminator
Hi , Does open-api core include support for discriminator i tried it but didn't seem to work. https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.1.md#discriminatorObject if not any hints on how i could include it in my project
components:
requestBodies:
object:
content:
application/json:
schema:
oneOf:
- $ref: '#/components/schemas/user'
- $ref: '#/components/schemas/admin'
discriminator:
propertyName: item_type
schemas:
user:
type: object
admin:
type: object
what i need is when the item_type is user in the request body it should be validated based on user schema and similarly for admin
Discriminator is not implemented per se.
But it shouldn't be a problem because if you use it only with propertyName it
act as a "hint" to shortcut validation and selection of the matching schema which may be a costly operation, depending on the complexity of the schema
This is not working I am getting the error:
not valid for schema of type object: <Object
...
<Object ...> is valid under each of [<Object schema>, <Object schema>]
It seems to me that polymorphism support via discriminator should be supported as it is a key concept for many APIs.
snippit of schema:
Resource:
description: |
A resource is a container for requirements. It allows the developer do define requirements for the current project
or external things and reference them separately.
type: object
required:
- name
properties:
name:
type: string
description:
type: string
requirements:
type: array
items:
oneOf:
- $ref: "apt_spec.yml#/components/schemas/AptRequirement"
- $ref: "yum_spec.yml#/components/schemas/YumRequirement"
discriminator:
propertyName: requirementType
example data:
- name: python3 requirementType: YumRequirement resolveDependencies: False
- name: python3 requirementType: AptRequirement resolveDependencies: False
See https://github.com/p1c2u/openapi-core/issues/257#issuecomment-964053231 for a workaround.
dingus9 is this issue still active ?