Discussions
Nested Discriminator support
10 months ago by Eduard Isakhanyan
Hey Readme.io community
I would like to know how I can achieve nested discriminator oneOf -> oneOf nested.
When I have a nested oneOf property it does not take first discriminator for "channel"
Example Code
"oneOf": [
{
"$ref": "#/components/schemas/TemplateSMSPostRequestDto"
},
{
"$ref": "#/components/schemas/TemplateViberPostRequestDto"
}
],
"discriminator": {
"propertyName": "channel",
"mapping": {
"SMS": "#/components/schemas/TemplateSMSPostRequestDto",
"VIBER": "#/components/schemas/TemplateViberPostRequestDto"
}
}
TemplateSMSPostRequestDto
{
"title": "SMS Template",
"type": "object",
"required": [
"text",
"channel"
],
"properties": {
"channel": {
"type": "string"
},
"text": {
"type": "string",
"maxLength": 1000
}
}
}
TemplateViberPostRequestDto
{
"title": "Viber Template",
"type": "object",
"allOf": [
{
"required": [
"channel"
],
"properties": {
"channel": {
"type": "string"
}
}
},
{
"oneOf": [
{
"$ref": "#/components/schemas/TemplateViberImagePostRequestDto"
},
{
"$ref": "#/components/schemas/TemplateViberDocumentPostRequestDto"
}
],
"discriminator": {
"propertyName": "type",
"mapping": {
"image": "#/components/schemas/TemplateViberImagePostRequestDto",
"document": "#/components/schemas/TemplateViberDocumentPostRequestDto"
}
}
}
]
}
TemplateViberImagePostRequestDto
{
"title": "Image Template",
"type": "object",
"required": [
"type",
"channel"
],
"properties": {
"type": {
"type": "string"
},
"text": {
"type": "string"
},
"url": {
"type": "string",
"description": "One of 'url' or 'media_id' is required"
},
"media_id": {
"type": "string",
"format": "uuid",
"description": "One of 'url' or 'media_id' is required"
}
}
}
TemplateViberDocumentPostRequestDto
{
"title": "Document Template",
"type": "object",
"required": [
"type",
"filename",
"channel"
],
"properties": {
"type": {
"type": "string"
},
"filename": {
"type": "string"
},
"url": {
"type": "string"
},
"media_id": {
"type": "string",
"format": "uuid"
}
}
}