RicoSuter / NSwag

The Swagger/OpenAPI toolchain for .NET, ASP.NET Core and TypeScript.
http://NSwag.org
MIT License
6.67k stars 1.23k forks source link

OpenApiDocuments with `RequireParametersWithoutDefault = true` makes all ApiParameters with ModelMetaData Containers required #4745

Open cavallialexander opened 6 months ago

cavallialexander commented 6 months ago

When using Nswag.AspNetcore setting configure.RequireParametersWithoutDefault = true; on an OpenApiDocument, all parameters defined within classes are required.

I've determined that this is because of the OperationParameterProcessor class.

On lines 79-87, if the apiParameter has ModelMetadata and the PropertyName exists on the container type, the property variable is set and assigned to the extendedApiParameter.PropertyInfo. This also causes the extendedApiParameter.ParameterInfo property to never be set (line 96 is the only place the property is set). image

This means when ExtendedApiParameterDescription.IsRequired is called, at the end (line 553) requireParametersWithoutDefault && ParameterInfo?.HasDefaultValue != true is always true because ParameterInfo is always null image