Skip to content

Conversation

@captainsafia
Copy link
Member

@captainsafia captainsafia commented Aug 6, 2024

Closes #57112.

This PR updates the handling of required parameters within the form body to match the framework implementation.

  • The top-level OpenApiRequestBody.Required property is always set to true for forms. The framework does not support empty bodies for form-based requests in the same way that it does for JSON-based requests.
  • The OpenApiRequestBody.Content.Required property is updated to include required parameters of a primitive type in the list if they are required.
  • While testing this I discovered Empty form body with optional form file-based argument produces unexpected 408 in minimal APIs #57195, which makes it difficult to verify the optional of FormFile/FormFileCollection. Requiredness is still configured for these parameter types but we'll need to fix the underlying bug and test the end-to-end.
  • Requiredness for complex types (like [FromForm] Todo todo) is not affected by this change since the JsonSchemaExporter will set requiredness correctly for complex types.

@captainsafia captainsafia requested a review from a team as a code owner August 6, 2024 18:15
@ghost ghost added the area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates label Aug 6, 2024
@captainsafia captainsafia added feature-openapi area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc and removed area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates labels Aug 6, 2024
@dotnet-policy-service dotnet-policy-service bot added area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates labels Aug 6, 2024
Copy link
Contributor

@mikekistler mikekistler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. 👍

@captainsafia captainsafia merged commit 2a67ffb into main Aug 7, 2024
@captainsafia captainsafia deleted the safia/57112 branch August 7, 2024 00:09
@dotnet-policy-service dotnet-policy-service bot added this to the 9.0-rc1 milestone Aug 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates feature-openapi

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Non-nullable form parameters should be marked required in the generated OpenAPI

4 participants