Route constraints don't produce appropriate information in OpenAPI schema #36525
Labels
feature-openapi
old-area-web-frameworks-do-not-use
*DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels
Priority:0
Work that we can't release without
Milestone
Routes in ASP.NET Core apps support the following set of constraints on route parameters:
All of these constraints map to options that can be set in the OpenAPI schema for a particular parameter. For example, the following route template
/foo/{bar:int:min(3)}
should produce the following OpenAPI schema:To determine what constraints should be populated in the schema, Swashbuckle looks for data validation attributes on the parameters associated with each roue parameter as seen below.
https://github.com/domaindrivendev/Swashbuckle.AspNetCore/blob/95cb4d370e08e54eb04cf14e7e6388ca974a686e/src/Swashbuckle.AspNetCore.SwaggerGen/SchemaGenerator/OpenApiSchemaExtensions.cs#L10-L32
The attributes that Swashbuckle looks through are derived from the
ParameterInfo
provided in theApiParameterDescription
object populated by the ApiExplorer.For minimal APIs, this means that an endpoint like:
will not produce the correct annotations. The same problem exists for controllers where a controller action like the one below:
will produce an OpenAPI schema like the following:
when it should be producing a schema like the following:
There is a workaround for this change which requires applying the matching data validation annotations to the parameters.
will produce the correct annotations.
The same problem exists for OpenAPI schemas generated using NSwag.
TL;DR:
The text was updated successfully, but these errors were encountered: