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

Fix: Update reference types to remove cloning #2088

Draft
wants to merge 2 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.

using System;
Expand Down Expand Up @@ -70,11 +70,13 @@ internal OpenApiCallbackReference(OpenApiCallback target, string referenceId)
};
}

private Dictionary<RuntimeExpression, OpenApiPathItem> _pathItems;
/// <inheritdoc/>
public override Dictionary<RuntimeExpression, OpenApiPathItem> PathItems { get => Target.PathItems; set => Target.PathItems = value; }
public override Dictionary<RuntimeExpression, OpenApiPathItem> PathItems { get => _pathItems is not null ? _pathItems : Target?.PathItems; set => _pathItems = value; }

private IDictionary<string, IOpenApiExtension> _extensions;
/// <inheritdoc/>
public override IDictionary<string, IOpenApiExtension> Extensions { get => Target.Extensions; set => Target.Extensions = value; }
public override IDictionary<string, IOpenApiExtension> Extensions { get => _extensions is not null ? _extensions : Target?.Extensions; set => _extensions = value; }

/// <inheritdoc/>
public override void SerializeAsV3(IOpenApiWriter writer)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,9 @@ public OpenApiExample Target
get
{
_target ??= Reference.HostDocument.ResolveReferenceTo<OpenApiExample>(_reference);
OpenApiExample resolved = new OpenApiExample(_target);
if (!string.IsNullOrEmpty(_description)) resolved.Description = _description;
if (!string.IsNullOrEmpty(_summary)) resolved.Summary = _summary;
return resolved;
if (!string.IsNullOrEmpty(_description)) _target.Description = _description;
if (!string.IsNullOrEmpty(_summary)) _target.Summary = _summary;
return _target;
}
}

Expand Down Expand Up @@ -76,25 +75,28 @@ internal OpenApiExampleReference(OpenApiExample target, string referenceId)
/// <inheritdoc/>
public override string Description
{
get => string.IsNullOrEmpty(_description) ? Target.Description : _description;
get => string.IsNullOrEmpty(_description) ? Target?.Description : _description;
set => _description = value;
}

/// <inheritdoc/>
public override string Summary
{
get => string.IsNullOrEmpty(_summary) ? Target.Summary : _summary;
get => string.IsNullOrEmpty(_summary) ? Target?.Summary : _summary;
set => _summary = value;
}

private IDictionary<string, IOpenApiExtension> _extensions;
/// <inheritdoc/>
public override IDictionary<string, IOpenApiExtension> Extensions { get => Target.Extensions; set => Target.Extensions = value; }
public override IDictionary<string, IOpenApiExtension> Extensions { get => _extensions is not null ? _extensions : Target?.Extensions; set => _extensions = value; }

private string _externalValue;
/// <inheritdoc/>
public override string ExternalValue { get => Target.ExternalValue; set => Target.ExternalValue = value; }
public override string ExternalValue { get => !string.IsNullOrEmpty(_externalValue) ? _externalValue : Target?.ExternalValue; set => _externalValue = value; }

private JsonNode _value;
/// <inheritdoc/>
public override JsonNode Value { get => Target.Value; set => Target.Value = value; }
public override JsonNode Value { get => _value is not null ? _value : Target?.Value; set => _value = value; }

/// <inheritdoc/>
public override void SerializeAsV3(IOpenApiWriter writer)
Expand Down
40 changes: 25 additions & 15 deletions src/Microsoft.OpenApi/Models/References/OpenApiHeaderReference.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,8 @@ public OpenApiHeader Target
get
{
_target ??= Reference.HostDocument.ResolveReferenceTo<OpenApiHeader>(_reference);
OpenApiHeader resolved = new OpenApiHeader(_target);
if (!string.IsNullOrEmpty(_description)) resolved.Description = _description;
return resolved;
if (!string.IsNullOrEmpty(_description)) _target.Description = _description;
return _target;
}
}

Expand Down Expand Up @@ -74,42 +73,53 @@ internal OpenApiHeaderReference(OpenApiHeader target, string referenceId)
/// <inheritdoc/>
public override string Description
{
get => string.IsNullOrEmpty(_description) ? Target.Description : _description;
get => string.IsNullOrEmpty(_description) ? Target?.Description : _description;
set => _description = value;
}

private bool? _required;
/// <inheritdoc/>
public override bool Required { get => Target.Required; set => Target.Required = value; }
public override bool Required { get => _required is not null ? _required.Value : Target?.Required ?? false; set => _required = value; }

private bool? _deprecated;
/// <inheritdoc/>
public override bool Deprecated { get => Target.Deprecated; set => Target.Deprecated = value; }
public override bool Deprecated { get => _deprecated is not null ? _deprecated.Value : Target?.Deprecated ?? false; set => _deprecated = value; }

private bool? _allowEmptyValue;
/// <inheritdoc/>
public override bool AllowEmptyValue { get => Target.AllowEmptyValue; set => Target.AllowEmptyValue = value; }
public override bool AllowEmptyValue { get => _allowEmptyValue is not null ? _allowEmptyValue.Value : Target?.AllowEmptyValue ?? false; set => _allowEmptyValue = value; }

private OpenApiSchema _schema;
/// <inheritdoc/>
public override OpenApiSchema Schema { get => Target.Schema; set => Target.Schema = value; }
public override OpenApiSchema Schema { get => _schema is not null ? _schema : Target?.Schema; set => _schema = value; }

private ParameterStyle? _style;
/// <inheritdoc/>
public override ParameterStyle? Style { get => Target.Style; set => Target.Style = value; }
public override ParameterStyle? Style { get => _style is not null ? _style : Target?.Style; set => _style = value; }

private bool? _explode;
/// <inheritdoc/>
public override bool Explode { get => Target.Explode; set => Target.Explode = value; }
public override bool Explode { get => _explode is not null ? _explode.Value : Target?.Explode ?? false; set => _explode = value; }

private bool? _allowReserved;
/// <inheritdoc/>
public override bool AllowReserved { get => Target.AllowReserved; set => Target.AllowReserved = value; }
public override bool AllowReserved { get => _allowReserved is not null ? _allowReserved.Value : Target?.AllowReserved ?? false ; set => _allowReserved = value; }

private JsonNode _example;
/// <inheritdoc/>
public override JsonNode Example { get => Target.Example; set => Target.Example = value; }
public override JsonNode Example { get => _example is not null ? _example : Target?.Example; set => _example = value; }

private IDictionary<string, OpenApiExample> _examples;
/// <inheritdoc/>
public override IDictionary<string, OpenApiExample> Examples { get => Target.Examples; set => Target.Examples = value; }
public override IDictionary<string, OpenApiExample> Examples { get => _examples is not null ? _examples : Target?.Examples; set => _examples = value; }

private IDictionary<string, OpenApiMediaType> _content;
/// <inheritdoc/>
public override IDictionary<string, OpenApiMediaType> Content { get => Target.Content; set => Target.Content = value; }
public override IDictionary<string, OpenApiMediaType> Content { get => _content is not null ? _content : Target?.Content; set => _content = value; }

private IDictionary<string, IOpenApiExtension> _extensions;
/// <inheritdoc/>
public override IDictionary<string, IOpenApiExtension> Extensions { get => base.Extensions; set => base.Extensions = value; }
public override IDictionary<string, IOpenApiExtension> Extensions { get => _extensions is not null ? _extensions : Target?.Extensions; set => _extensions = value; }

/// <inheritdoc/>
public override void SerializeAsV31(IOpenApiWriter writer)
Expand Down
23 changes: 14 additions & 9 deletions src/Microsoft.OpenApi/Models/References/OpenApiLinkReference.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,8 @@ public OpenApiLink Target
get
{
_target ??= Reference.HostDocument.ResolveReferenceTo<OpenApiLink>(_reference);
OpenApiLink resolved = new OpenApiLink(_target);
if (!string.IsNullOrEmpty(_description)) resolved.Description = _description;
return resolved;
if (!string.IsNullOrEmpty(_description)) _target.Description = _description;
return _target;
}
}

Expand Down Expand Up @@ -70,14 +69,17 @@ internal OpenApiLinkReference(OpenApiLink target, string referenceId)
};
}

private string _operationRef;
/// <inheritdoc/>
public override string OperationRef { get => Target.OperationRef; set => Target.OperationRef = value; }
public override string OperationRef { get => !string.IsNullOrEmpty(_operationRef) ? _operationRef : Target?.OperationRef; set => _operationRef = value; }

private string _operationId;
/// <inheritdoc/>
public override string OperationId { get => Target.OperationId; set => Target.OperationId = value; }
public override string OperationId { get => !string.IsNullOrEmpty(_operationId) ? _operationId : Target?.OperationId; set => _operationId = value; }

private OpenApiServer _server;
/// <inheritdoc/>
public override OpenApiServer Server { get => Target.Server; set => Target.Server = value; }
public override OpenApiServer Server { get => _server is not null ? _server : Target?.Server; set => _server = value; }

/// <inheritdoc/>
public override string Description
Expand All @@ -86,14 +88,17 @@ public override string Description
set => _description = value;
}

private Dictionary<string, RuntimeExpressionAnyWrapper> _parameters;
/// <inheritdoc/>
public override Dictionary<string, RuntimeExpressionAnyWrapper> Parameters { get => Target.Parameters; set => Target.Parameters = value; }
public override Dictionary<string, RuntimeExpressionAnyWrapper> Parameters { get => _parameters is not null ? _parameters : Target?.Parameters; set => _parameters = value; }

private RuntimeExpressionAnyWrapper _requestBody;
/// <inheritdoc/>
public override RuntimeExpressionAnyWrapper RequestBody { get => Target.RequestBody; set => Target.RequestBody = value; }
public override RuntimeExpressionAnyWrapper RequestBody { get => _requestBody is not null ? _requestBody : Target?.RequestBody; set => _requestBody = value; }

private IDictionary<string, IOpenApiExtension> _extensions;
/// <inheritdoc/>
public override IDictionary<string, IOpenApiExtension> Extensions { get => base.Extensions; set => base.Extensions = value; }
public override IDictionary<string, IOpenApiExtension> Extensions { get => _extensions is not null ? _extensions : Target?.Extensions; set => _extensions = value; }

/// <inheritdoc/>
public override void SerializeAsV3(IOpenApiWriter writer)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,8 @@ public OpenApiParameter Target
get
{
_target ??= Reference.HostDocument.ResolveReferenceTo<OpenApiParameter>(_reference);
OpenApiParameter resolved = new OpenApiParameter(_target);
if (!string.IsNullOrEmpty(_description)) resolved.Description = _description;
return resolved;
if (!string.IsNullOrEmpty(_description)) _target.Description = _description;
return _target;
}
}

Expand Down Expand Up @@ -73,39 +72,48 @@ internal OpenApiParameterReference(OpenApiParameter target, string referenceId)
};
}

private string _name;
/// <inheritdoc/>
public override string Name { get => Target.Name; set => Target.Name = value; }
public override string Name { get => !string.IsNullOrEmpty(_name) ? _name : Target?.Name; set => _name = value; }

/// <inheritdoc/>
public override string Description
{
get => string.IsNullOrEmpty(_description) ? Target.Description : _description;
get => string.IsNullOrEmpty(_description) ? Target?.Description : _description;
set => _description = value;
}

private bool? _required;
/// <inheritdoc/>
public override bool Required { get => Target.Required; set => Target.Required = value; }
public override bool Required { get => _required is not null ? _required.Value : Target?.Required ?? false; set => _required = value; }

private bool? _deprecated;
/// <inheritdoc/>
public override bool Deprecated { get => Target.Deprecated; set => Target.Deprecated = value; }
public override bool Deprecated { get => _deprecated is not null ? _deprecated.Value : Target?.Deprecated ?? false; set => _deprecated = value; }

private bool? _allowEmptyValue;
/// <inheritdoc/>
public override bool AllowEmptyValue { get => Target.AllowEmptyValue; set => Target.AllowEmptyValue = value; }
public override bool AllowEmptyValue { get => _allowEmptyValue is not null ? _allowEmptyValue.Value : Target?.AllowEmptyValue ?? false; set => _allowEmptyValue = value; }

private bool? _allowReserved;
/// <inheritdoc/>
public override bool AllowReserved { get => Target.AllowReserved; set => Target.AllowReserved = value; }
public override bool AllowReserved { get => _allowReserved is not null ? _allowReserved.Value : Target?.AllowReserved ?? false; set => _allowReserved = value; }

private OpenApiSchema _schema;
/// <inheritdoc/>
public override OpenApiSchema Schema { get => Target.Schema; set => Target.Schema = value; }
public override OpenApiSchema Schema { get => _schema is not null ? _schema : Target?.Schema; set => _schema = value; }

private JsonNode _example;
/// <inheritdoc/>
public override IDictionary<string, OpenApiExample> Examples { get => Target.Examples; set => Target.Examples = value; }
public override JsonNode Example { get => _example is not null ? _example : Target?.Example; set => _example = value; }

private IDictionary<string, OpenApiExample> _examples;
/// <inheritdoc/>
public override JsonNode Example { get => Target.Example; set => Target.Example = value; }
public override IDictionary<string, OpenApiExample> Examples { get => _examples is not null ? _examples : Target?.Examples; set => _examples = value; }

private ParameterLocation? _in;
/// <inheritdoc/>
public override ParameterLocation? In { get => Target.In; set => Target.In = value; }
public override ParameterLocation? In { get => _in is not null ? _in : Target?.In; set => _in = value; }

/// <inheritdoc/>
public override ParameterStyle? Style
Expand All @@ -121,12 +129,14 @@ public override bool Explode
set => _explode = value;
}

private IDictionary<string, OpenApiMediaType> _content;
/// <inheritdoc/>
public override IDictionary<string, OpenApiMediaType> Content { get => Target.Content; set => Target.Content = value; }
public override IDictionary<string, OpenApiMediaType> Content { get => _content is not null ? _content : Target?.Content; set => _content = value; }

private IDictionary<string, IOpenApiExtension> _extensions;
/// <inheritdoc/>
public override IDictionary<string, IOpenApiExtension> Extensions { get => Target.Extensions; set => Target.Extensions = value; }
public override IDictionary<string, IOpenApiExtension> Extensions { get => _extensions is not null ? _extensions : Target?.Extensions; set => _extensions = value; }

/// <inheritdoc/>
public override void SerializeAsV3(IOpenApiWriter writer)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,9 @@ public OpenApiPathItem Target
get
{
_target ??= Reference.HostDocument.ResolveReferenceTo<OpenApiPathItem>(_reference);
OpenApiPathItem resolved = new OpenApiPathItem(_target);
if (!string.IsNullOrEmpty(_description)) resolved.Description = _description;
if (!string.IsNullOrEmpty(_summary)) resolved.Summary = _summary;
return resolved;
if (!string.IsNullOrEmpty(_description)) _target.Description = _description;
if (!string.IsNullOrEmpty(_summary)) _target.Summary = _summary;
return _target;
}
}

Expand Down Expand Up @@ -75,29 +74,33 @@ internal OpenApiPathItemReference(OpenApiPathItem target, string referenceId)
/// <inheritdoc/>
public override string Summary
{
get => string.IsNullOrEmpty(_summary) ? Target.Summary : _summary;
get => string.IsNullOrEmpty(_summary) ? Target?.Summary : _summary;
set => _summary = value;
}

/// <inheritdoc/>
public override string Description
{
get => string.IsNullOrEmpty(_description) ? Target.Description : _description;
get => string.IsNullOrEmpty(_description) ? Target?.Description : _description;
set => _description = value;
}

private IDictionary<OperationType, OpenApiOperation> _operations;
/// <inheritdoc/>
public override IDictionary<OperationType, OpenApiOperation> Operations { get => Target.Operations; set => Target.Operations = value; }
public override IDictionary<OperationType, OpenApiOperation> Operations { get => _operations is not null ? _operations : Target?.Operations; set => _operations = value; }

private IList<OpenApiServer> _servers;
/// <inheritdoc/>
public override IList<OpenApiServer> Servers { get => Target.Servers; set => Target.Servers = value; }
public override IList<OpenApiServer> Servers { get => _servers is not null ? _servers : Target?.Servers; set => _servers = value; }

private IList<OpenApiParameter> _parameters;
/// <inheritdoc/>
public override IList<OpenApiParameter> Parameters { get => Target.Parameters; set => Target.Parameters = value; }
public override IList<OpenApiParameter> Parameters { get => _parameters is not null ? _parameters : Target?.Parameters; set => _parameters = value; }

private IDictionary<string, IOpenApiExtension> _extensions;
/// <inheritdoc/>
public override IDictionary<string, IOpenApiExtension> Extensions { get => Target.Extensions; set => Target.Extensions = value; }
public override IDictionary<string, IOpenApiExtension> Extensions { get => _extensions is not null ? _extensions : Target?.Extensions; set => _extensions = value; }

/// <inheritdoc/>
public override void SerializeAsV31(IOpenApiWriter writer)
{
Expand Down
Loading
Loading