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/reference copy #2046

Merged
merged 10 commits into from
Jan 21, 2025
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
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
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
Loading