Hello! I am using the OASValidation policy in apigee and getting a strange error when I use a discriminator. When using an open api schema such as this:
components:
schemas:
Request:
type: object
description: "description"
properties:
metadata:
$ref: '#/components/schemas/Metadata'
Metadata:
type: object
description: 'description'
discriminator:
propertyName: pet_type
mapping:
Cat: "#/components/schemas/CatMetadata"
Dog: "#/components/schemas/DogMetadata"
properties:
pet_type:
type: string
enum:
- Cat
- Dog
description: 'The type of pet'
example: Cat
required:
- pet_type
CatMetadata:
allOf:
- $ref: '#/components/schemas/Metadata'
- type: object
properties:
name:
type: string
description: 'Name of pet'
required:
- name
DogMetadata:
allOf:
- $ref: '#/components/schemas/Metadata'
- type: object
properties:
name:
type: string
description: 'Name of pet'
required:
- name
And submitting a payload such as this:
{
"metadata": {
"pet_type": "Cat",
"name": "Fluffy"
}
}
I am receiving an error similar to:
{
"title": "OAS Validation Failure",
"type": "OAS Validation Failure",
"status": "400",
"detail": "Request failed validation against the API specification.",
"instance": "/path",
"source": [
{
"detail": "ERROR - [Path '/metadata'] Validation loop: schema \"#/components/schemas/CatMetadata\" visited twice for pointer \"/metadata\" of validated instance: []"
}
]
}
Does anyone have guidance to workaround such an issue? Does OASValidation not support discriminators for open api spec version 3.0.1?
I'm having the same issue while validating requests against TMForum OpenAPI specs, which make extensive use of composite keywords (oneOf, anyOf, allOf) and the discriminator object:
PartyOrPartyRole_MVO:
type: object
description: ''
oneOf:
- $ref: '#/components/schemas/PartyRef_MVO'
- $ref: '#/components/schemas/PartyRoleRef_MVO'
- $ref: '#/components/schemas/Individual_MVO'
- $ref: '#/components/schemas/Organization_MVO'
- $ref: '#/components/schemas/PartyRole_MVO'
- $ref: '#/components/schemas/Supplier_MVO'
- $ref: '#/components/schemas/BusinessPartner_MVO'
- $ref: '#/components/schemas/Consumer_MVO'
- $ref: '#/components/schemas/Producer_MVO'
discriminator:
propertyName: '@type'
mapping:
PartyRef: '#/components/schemas/PartyRef_MVO'
PartyRoleRef: '#/components/schemas/PartyRoleRef_MVO'
Individual: '#/components/schemas/Individual_MVO'
Organization: '#/components/schemas/Organization_MVO'
PartyRole: '#/components/schemas/PartyRole_MVO'
Supplier: '#/components/schemas/Supplier_MVO'
BusinessPartner: '#/components/schemas/BusinessPartner_MVO'
Consumer: '#/components/schemas/Consumer_MVO'
Producer: '#/components/schemas/Producer_MVO'
PartyRef:
type: object
description: A Party reference
allOf:
- $ref: '#/components/schemas/EntityRef'
discriminator:
propertyName: '@type'
mapping:
PartyRef: '#/components/schemas/PartyRef'
Can we assume that OASValidation policy is not yet able to support these keywords?
@rmcavoy , where you able to find a workaround?