Repository navigation
Description
I'm trying to validate an OpenAPI document that contains a schema object that is of type 'array' that can be an 'anyOf' that uses a discriminator to know which object goes into the array and it's failing validation. The document appears to be a valid OAS3 document and the Swagger UI has no issues rendering it, so I'm guessing it's an issue with OpenAPI.NET.
I'm getting validation errors similar to:
Composite Schema ChildTypeA must contain property specified in the discriminator type. [#/components/schemas/SampleResponse/properties/suggestedActions/items/anyOf]
Composite schema ChildTypeA must contain property specified in the discriminator type in the required field list. [#/components/schemas/SampleResponse/properties/suggestedActions/items/anyOf]
...for this document
openapi: 3.0.0
info:
description: Service to test discriminator
version: 1.0.0
title: Test Service
servers:
- url: 'https://localhost'
paths:
/test:
post:
description: Sample post of SampleRequest
requestBody:
description: Returns the SampleResponse with multiple types
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/SampleRequest'
responses:
'200':
description: OK
content:
application/json:
schema:
$ref: '#/components/schemas/SampleResponse'
components:
schemas:
SampleRequest:
type: object
required:
- id
properties:
id:
type: string
description: Random ID
example: '1513776099991'
BaseType:
type: object
required:
- type
properties:
type:
type: string
description: Suggested object type
ChildTypeA:
allOf:
- $ref: '#/components/schemas/BaseType'
properties:
type:
type: string
enum:
- typeA
type: object
ChildTypeB:
allOf:
- $ref: '#/components/schemas/BaseType'
properties:
type:
type: string
enum:
- typeB
type: object
SampleResponse:
type: object
properties:
suggestedActions:
type: array
items:
anyOf:
- $ref: '#/components/schemas/ChildTypeA'
- $ref: '#/components/schemas/ChildTypeB'
discriminator:
propertyName: type
Activity
PerthCharern commentedon Apr 28, 2019
I think currently that rule only looks at the properties in the schema itself without delving into the properties in the anyOf/allOf. This is a bug in our validator.
ma499 commentedon Feb 27, 2020
Are there any plans to fix this bug? This validator is now being used by Azure API Management when deploying APIs, and we are no longer able to deploy updates to our existing API to production because of this problem.
Robzilla commentedon Feb 27, 2020
Yes reported last November. Pretty big impact for me too. Apparently a fix is rolling out next week. See #429
Bit scary when something this big stops deployments for a few months.
fabich commentedon Apr 15, 2020
PerthCharern any updates on this?
ma499 commentedon May 13, 2020
Is this actually a bug? I just read the relevant section of the latest Open API 3.0.3 specification which indicates that a discriminator field is actually required to be a 'required' field.This is not new, the same is specified for Open API 2.0.Therefore, having read the specification, and thinking about the semantics of a discriminator field, I would argue that OpenAPI.NET's behaviour is actually correct and the official OpenAPI/Swagger parsers are the ones that actually have the bug as they are not strict enough to identify this problem.I realise I hadn't understood the issue properly and this is indeed a bug in the parser that it is not traversing the anyOf link to look in the child schemas for the required discriminator field.
himanigulati commentedon Jan 14, 2021
Is this issue still Open? We are dealing with the similar problem.
amrith92 commentedon Jan 29, 2021
himanigulati Yes, I think this is still open.
darrelmiller commentedon Jan 30, 2021
Ok, I must be doing something wrong. I'm trying the above sample in the OpenAPIWorkbench tool from the master branch and I am not seeing the error...

darrelmiller commentedon Mar 15, 2021
I verified this again and I am not seeing any errors. Please re-open if you find this is still a problem.
cnwta3 commentedon Aug 18, 2021
I can still reproduce the error with the following reproducer specification.
I get the following error:
The specification validates correctly in Swagger Editor.
2 remaining items
danehorak-callaway commentedon Jun 17, 2022
Can we get an update on the status of this fix? When can we expect a fix to be released?
baywet commentedon Jun 28, 2022
Hi everyone,
We just hit that issue recently with our internal tooling. After a quick chat with Darrel (@darrelmiller) here is the course of actions.
This code block needs improvements:
When the validation rule doesn't find the discriminator field in the current schema's required fields, it should recursively look into the anyOf/oneOf/allOf schemas (if any) before returning an error.
Ping Carol Kigoonya (@CarolKigoonya) to bump the priority of this one given the current impact.
Additionally for implementers, #383 provides additional testing cases.
julealgon commentedon Oct 1, 2025
I see this was apparently fixed several years ago, but I'm seeing the exact same issue today while attempting to import an OpenApi spec into Azure API Management:
This just happened as I switched our OpenApi generation in the API from
Swashbuckle's library, to latestMicrosoft.AspNetCore.OpenApi.In our case, this is due to an inheritance chain that generates this section:
Can someone clarify whether or not this is a bug on the parsing side (on Azure API Management), or a bug in the generation side?
This is currently making it impossible for us to update our API in APIM.
baywet commentedon Oct 1, 2025
If the type property is defined on all the anyOf entries somehow, it's a bug on the parsing side.
If it's not defined on all the anyOf entries, it's a bug on the generation side.
julealgon commentedon Oct 1, 2025
Vincent Biret (@baywet) that
$typeproperty does not exist in any of the actual .NET models (not in theabstractbase, and not in any of the concrete ones). It was automatically generated byMicrosoft.AspNetCore.OpenApito model the hierarchy as a set ofanyOfentries.I assume I should go ahead and open a Bug on the library then?
baywet commentedon Oct 1, 2025
https://github.com/dotnet/aspnetcore yes
julealgon commentedon Oct 2, 2025
Thanks Vincent Biret (@baywet) . While creating a smaller repro to post the issue on the
aspnetcorerepo, I realized that the reason we were getting that structure was due to a customDefaultJsonTypeInfoResolverimplementation, and that when removing that customization, we get a valid document again.I'll look into that customization on our side more closely before opening the issue as it may very well just be an oversight on our side and not on the library side.