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 - RequestBody null not preserved #1192

Closed
dldl-cmd opened this issue Mar 27, 2023 · 1 comment · Fixed by #1195
Closed

OpenApiOperation copy constructor - RequestBody null not preserved #1192

dldl-cmd opened this issue Mar 27, 2023 · 1 comment · Fixed by #1195

Comments

@dldl-cmd
Copy link
Contributor

Describe the bug
OpenApiOperation copy constructor: public OpenApiOperation(OpenApiOperation operation) changes a null in the RequestBody into an object instance.

To Reproduce

var operation = new OpenApiOperation();
//operation.RequestBody = null is the default
var copiedOperation = new OpenApiOperation(operation);

copiedOperation.RequestBody is an new OpenApiRequestBody.

Expected behavior
copiedOperation.RequestBody should also be null, as on the source object.

public OpenApiOperation(OpenApiOperation operation)
{
Tags = new List<OpenApiTag>(operation?.Tags);
Summary = operation?.Summary ?? Summary;
Description = operation?.Description ?? Description;
ExternalDocs = operation?.ExternalDocs != null ? new(operation?.ExternalDocs) : null;
OperationId = operation?.OperationId ?? OperationId;
Parameters = operation?.Parameters != null ? new List<OpenApiParameter>(operation.Parameters) : null;
RequestBody = new(operation?.RequestBody);
Responses = operation?.Responses != null ? new(operation?.Responses) : null;
Callbacks = operation?.Callbacks != null ? new Dictionary<string, OpenApiCallback>(operation.Callbacks) : null;
Deprecated = operation?.Deprecated ?? Deprecated;
Security = operation?.Security != null ? new List<OpenApiSecurityRequirement>(operation.Security) : null;
Servers = operation?.Servers != null ? new List<OpenApiServer>(operation.Servers) : null;
Extensions = operation?.Extensions != null ? new Dictionary<string, IOpenApiExtension>(operation.Extensions) : null;
}

I could provide a PR to fix this.

@MaggieKimani1
Copy link
Contributor

@dldl-cmd please feel free to send a PR our way 🙂

dldl-cmd pushed a commit to dldl-cmd/OpenAPI.NET that referenced this issue Mar 28, 2023
 Fixes microsoft#1192

 - Fix OpenApiOperation RequestBody and Tags null is not preserved
 - Add tests for null preserving null on copy constructor
 - Add tests for copy constructor serialization result to be equal
 - Fix OpenApiParameter object changes during serialization, so that the serialization result is on consecutive run the same.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants