You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In OpenApi (Version 9.0.4) schema json there are duplicate schemas if i use arrays.
Expected Behavior
Schemas should not duplicate.
Steps To Reproduce
Controller methods:
[HttpGet("new")][Produces("application/json")][ProducesResponseType((int)HttpStatusCode.OK,Type=typeof(IEnumerable<EventDto>))]publicasyncTask<IActionResult>GetAllEventsWithImages(){try{varevents=await_eventLogic.GetAllNewEventsAsync();returnOk(events);}catch(Exceptionex){_logger.LogError(ex,"Error while fetching new events.");returnStatusCode((int)HttpStatusCode.InternalServerError,InternalServerErrorMessage);}}[HttpGet("{id:guid}")][Produces("application/json")][ProducesResponseType((int)HttpStatusCode.OK,Type=typeof(EventDto))]publicasyncTask<IActionResult>GetEventById(Guidid){_logger.LogInformation("Fetching event with ID {EventId}",id);vareventDto=await_eventLogic.GetEventByIdAsync(id);if(eventDto==null){_logger.LogWarning("Event with ID {EventId} not found",id);returnNotFound($"Event with ID {id} not found");}returnOk(eventDto);}
Two schemas are generated #/components/schemas/SomeCustomType and #/components/schemas/SomeCustomType2.
Temporary I can work around this with following configuration but it's too fragile to be a long term solution. Gets API clients to generate in dev loop with no errors, at least.
services.AddOpenApi(options =>{options.AddSchemaTransformer((schema,context,cancellationToken)=>{if(schema.Propertiesis not null){if(schema.Properties.TryGetValue("overallResults",outvaroverallResultsRef)){overallResultsRef.Nullable=true;overallResultsRef.Reference=newOpenApiReference(){Id="SomeCustomType",// forces SomeCustomType instead of SomeCustomType2Type=ReferenceType.Schema,};}}returnTask.CompletedTask;});});
Strangely enough, resulting JSON doesn't have nullable set to true on overallResults after this modification - I don't know why.
"groupedResults": {"type": "object","additionalProperties": {"$ref": "#/components/schemas/SomeCustomType"},"nullable": true},"overallResults": {// would be suffixed with `2` and cause entire new schema to generate without workaround"$ref": "#/components/schemas/SomeCustomType"},
Is there an existing issue for this?
Describe the bug
In OpenApi (Version 9.0.4) schema json there are duplicate schemas if i use arrays.
Expected Behavior
Schemas should not duplicate.
Steps To Reproduce
Controller methods:
Dto:
Generated schema:
Exceptions (if any)
No response
.NET Version
9.0.200
Anything else?
No response
The text was updated successfully, but these errors were encountered: