Skip to content

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

@panky98

Description

@panky98

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions