Skip to content

OpenApiOperation copy constructor - RequestBody null not preserved #1192

Closed

Description

@dldl-cmd

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.

Activity

  1. MaggieKimani1 commented on Mar 28, 2023

    @MaggieKimani1
    Contributor

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

  2. added a commit that references this issue on Mar 28, 2023
    61fd3f7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions