Skip to content

Add support for generating OpenAPI parameters #55041

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 10, 2024

Conversation

captainsafia
Copy link
Member

This pull request adds support for populating parameters not sourced from the request body into the OpenAPI document.

Additions to ApiDescriptionExtensions.cs:

  • src/OpenApi/src/Extensions/ApiDescriptionExtensions.cs: A new method IsRequestBodyParameter has been added to determine if a given ApiParameterDescription is a request body parameter. This method checks if the parameter source is either BindingSource.Body, BindingSource.FormFile, or BindingSource.Form. The Microsoft.AspNetCore.Mvc.ModelBinding namespace was also added to this file. [1] [2]

Modifications to OpenApiDocumentService.cs:

  • src/OpenApi/src/Services/OpenApiDocumentService.cs: The GetOperation method was modified to include parameters in the generated OpenApiOperation. A new method GetParameters was added to generate a list of OpenApiParameter from the ApiDescription. This method filters out parameters that should be in the request body and populates the parameters list with the remaining parameters. The Microsoft.AspNetCore.Mvc.ModelBinding namespace was also added to this file. [1] [2] [3]

New test cases:

  • src/OpenApi/test/Services/OpenApiDocumentServiceTests.Parameters.cs: New test cases were added to verify the correct generation of parameter locations, the requiredness of route parameters, the requiredness of query parameters, the requiredness of header parameters, and the skipping of request body parameters. A new shared type Todo was also added for use in the tests. [1] [2]

@captainsafia captainsafia added area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates feature-openapi area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc labels Apr 9, 2024
@captainsafia captainsafia requested a review from a team as a code owner April 9, 2024 23:35
@captainsafia captainsafia merged commit e0c652d into feature/openapi Apr 10, 2024
21 checks passed
@captainsafia captainsafia deleted the safia/get-parameters branch April 10, 2024 21:42
captainsafia added a commit that referenced this pull request Apr 18, 2024
Co-authored-by: Martin Costello <[email protected]>
Co-authored-by: Rick Anderson <[email protected]>

This PR adds support for OpenAPI document generation, sans schema generation to Microsoft.AspNetCore.OpenApi. Relevant changes are available in individual PRs:

- Add entry-point APIs for OpenAPI support (#54789)
- Support resolving OpenApiPaths entries from document (#54847) 
- Support generating OpenAPI operation and associated fields (#54903) 
- Add APIs for OpenAPI document transformers (#54935) 
- Add support for generating OpenAPI parameters (#55041)
- Add support for generating OpenAPI responses (#55020) 
- Add support for generating OpenAPI request bodies (#55040)
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.

2 participants