Skip to content
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

OpenApiOperation copy constructor is creating RequestBody even if in source object it was null #1515

Closed
panky98 opened this issue Jan 5, 2024 · 3 comments

Comments

@panky98
Copy link

panky98 commented Jan 5, 2024

Describe the bug
The problem is, when using extension method .WithOpenApi() to customize OpenAPI specification for some endpoint and when using copy constructor (#832) in the handler, as suggested, the result is that object created using copy constructor will have RequestBody even if in source object it was null. The drawback of that is that OpenAPI specification for that endpoint will have requestBody and if using that specification we try to generate client, generated client will require body for requests even if body is not required (this happens mostly for GET endpoints).

OpenApi File To Reproduce
/

Expected behavior
Expected is next: If in source object RequestBody is null, then in newly created object, which should be copy of source object, RequestBody should also be null.

Screenshots/Code Snippets
Resulting specification:

image

image

By the way, SwashBuckle is used for specification generation.

Additional context

This is more a question than bug report. For myself, the solution was to not use the copy constructor and to modify the source object directly.

@MaggieKimani1
Copy link
Contributor

MaggieKimani1 commented Jan 15, 2024

We only new up a RequestBody object in the OpenApiOperation copy constructor if it exists in the source object as defined below, otherwise it results to a null object:

RequestBody = operation?.RequestBody != null ? new(operation?.RequestBody) : null;

Can you share a file/example that can help us reproduce this issue on our end?

@panky98
Copy link
Author

panky98 commented Jan 15, 2024

Hi @MaggieKimani1. In my project, I am using v7.0.11, probably as soon as we migrate to dotnet 8 everything is going to be ok
then.

Thank you very much for the response :)

@MaggieKimani1
Copy link
Contributor

Closing this issue as it was already fixed by #1195

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants