Incorrect behaviour with Implicit-Required on [FromQuery]
in Microsoft.AspNetCore.OpenAPI
Attempting to call /weatherforecast
without a city
query parameter will, correctly, fail with
{
"type": "https://tools.ietf.org/html/rfc9110#section-15.5.1",
"title": "One or more validation errors occurred.",
"status": 400,
"errors": {
"City": [
"The City field is required."
]
},
"traceId": "00-b60d49f5662be73508730192b2ffd1e2-9951b7eb55e622f8-00"
}
Attempting to call /weatherforecast?city=London
will succeed.
However, the OpenAPI Schema at /openapi/v1.json
does not list the city
parameter as "required": true
{
"openapi": "3.1.1",
"info": {
"title": "WebApplication1 | v1",
"version": "1.0.0"
},
"servers": [
{
"url": "http://localhost:5182/"
}
],
"paths": {
"/WeatherForecast": {
"get": {
"tags": [
"WeatherForecast"
],
"operationId": "GetWeatherForecast",
"parameters": [
{
"name": "City",
"in": "query",
"schema": {
"type": "string"
}
}
],
"responses": {
"200": {
"description": "OK",
"content": {
"text/plain": {
"schema": {
"type": "array",
"items": {
"$ref": "#/components/schemas/WeatherForecast"
}
}
},
"application/json": {
"schema": {
"type": "array",
"items": {
"$ref": "#/components/schemas/WeatherForecast"
}
}
},
"text/json": {
"schema": {
"type": "array",
"items": {
"$ref": "#/components/schemas/WeatherForecast"
}
}
}
}
}
}
}
}
},
"components": {
"schemas": {
"WeatherForecast": {
"type": "object",
"properties": {
"date": {
"type": "string",
"format": "date"
},
"temperatureC": {
"pattern": "^-?(?:0|[1-9]\\d*)$",
"type": [
"integer",
"string"
],
"format": "int32"
},
"temperatureF": {
"pattern": "^-?(?:0|[1-9]\\d*)$",
"type": [
"integer",
"string"
],
"format": "int32"
},
"summary": {
"type": [
"null",
"string"
]
}
}
}
}
},
"tags": [
{
"name": "WeatherForecast"
}
]
}