Skip to content

Commit

Permalink
Merge pull request #2046 from microsoft/fix/reference-copy
Browse files Browse the repository at this point in the history
fix/reference copy
  • Loading branch information
baywet authored Jan 21, 2025
2 parents b522f9f + 6e904d0 commit 995528e
Show file tree
Hide file tree
Showing 16 changed files with 370 additions and 188 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.

namespace Microsoft.OpenApi.Interfaces
{
/// <summary>
/// A generic interface for OpenApiReferenceable objects that have a target.
/// </summary>
/// <typeparam name="T"></typeparam>
public interface IOpenApiReferenceableWithTarget<T> : IOpenApiReferenceable
{
/// <summary>
/// Gets the resolved target object.
/// </summary>
T Target { get; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,20 @@ namespace Microsoft.OpenApi.Models.References
/// <summary>
/// Callback Object Reference: A reference to a map of possible out-of band callbacks related to the parent operation.
/// </summary>
public class OpenApiCallbackReference : OpenApiCallback
public class OpenApiCallbackReference : OpenApiCallback, IOpenApiReferenceableWithTarget<OpenApiCallback>
{
#nullable enable
internal OpenApiCallback _target;
private readonly OpenApiReference _reference;

private OpenApiCallback Target
/// <summary>
/// Gets the target callback.
/// </summary>
/// <remarks>
/// If the reference is not resolved, this will return null.
/// </remarks>
public OpenApiCallback Target
#nullable restore
{
get
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,20 @@ namespace Microsoft.OpenApi.Models.References
/// <summary>
/// Example Object Reference.
/// </summary>
public class OpenApiExampleReference : OpenApiExample
public class OpenApiExampleReference : OpenApiExample, IOpenApiReferenceableWithTarget<OpenApiExample>
{
internal OpenApiExample _target;
private readonly OpenApiReference _reference;
private string _summary;
private string _description;

private OpenApiExample Target
/// <summary>
/// Gets the target example.
/// </summary>
/// <remarks>
/// If the reference is not resolved, this will return null.
/// </remarks>
public OpenApiExample Target
{
get
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,19 @@ namespace Microsoft.OpenApi.Models.References
/// <summary>
/// Header Object Reference.
/// </summary>
public class OpenApiHeaderReference : OpenApiHeader
public class OpenApiHeaderReference : OpenApiHeader, IOpenApiReferenceableWithTarget<OpenApiHeader>
{
internal OpenApiHeader _target;
private readonly OpenApiReference _reference;
private string _description;

private OpenApiHeader Target
/// <summary>
/// Gets the target header.
/// </summary>
/// <remarks>
/// If the reference is not resolved, this will return null.
/// </remarks>
public OpenApiHeader Target
{
get
{
Expand Down
10 changes: 8 additions & 2 deletions src/Microsoft.OpenApi/Models/References/OpenApiLinkReference.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,19 @@ namespace Microsoft.OpenApi.Models.References
/// <summary>
/// Link Object Reference.
/// </summary>
public class OpenApiLinkReference : OpenApiLink
public class OpenApiLinkReference : OpenApiLink, IOpenApiReferenceableWithTarget<OpenApiLink>
{
internal OpenApiLink _target;
private readonly OpenApiReference _reference;
private string _description;

private OpenApiLink Target
/// <summary>
/// Gets the target link.
/// </summary>
/// <remarks>
/// If the reference is not resolved, this will return null.
/// </remarks>
public OpenApiLink Target
{
get
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,21 @@ namespace Microsoft.OpenApi.Models.References
/// <summary>
/// Parameter Object Reference.
/// </summary>
public class OpenApiParameterReference : OpenApiParameter
public class OpenApiParameterReference : OpenApiParameter, IOpenApiReferenceableWithTarget<OpenApiParameter>
{
internal OpenApiParameter _target;
private readonly OpenApiReference _reference;
private string _description;
private bool? _explode;
private ParameterStyle? _style;

private OpenApiParameter Target
/// <summary>
/// Gets the target parameter.
/// </summary>
/// <remarks>
/// If the reference is not resolved, this will return null.
/// </remarks>
public OpenApiParameter Target
{
get
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,20 @@ namespace Microsoft.OpenApi.Models.References
/// <summary>
/// Path Item Object Reference: to describe the operations available on a single path.
/// </summary>
public class OpenApiPathItemReference : OpenApiPathItem
public class OpenApiPathItemReference : OpenApiPathItem, IOpenApiReferenceableWithTarget<OpenApiPathItem>
{
internal OpenApiPathItem _target;
private readonly OpenApiReference _reference;
private string _description;
private string _summary;

private OpenApiPathItem Target
/// <summary>
/// Gets the target path item.
/// </summary>
/// <remarks>
/// If the reference is not resolved, this will return null.
/// </remarks>
public OpenApiPathItem Target
{
get
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,19 @@ namespace Microsoft.OpenApi.Models.References
/// <summary>
/// Request Body Object Reference.
/// </summary>
public class OpenApiRequestBodyReference : OpenApiRequestBody
public class OpenApiRequestBodyReference : OpenApiRequestBody, IOpenApiReferenceableWithTarget<OpenApiRequestBody>
{
internal OpenApiRequestBody _target;
private readonly OpenApiReference _reference;
private string _description;

private OpenApiRequestBody Target
/// <summary>
/// Gets the target request body.
/// </summary>
/// <remarks>
/// If the reference is not resolved, this will return null.
/// </remarks>
public OpenApiRequestBody Target
{
get
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,19 @@ namespace Microsoft.OpenApi.Models.References
/// <summary>
/// Response Object Reference.
/// </summary>
public class OpenApiResponseReference : OpenApiResponse
public class OpenApiResponseReference : OpenApiResponse, IOpenApiReferenceableWithTarget<OpenApiResponse>
{
internal OpenApiResponse _target;
private readonly OpenApiReference _reference;
private string _description;

private OpenApiResponse Target
/// <summary>
/// Gets the target response.
/// </summary>
/// <remarks>
/// If the reference is not resolved, this will return null.
/// </remarks>
public OpenApiResponse Target
{
get
{
Expand Down
18 changes: 12 additions & 6 deletions src/Microsoft.OpenApi/Models/References/OpenApiSchemaReference.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ namespace Microsoft.OpenApi.Models.References
/// <summary>
/// Schema reference object
/// </summary>
public class OpenApiSchemaReference : OpenApiSchema
public class OpenApiSchemaReference : OpenApiSchema, IOpenApiReferenceableWithTarget<OpenApiSchema>
{
#nullable enable
#nullable enable
private OpenApiSchema? _target;
private readonly OpenApiReference _reference;
private string? _description;
Expand Down Expand Up @@ -69,8 +69,14 @@ public class OpenApiSchemaReference : OpenApiSchema
private bool? _unevaluatedProperties;
private IList<JsonNode>? _enum;

private OpenApiSchema? Target
#nullable restore
/// <summary>
/// Gets the target schema.
/// </summary>
/// <remarks>
/// If the reference is not resolved, this will return null.
/// </remarks>
public OpenApiSchema? Target
#nullable restore
{
get
{
Expand Down Expand Up @@ -190,7 +196,7 @@ public override string Description
/// <inheritdoc/>
public override bool? UniqueItems { get => _uniqueItems is not null ? _uniqueItems : Target?.UniqueItems; set => _uniqueItems = value; }
/// <inheritdoc/>
public override IDictionary<string, OpenApiSchema> Properties { get => _properties is not null ? _properties : Target?.Properties ; set => _properties = value; }
public override IDictionary<string, OpenApiSchema> Properties { get => _properties is not null ? _properties : Target?.Properties; set => _properties = value; }
/// <inheritdoc/>
public override IDictionary<string, OpenApiSchema> PatternProperties { get => _patternProperties is not null ? _patternProperties : Target?.PatternProperties; set => _patternProperties = value; }
/// <inheritdoc/>
Expand Down Expand Up @@ -257,7 +263,7 @@ public override void SerializeAsV3(IOpenApiWriter writer)
_reference.SerializeAsV3(writer);
return;
}

SerializeInternal(writer, (writer, element) => element.SerializeAsV3(writer));
writer.GetSettings().LoopDetector.PopLoop<OpenApiSchema>();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,19 @@ namespace Microsoft.OpenApi.Models.References
/// <summary>
/// Security Scheme Object Reference.
/// </summary>
public class OpenApiSecuritySchemeReference : OpenApiSecurityScheme
public class OpenApiSecuritySchemeReference : OpenApiSecurityScheme, IOpenApiReferenceableWithTarget<OpenApiSecurityScheme>
{
internal OpenApiSecurityScheme _target;
private readonly OpenApiReference _reference;
private string _description;

private OpenApiSecurityScheme Target
/// <summary>
/// Gets the target security scheme.
/// </summary>
/// <remarks>
/// If the reference is not resolved, this will return null.
/// </remarks>
public OpenApiSecurityScheme Target
{
get
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace Microsoft.OpenApi.Models.References
/// <summary>
/// Tag Object Reference
/// </summary>
public class OpenApiTagReference : OpenApiTag, IOpenApiReferenceable
public class OpenApiTagReference : OpenApiTag, IOpenApiReferenceableWithTarget<OpenApiTag>
{
internal OpenApiTag _target;

Expand Down
Loading

0 comments on commit 995528e

Please sign in to comment.