Skip to content

OpenApiOperation copy constructor - RequestBody null not preserved #1192

@dldl-cmd

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.

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