davidfowl / TodoApi

Todo application with ASP.NET Core Blazor WASM, Minimal APIs and Authentication
MIT License
2.79k stars 419 forks source link

Bug fix: The AddOpenApiSecurityRequirement creates empty requestBody … #73

Closed cleftheris closed 1 year ago

cleftheris commented 1 year ago

…when it originaly should be left null. This messes up operations in the openapi spec that otherwise have an empty body.

I cannot help but wonder though if the new OpenApiOperation constructor should be taking the liberty of initializing the RequestBody property since the passed parameter has it null. Maybe it is a bug with the Microsoft.AspNetCore.OpenApi library.

I love this repo and was deeply influenced to start with minimal APIs (and docker for that matter). So my pull request is for all the people like me that copied the helpers (Extensions) from here as a starting point.

This is not related to the endpoints behavior but can be a problem when you are actually invested in generating clients from the open API spec.

cleftheris commented 1 year ago

There is actually a workaround. I have found that this bug stems from Microsoft.OpenApi nuget package. If you include an explicit reference to the preview 1.6.4-preview2 version the issue is tackled and this pull request is not needed.

It was indeed the new OpenApiOperation(OpenApiOperation operation) constructors fault.

davidfowl commented 1 year ago

do you want to send an update with that change?

cleftheris commented 1 year ago

Yes definitely

cleftheris commented 1 year ago

Updated with the said changes. Probably better if you squashed the pull request since I did a couple of extra commits revert my visualstudio tabs/spaces settings.