In the OpenAPI documentation there is example of using discriminator
components:
responses:
sampleObjectResponse:
content:
application/json:
schema:
oneOf:
- $ref: '#/components/schemas/Object1'
- $ref: '#/components/schemas/Object2'
- $ref: 'sysObject.json#/sysObject'
discriminator:
propertyName: objectType
mapping:
obj1: '#/components/schemas/Object1'
obj2: '#/components/schemas/Object2'
system: 'sysObject.json#/sysObject'
schemas:
Object1:
type: object
required:
- objectType
properties:
objectType:
type: string
Unfortunately it work only when objectType is not nested field in Object1. In our project field objectType is nested like this:
schemas:
Object1:
type: object
properties:
nextObject:
type: object
properties:
objectType:
type: string
Is there any solution to point this field out? Something like this..?
propertyName: nextObject.objectType