From 66e4101c3d656b5e557ed9dfa9b120a9850c0df1 Mon Sep 17 00:00:00 2001 From: Vincent Biret Date: Wed, 8 Jan 2025 10:57:03 -0500 Subject: [PATCH 1/6] chore: removes unused method --- src/Microsoft.OpenApi/Writers/OpenApiWriterSettings.cs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/Microsoft.OpenApi/Writers/OpenApiWriterSettings.cs b/src/Microsoft.OpenApi/Writers/OpenApiWriterSettings.cs index f05fd13a7..09a65cc83 100644 --- a/src/Microsoft.OpenApi/Writers/OpenApiWriterSettings.cs +++ b/src/Microsoft.OpenApi/Writers/OpenApiWriterSettings.cs @@ -26,10 +26,5 @@ internal bool ShouldInlineReference(OpenApiReference reference) return (reference.IsLocal && InlineLocalReferences) || (reference.IsExternal && InlineExternalReferences); } - - internal bool ShouldInlineReference() - { - return InlineLocalReferences || InlineExternalReferences; - } } } From 88daad5d31fee2f4826be9717ece808495d9b4d8 Mon Sep 17 00:00:00 2001 From: Vincent Biret Date: Wed, 8 Jan 2025 10:57:53 -0500 Subject: [PATCH 2/6] fix: components schema copy --- .../References/OpenApiSchemaReference.cs | 16 +- .../Services/CopyReferences.cs | 304 +++++++++--------- .../PublicApi/PublicApi.approved.txt | 1 + 3 files changed, 163 insertions(+), 158 deletions(-) diff --git a/src/Microsoft.OpenApi/Models/References/OpenApiSchemaReference.cs b/src/Microsoft.OpenApi/Models/References/OpenApiSchemaReference.cs index 41a1dceb5..62cb0bae4 100644 --- a/src/Microsoft.OpenApi/Models/References/OpenApiSchemaReference.cs +++ b/src/Microsoft.OpenApi/Models/References/OpenApiSchemaReference.cs @@ -14,7 +14,7 @@ namespace Microsoft.OpenApi.Models.References /// public class OpenApiSchemaReference : OpenApiSchema { - #nullable enable +#nullable enable private OpenApiSchema? _target; private readonly OpenApiReference _reference; private string? _description; @@ -69,8 +69,14 @@ public class OpenApiSchemaReference : OpenApiSchema private bool? _unevaluatedProperties; private IList? _enum; - private OpenApiSchema? Target - #nullable restore + /// + /// Gets the target schema. + /// + /// + /// If the reference is not resolved, this will return null. + /// + public OpenApiSchema? Target +#nullable restore { get { @@ -190,7 +196,7 @@ public override string Description /// public override bool? UniqueItems { get => _uniqueItems is not null ? _uniqueItems : Target?.UniqueItems; set => _uniqueItems = value; } /// - public override IDictionary Properties { get => _properties is not null ? _properties : Target?.Properties ; set => _properties = value; } + public override IDictionary Properties { get => _properties is not null ? _properties : Target?.Properties; set => _properties = value; } /// public override IDictionary PatternProperties { get => _patternProperties is not null ? _patternProperties : Target?.PatternProperties; set => _patternProperties = value; } /// @@ -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(); } diff --git a/src/Microsoft.OpenApi/Services/CopyReferences.cs b/src/Microsoft.OpenApi/Services/CopyReferences.cs index 73bb667b6..f12b11f28 100644 --- a/src/Microsoft.OpenApi/Services/CopyReferences.cs +++ b/src/Microsoft.OpenApi/Services/CopyReferences.cs @@ -4,183 +4,181 @@ using System.Collections.Generic; using Microsoft.OpenApi.Interfaces; using Microsoft.OpenApi.Models; +using Microsoft.OpenApi.Models.References; -namespace Microsoft.OpenApi.Services +namespace Microsoft.OpenApi.Services; +internal class CopyReferences(OpenApiDocument target) : OpenApiVisitorBase { - internal class CopyReferences : OpenApiVisitorBase + private readonly OpenApiDocument _target = target; + public OpenApiComponents Components = new(); + + /// + /// Visits IOpenApiReferenceable instances that are references and not in components. + /// + /// An IOpenApiReferenceable object. + public override void Visit(IOpenApiReferenceable referenceable) { - private readonly OpenApiDocument _target; - public OpenApiComponents Components = new(); - - public CopyReferences(OpenApiDocument target) + switch (referenceable) { - _target = target; - } + case OpenApiSchemaReference openApiSchemaReference: + AddSchemaToComponents(openApiSchemaReference.Target, openApiSchemaReference.Reference.Id); + break; + case OpenApiSchema schema: + AddSchemaToComponents(schema); + break; + + case OpenApiParameter parameter: + EnsureComponentsExist(); + EnsureParametersExist(); + if (!Components.Parameters.ContainsKey(parameter.Reference.Id)) + { + Components.Parameters.Add(parameter.Reference.Id, parameter); + } + break; - /// - /// Visits IOpenApiReferenceable instances that are references and not in components. - /// - /// An IOpenApiReferenceable object. - public override void Visit(IOpenApiReferenceable referenceable) - { - switch (referenceable) - { - case OpenApiSchema schema: - EnsureComponentsExist(); - EnsureSchemasExist(); - if (!Components.Schemas.ContainsKey(schema.Reference.Id)) - { - Components.Schemas.Add(schema.Reference.Id, schema); - } - break; - - case OpenApiParameter parameter: - EnsureComponentsExist(); - EnsureParametersExist(); - if (!Components.Parameters.ContainsKey(parameter.Reference.Id)) - { - Components.Parameters.Add(parameter.Reference.Id, parameter); - } - break; - - case OpenApiResponse response: - EnsureComponentsExist(); - EnsureResponsesExist(); - if (!Components.Responses.ContainsKey(response.Reference.Id)) - { - Components.Responses.Add(response.Reference.Id, response); - } - break; - - case OpenApiRequestBody requestBody: - EnsureComponentsExist(); - EnsureResponsesExist(); - EnsureRequestBodiesExist(); - if (!Components.RequestBodies.ContainsKey(requestBody.Reference.Id)) - { - Components.RequestBodies.Add(requestBody.Reference.Id, requestBody); - } - break; - - case OpenApiExample example: - EnsureComponentsExist(); - EnsureExamplesExist(); - if (!Components.Examples.ContainsKey(example.Reference.Id)) - { - Components.Examples.Add(example.Reference.Id, example); - } - break; - - case OpenApiHeader header: - EnsureComponentsExist(); - EnsureHeadersExist(); - if (!Components.Headers.ContainsKey(header.Reference.Id)) - { - Components.Headers.Add(header.Reference.Id, header); - } - break; - - case OpenApiCallback callback: - EnsureComponentsExist(); - EnsureCallbacksExist(); - if (!Components.Callbacks.ContainsKey(callback.Reference.Id)) - { - Components.Callbacks.Add(callback.Reference.Id, callback); - } - break; - - case OpenApiLink link: - EnsureComponentsExist(); - EnsureLinksExist(); - if (!Components.Links.ContainsKey(link.Reference.Id)) - { - Components.Links.Add(link.Reference.Id, link); - } - break; - - case OpenApiSecurityScheme securityScheme: - EnsureComponentsExist(); - EnsureSecuritySchemesExist(); - if (!Components.SecuritySchemes.ContainsKey(securityScheme.Reference.Id)) - { - Components.SecuritySchemes.Add(securityScheme.Reference.Id, securityScheme); - } - break; - - default: - break; - } - - base.Visit(referenceable); - } + case OpenApiResponse response: + EnsureComponentsExist(); + EnsureResponsesExist(); + if (!Components.Responses.ContainsKey(response.Reference.Id)) + { + Components.Responses.Add(response.Reference.Id, response); + } + break; - /// - /// Visits - /// - /// The OpenApiSchema to be visited. - public override void Visit(OpenApiSchema schema) - { - // This is needed to handle schemas used in Responses in components - if (schema.Reference != null) - { + case OpenApiRequestBody requestBody: EnsureComponentsExist(); - EnsureSchemasExist(); - if (!Components.Schemas.ContainsKey(schema.Reference.Id)) + EnsureResponsesExist(); + EnsureRequestBodiesExist(); + if (!Components.RequestBodies.ContainsKey(requestBody.Reference.Id)) { - Components.Schemas.Add(schema.Reference.Id, schema); + Components.RequestBodies.Add(requestBody.Reference.Id, requestBody); } - } - base.Visit(schema); - } + break; - private void EnsureComponentsExist() - { - _target.Components ??= new(); - } + case OpenApiExample example: + EnsureComponentsExist(); + EnsureExamplesExist(); + if (!Components.Examples.ContainsKey(example.Reference.Id)) + { + Components.Examples.Add(example.Reference.Id, example); + } + break; - private void EnsureSchemasExist() - { - _target.Components.Schemas ??= new Dictionary(); - } + case OpenApiHeader header: + EnsureComponentsExist(); + EnsureHeadersExist(); + if (!Components.Headers.ContainsKey(header.Reference.Id)) + { + Components.Headers.Add(header.Reference.Id, header); + } + break; - private void EnsureParametersExist() - { - _target.Components.Parameters ??= new Dictionary(); - } + case OpenApiCallback callback: + EnsureComponentsExist(); + EnsureCallbacksExist(); + if (!Components.Callbacks.ContainsKey(callback.Reference.Id)) + { + Components.Callbacks.Add(callback.Reference.Id, callback); + } + break; - private void EnsureResponsesExist() - { - _target.Components.Responses ??= new Dictionary(); - } + case OpenApiLink link: + EnsureComponentsExist(); + EnsureLinksExist(); + if (!Components.Links.ContainsKey(link.Reference.Id)) + { + Components.Links.Add(link.Reference.Id, link); + } + break; - private void EnsureRequestBodiesExist() - { - _target.Components.RequestBodies ??= new Dictionary(); - } + case OpenApiSecurityScheme securityScheme: + EnsureComponentsExist(); + EnsureSecuritySchemesExist(); + if (!Components.SecuritySchemes.ContainsKey(securityScheme.Reference.Id)) + { + Components.SecuritySchemes.Add(securityScheme.Reference.Id, securityScheme); + } + break; - private void EnsureExamplesExist() - { - _target.Components.Examples ??= new Dictionary(); + default: + break; } - private void EnsureHeadersExist() - { - _target.Components.Headers ??= new Dictionary(); - } + base.Visit(referenceable); + } - private void EnsureCallbacksExist() + private void AddSchemaToComponents(OpenApiSchema schema, string referenceId = null) + { + EnsureComponentsExist(); + EnsureSchemasExist(); + if (!Components.Schemas.ContainsKey(referenceId ?? schema.Reference.Id)) { - _target.Components.Callbacks ??= new Dictionary(); + Components.Schemas.Add(referenceId ?? schema.Reference.Id, schema); } + } - private void EnsureLinksExist() + /// + public override void Visit(OpenApiSchema schema) + { + // This is needed to handle schemas used in Responses in components + if (schema is OpenApiSchemaReference openApiSchemaReference) { - _target.Components.Links ??= new Dictionary(); + AddSchemaToComponents(openApiSchemaReference.Target, openApiSchemaReference.Reference.Id); } - - private void EnsureSecuritySchemesExist() + else if (schema.Reference != null) { - _target.Components.SecuritySchemes ??= new Dictionary(); + AddSchemaToComponents(schema); } + base.Visit(schema); + } + + private void EnsureComponentsExist() + { + _target.Components ??= new(); + } + + private void EnsureSchemasExist() + { + _target.Components.Schemas ??= new Dictionary(); + } + + private void EnsureParametersExist() + { + _target.Components.Parameters ??= new Dictionary(); + } + + private void EnsureResponsesExist() + { + _target.Components.Responses ??= new Dictionary(); + } + + private void EnsureRequestBodiesExist() + { + _target.Components.RequestBodies ??= new Dictionary(); + } + + private void EnsureExamplesExist() + { + _target.Components.Examples ??= new Dictionary(); + } + + private void EnsureHeadersExist() + { + _target.Components.Headers ??= new Dictionary(); + } + + private void EnsureCallbacksExist() + { + _target.Components.Callbacks ??= new Dictionary(); + } + + private void EnsureLinksExist() + { + _target.Components.Links ??= new Dictionary(); + } + + private void EnsureSecuritySchemesExist() + { + _target.Components.SecuritySchemes ??= new Dictionary(); } } diff --git a/test/Microsoft.OpenApi.Tests/PublicApi/PublicApi.approved.txt b/test/Microsoft.OpenApi.Tests/PublicApi/PublicApi.approved.txt index 88599f6ef..557266d9d 100644 --- a/test/Microsoft.OpenApi.Tests/PublicApi/PublicApi.approved.txt +++ b/test/Microsoft.OpenApi.Tests/PublicApi/PublicApi.approved.txt @@ -1212,6 +1212,7 @@ namespace Microsoft.OpenApi.Models.References public class OpenApiSchemaReference : Microsoft.OpenApi.Models.OpenApiSchema { public OpenApiSchemaReference(string referenceId, Microsoft.OpenApi.Models.OpenApiDocument hostDocument, string externalResource = null) { } + public Microsoft.OpenApi.Models.OpenApiSchema? Target { get; } public override Microsoft.OpenApi.Models.OpenApiSchema AdditionalProperties { get; set; } public override bool AdditionalPropertiesAllowed { get; set; } public override System.Collections.Generic.IList AllOf { get; set; } From 962e929703a6ccbc5836924e8c0d692bac3f3cea Mon Sep 17 00:00:00 2001 From: Maggiekimani1 Date: Fri, 17 Jan 2025 11:16:20 +0300 Subject: [PATCH 3/6] Replicate copying logic for other component types --- .../References/OpenApiCallbackReference.cs | 12 +- .../References/OpenApiExampleReference.cs | 10 +- .../References/OpenApiHeaderReference.cs | 10 +- .../Models/References/OpenApiLinkReference.cs | 10 +- .../References/OpenApiParameterReference.cs | 10 +- .../References/OpenApiPathItemReference.cs | 10 +- .../References/OpenApiRequestBodyReference.cs | 10 +- .../References/OpenApiResponseReference.cs | 10 +- .../References/OpenApiSchemaReference.cs | 2 +- .../OpenApiSecuritySchemeReference.cs | 10 +- .../Services/CopyReferences.cs | 177 ++++++++++++------ 11 files changed, 194 insertions(+), 77 deletions(-) diff --git a/src/Microsoft.OpenApi/Models/References/OpenApiCallbackReference.cs b/src/Microsoft.OpenApi/Models/References/OpenApiCallbackReference.cs index 632aa485f..2d610336f 100644 --- a/src/Microsoft.OpenApi/Models/References/OpenApiCallbackReference.cs +++ b/src/Microsoft.OpenApi/Models/References/OpenApiCallbackReference.cs @@ -12,12 +12,20 @@ namespace Microsoft.OpenApi.Models.References /// /// Callback Object Reference: A reference to a map of possible out-of band callbacks related to the parent operation. /// - public class OpenApiCallbackReference : OpenApiCallback + public class OpenApiCallbackReference : OpenApiCallback, IOpenApiReferenceable { +#nullable enable internal OpenApiCallback _target; private readonly OpenApiReference _reference; - private OpenApiCallback Target + /// + /// Gets the target callback. + /// + /// + /// If the reference is not resolved, this will return null. + /// + public OpenApiCallback Target +#nullable restore { get { diff --git a/src/Microsoft.OpenApi/Models/References/OpenApiExampleReference.cs b/src/Microsoft.OpenApi/Models/References/OpenApiExampleReference.cs index 310ff0a8e..d471977f6 100644 --- a/src/Microsoft.OpenApi/Models/References/OpenApiExampleReference.cs +++ b/src/Microsoft.OpenApi/Models/References/OpenApiExampleReference.cs @@ -12,14 +12,20 @@ namespace Microsoft.OpenApi.Models.References /// /// Example Object Reference. /// - public class OpenApiExampleReference : OpenApiExample + public class OpenApiExampleReference : OpenApiExample, IOpenApiReferenceable { internal OpenApiExample _target; private readonly OpenApiReference _reference; private string _summary; private string _description; - private OpenApiExample Target + /// + /// Gets the target example. + /// + /// + /// If the reference is not resolved, this will return null. + /// + public OpenApiExample Target { get { diff --git a/src/Microsoft.OpenApi/Models/References/OpenApiHeaderReference.cs b/src/Microsoft.OpenApi/Models/References/OpenApiHeaderReference.cs index 2ffb0c3de..a3961be76 100644 --- a/src/Microsoft.OpenApi/Models/References/OpenApiHeaderReference.cs +++ b/src/Microsoft.OpenApi/Models/References/OpenApiHeaderReference.cs @@ -12,13 +12,19 @@ namespace Microsoft.OpenApi.Models.References /// /// Header Object Reference. /// - public class OpenApiHeaderReference : OpenApiHeader + public class OpenApiHeaderReference : OpenApiHeader, IOpenApiReferenceable { internal OpenApiHeader _target; private readonly OpenApiReference _reference; private string _description; - private OpenApiHeader Target + /// + /// Gets the target header. + /// + /// + /// If the reference is not resolved, this will return null. + /// + public OpenApiHeader Target { get { diff --git a/src/Microsoft.OpenApi/Models/References/OpenApiLinkReference.cs b/src/Microsoft.OpenApi/Models/References/OpenApiLinkReference.cs index a3c33503e..55574666c 100644 --- a/src/Microsoft.OpenApi/Models/References/OpenApiLinkReference.cs +++ b/src/Microsoft.OpenApi/Models/References/OpenApiLinkReference.cs @@ -11,13 +11,19 @@ namespace Microsoft.OpenApi.Models.References /// /// Link Object Reference. /// - public class OpenApiLinkReference : OpenApiLink + public class OpenApiLinkReference : OpenApiLink, IOpenApiReferenceable { internal OpenApiLink _target; private readonly OpenApiReference _reference; private string _description; - private OpenApiLink Target + /// + /// Gets the target link. + /// + /// + /// If the reference is not resolved, this will return null. + /// + public OpenApiLink Target { get { diff --git a/src/Microsoft.OpenApi/Models/References/OpenApiParameterReference.cs b/src/Microsoft.OpenApi/Models/References/OpenApiParameterReference.cs index 2c2a6c90d..c0549798f 100644 --- a/src/Microsoft.OpenApi/Models/References/OpenApiParameterReference.cs +++ b/src/Microsoft.OpenApi/Models/References/OpenApiParameterReference.cs @@ -12,7 +12,7 @@ namespace Microsoft.OpenApi.Models.References /// /// Parameter Object Reference. /// - public class OpenApiParameterReference : OpenApiParameter + public class OpenApiParameterReference : OpenApiParameter, IOpenApiReferenceable { internal OpenApiParameter _target; private readonly OpenApiReference _reference; @@ -20,7 +20,13 @@ public class OpenApiParameterReference : OpenApiParameter private bool? _explode; private ParameterStyle? _style; - private OpenApiParameter Target + /// + /// Gets the target parameter. + /// + /// + /// If the reference is not resolved, this will return null. + /// + public OpenApiParameter Target { get { diff --git a/src/Microsoft.OpenApi/Models/References/OpenApiPathItemReference.cs b/src/Microsoft.OpenApi/Models/References/OpenApiPathItemReference.cs index f757b7a07..d22c8340f 100644 --- a/src/Microsoft.OpenApi/Models/References/OpenApiPathItemReference.cs +++ b/src/Microsoft.OpenApi/Models/References/OpenApiPathItemReference.cs @@ -11,14 +11,20 @@ namespace Microsoft.OpenApi.Models.References /// /// Path Item Object Reference: to describe the operations available on a single path. /// - public class OpenApiPathItemReference : OpenApiPathItem + public class OpenApiPathItemReference : OpenApiPathItem, IOpenApiReferenceable { internal OpenApiPathItem _target; private readonly OpenApiReference _reference; private string _description; private string _summary; - private OpenApiPathItem Target + /// + /// Gets the target path item. + /// + /// + /// If the reference is not resolved, this will return null. + /// + public OpenApiPathItem Target { get { diff --git a/src/Microsoft.OpenApi/Models/References/OpenApiRequestBodyReference.cs b/src/Microsoft.OpenApi/Models/References/OpenApiRequestBodyReference.cs index 8e3a81ad8..89375d665 100644 --- a/src/Microsoft.OpenApi/Models/References/OpenApiRequestBodyReference.cs +++ b/src/Microsoft.OpenApi/Models/References/OpenApiRequestBodyReference.cs @@ -11,13 +11,19 @@ namespace Microsoft.OpenApi.Models.References /// /// Request Body Object Reference. /// - public class OpenApiRequestBodyReference : OpenApiRequestBody + public class OpenApiRequestBodyReference : OpenApiRequestBody, IOpenApiReferenceable { internal OpenApiRequestBody _target; private readonly OpenApiReference _reference; private string _description; - private OpenApiRequestBody Target + /// + /// Gets the target request body. + /// + /// + /// If the reference is not resolved, this will return null. + /// + public OpenApiRequestBody Target { get { diff --git a/src/Microsoft.OpenApi/Models/References/OpenApiResponseReference.cs b/src/Microsoft.OpenApi/Models/References/OpenApiResponseReference.cs index c24652504..437d34c19 100644 --- a/src/Microsoft.OpenApi/Models/References/OpenApiResponseReference.cs +++ b/src/Microsoft.OpenApi/Models/References/OpenApiResponseReference.cs @@ -11,13 +11,19 @@ namespace Microsoft.OpenApi.Models.References /// /// Response Object Reference. /// - public class OpenApiResponseReference : OpenApiResponse + public class OpenApiResponseReference : OpenApiResponse, IOpenApiReferenceable { internal OpenApiResponse _target; private readonly OpenApiReference _reference; private string _description; - private OpenApiResponse Target + /// + /// Gets the target response. + /// + /// + /// If the reference is not resolved, this will return null. + /// + public OpenApiResponse Target { get { diff --git a/src/Microsoft.OpenApi/Models/References/OpenApiSchemaReference.cs b/src/Microsoft.OpenApi/Models/References/OpenApiSchemaReference.cs index 62cb0bae4..b5b7fb4a1 100644 --- a/src/Microsoft.OpenApi/Models/References/OpenApiSchemaReference.cs +++ b/src/Microsoft.OpenApi/Models/References/OpenApiSchemaReference.cs @@ -12,7 +12,7 @@ namespace Microsoft.OpenApi.Models.References /// /// Schema reference object /// - public class OpenApiSchemaReference : OpenApiSchema + public class OpenApiSchemaReference : OpenApiSchema, IOpenApiReferenceable { #nullable enable private OpenApiSchema? _target; diff --git a/src/Microsoft.OpenApi/Models/References/OpenApiSecuritySchemeReference.cs b/src/Microsoft.OpenApi/Models/References/OpenApiSecuritySchemeReference.cs index faf6ae3bc..7b5064309 100644 --- a/src/Microsoft.OpenApi/Models/References/OpenApiSecuritySchemeReference.cs +++ b/src/Microsoft.OpenApi/Models/References/OpenApiSecuritySchemeReference.cs @@ -11,13 +11,19 @@ namespace Microsoft.OpenApi.Models.References /// /// Security Scheme Object Reference. /// - public class OpenApiSecuritySchemeReference : OpenApiSecurityScheme + public class OpenApiSecuritySchemeReference : OpenApiSecurityScheme, IOpenApiReferenceable { internal OpenApiSecurityScheme _target; private readonly OpenApiReference _reference; private string _description; - private OpenApiSecurityScheme Target + /// + /// Gets the target security scheme. + /// + /// + /// If the reference is not resolved, this will return null. + /// + public OpenApiSecurityScheme Target { get { diff --git a/src/Microsoft.OpenApi/Services/CopyReferences.cs b/src/Microsoft.OpenApi/Services/CopyReferences.cs index f12b11f28..c122d5132 100644 --- a/src/Microsoft.OpenApi/Services/CopyReferences.cs +++ b/src/Microsoft.OpenApi/Services/CopyReferences.cs @@ -26,80 +26,54 @@ public override void Visit(IOpenApiReferenceable referenceable) case OpenApiSchema schema: AddSchemaToComponents(schema); break; - + case OpenApiParameterReference openApiParameterReference: + AddParameterToComponents(openApiParameterReference.Target, openApiParameterReference.Reference.Id); + break; case OpenApiParameter parameter: - EnsureComponentsExist(); - EnsureParametersExist(); - if (!Components.Parameters.ContainsKey(parameter.Reference.Id)) - { - Components.Parameters.Add(parameter.Reference.Id, parameter); - } + AddParameterToComponents(parameter); + break; + case OpenApiResponseReference openApiResponseReference: + AddResponseToComponents(openApiResponseReference.Target, openApiResponseReference.Reference.Id); break; - case OpenApiResponse response: - EnsureComponentsExist(); - EnsureResponsesExist(); - if (!Components.Responses.ContainsKey(response.Reference.Id)) - { - Components.Responses.Add(response.Reference.Id, response); - } + AddResponseToComponents(response); + break; + case OpenApiRequestBodyReference openApiRequestBodyReference: + AddRequestBodyToComponents(openApiRequestBodyReference.Target, openApiRequestBodyReference.Reference.Id); break; - case OpenApiRequestBody requestBody: - EnsureComponentsExist(); - EnsureResponsesExist(); - EnsureRequestBodiesExist(); - if (!Components.RequestBodies.ContainsKey(requestBody.Reference.Id)) - { - Components.RequestBodies.Add(requestBody.Reference.Id, requestBody); - } + AddRequestBodyToComponents(requestBody); + break; + case OpenApiExampleReference openApiExampleReference: + AddExampleToComponents(openApiExampleReference.Target, openApiExampleReference.Reference.Id); break; - case OpenApiExample example: - EnsureComponentsExist(); - EnsureExamplesExist(); - if (!Components.Examples.ContainsKey(example.Reference.Id)) - { - Components.Examples.Add(example.Reference.Id, example); - } + AddExampleToComponents(example); + break; + case OpenApiHeaderReference openApiHeaderReference: + AddHeaderToComponents(openApiHeaderReference.Target, openApiHeaderReference.Reference.Id); break; - case OpenApiHeader header: - EnsureComponentsExist(); - EnsureHeadersExist(); - if (!Components.Headers.ContainsKey(header.Reference.Id)) - { - Components.Headers.Add(header.Reference.Id, header); - } + AddHeaderToComponents(header); + break; + case OpenApiCallbackReference openApiCallbackReference: + AddCallbackToComponents(openApiCallbackReference.Target, openApiCallbackReference.Reference.Id); break; - case OpenApiCallback callback: - EnsureComponentsExist(); - EnsureCallbacksExist(); - if (!Components.Callbacks.ContainsKey(callback.Reference.Id)) - { - Components.Callbacks.Add(callback.Reference.Id, callback); - } + AddCallbackToComponents(callback); + break; + case OpenApiLinkReference openApiLinkReference: + AddLinkToComponents(openApiLinkReference.Target, openApiLinkReference.Reference.Id); break; - case OpenApiLink link: - EnsureComponentsExist(); - EnsureLinksExist(); - if (!Components.Links.ContainsKey(link.Reference.Id)) - { - Components.Links.Add(link.Reference.Id, link); - } + AddLinkToComponents(link); + break; + case OpenApiSecuritySchemeReference openApiSecuritySchemeReference: + AddSecuritySchemeToComponents(openApiSecuritySchemeReference.Target, openApiSecuritySchemeReference.Reference.Id); break; - case OpenApiSecurityScheme securityScheme: - EnsureComponentsExist(); - EnsureSecuritySchemesExist(); - if (!Components.SecuritySchemes.ContainsKey(securityScheme.Reference.Id)) - { - Components.SecuritySchemes.Add(securityScheme.Reference.Id, securityScheme); - } + AddSecuritySchemeToComponents(securityScheme); break; - default: break; } @@ -117,6 +91,89 @@ private void AddSchemaToComponents(OpenApiSchema schema, string referenceId = nu } } + private void AddParameterToComponents(OpenApiParameter parameter, string referenceId = null) + { + EnsureComponentsExist(); + EnsureParametersExist(); + if (!Components.Parameters.ContainsKey(referenceId ?? parameter.Reference.Id)) + { + Components.Parameters.Add(referenceId ?? parameter.Reference.Id, parameter); + } + } + + private void AddResponseToComponents(OpenApiResponse response, string referenceId = null) + { + EnsureComponentsExist(); + EnsureResponsesExist(); + if (!Components.Responses.ContainsKey(referenceId ?? response.Reference.Id)) + { + Components.Responses.Add(referenceId ?? response.Reference.Id, response); + } + } + private void AddRequestBodyToComponents(OpenApiRequestBody requestBody, string referenceId = null) + { + EnsureComponentsExist(); + EnsureRequestBodiesExist(); + if (!Components.RequestBodies.ContainsKey(referenceId ?? requestBody.Reference.Id)) + { + Components.RequestBodies.Add(referenceId ?? requestBody.Reference.Id, requestBody); + } + } + private void AddLinkToComponents(OpenApiLink link, string referenceId = null) + { + EnsureComponentsExist(); + EnsureLinksExist(); + if (!Components.Links.ContainsKey(referenceId ?? link.Reference.Id)) + { + Components.Links.Add(referenceId ?? link.Reference.Id, link); + } + } + private void AddCallbackToComponents(OpenApiCallback callback, string referenceId = null) + { + EnsureComponentsExist(); + EnsureCallbacksExist(); + if (!Components.Callbacks.ContainsKey(referenceId ?? callback.Reference.Id)) + { + Components.Callbacks.Add(referenceId ?? callback.Reference.Id, callback); + } + } + private void AddHeaderToComponents(OpenApiHeader header, string referenceId = null) + { + EnsureComponentsExist(); + EnsureHeadersExist(); + if (!Components.Headers.ContainsKey(referenceId ?? header.Reference.Id)) + { + Components.Headers.Add(referenceId ?? header.Reference.Id, header); + } + } + private void AddExampleToComponents(OpenApiExample example, string referenceId = null) + { + EnsureComponentsExist(); + EnsureExamplesExist(); + if (!Components.Examples.ContainsKey(referenceId ?? example.Reference.Id)) + { + Components.Examples.Add(referenceId ?? example.Reference.Id, example); + } + } + private void AddPathItemToComponents(OpenApiPathItem pathItem, string referenceId = null) + { + EnsureComponentsExist(); + EnsurePathItemsExist(); + if (!Components.PathItems.ContainsKey(referenceId ?? pathItem.Reference.Id)) + { + Components.PathItems.Add(referenceId ?? pathItem.Reference.Id, pathItem); + } + } + private void AddSecuritySchemeToComponents(OpenApiSecurityScheme securityScheme, string referenceId = null) + { + EnsureComponentsExist(); + EnsureSecuritySchemesExist(); + if (!Components.SecuritySchemes.ContainsKey(referenceId ?? securityScheme.Reference.Id)) + { + Components.SecuritySchemes.Add(referenceId ?? securityScheme.Reference.Id, securityScheme); + } + } + /// public override void Visit(OpenApiSchema schema) { @@ -181,4 +238,8 @@ private void EnsureSecuritySchemesExist() { _target.Components.SecuritySchemes ??= new Dictionary(); } + private void EnsurePathItemsExist() + { + _target.Components.PathItems ??= new Dictionary(); + } } From 70694469c1426489632f8d2794a68acf6a5b53af Mon Sep 17 00:00:00 2001 From: Maggiekimani1 Date: Mon, 20 Jan 2025 11:09:22 +0300 Subject: [PATCH 4/6] Implement an interface for IOpenApiReferenceable items with a target object --- .../IOpenApiReferenceableWithTarget.cs | 17 +++++++++++++++++ .../References/OpenApiCallbackReference.cs | 2 +- .../References/OpenApiExampleReference.cs | 2 +- .../Models/References/OpenApiHeaderReference.cs | 2 +- .../Models/References/OpenApiLinkReference.cs | 2 +- .../References/OpenApiParameterReference.cs | 2 +- .../References/OpenApiPathItemReference.cs | 2 +- .../References/OpenApiRequestBodyReference.cs | 2 +- .../References/OpenApiResponseReference.cs | 2 +- .../Models/References/OpenApiSchemaReference.cs | 2 +- .../OpenApiSecuritySchemeReference.cs | 2 +- .../Models/References/OpenApiTagReference.cs | 2 +- 12 files changed, 28 insertions(+), 11 deletions(-) create mode 100644 src/Microsoft.OpenApi/Interfaces/IOpenApiReferenceableWithTarget.cs diff --git a/src/Microsoft.OpenApi/Interfaces/IOpenApiReferenceableWithTarget.cs b/src/Microsoft.OpenApi/Interfaces/IOpenApiReferenceableWithTarget.cs new file mode 100644 index 000000000..fc4c1daed --- /dev/null +++ b/src/Microsoft.OpenApi/Interfaces/IOpenApiReferenceableWithTarget.cs @@ -0,0 +1,17 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT license. + +namespace Microsoft.OpenApi.Interfaces +{ + /// + /// A generic interface for OpenApiReferenceable objects that have a target. + /// + /// + public interface IOpenApiReferenceableWithTarget : IOpenApiReferenceable + { + /// + /// Gets the resolved target object. + /// + T Target { get; } + } +} diff --git a/src/Microsoft.OpenApi/Models/References/OpenApiCallbackReference.cs b/src/Microsoft.OpenApi/Models/References/OpenApiCallbackReference.cs index 2d610336f..81985cb12 100644 --- a/src/Microsoft.OpenApi/Models/References/OpenApiCallbackReference.cs +++ b/src/Microsoft.OpenApi/Models/References/OpenApiCallbackReference.cs @@ -12,7 +12,7 @@ namespace Microsoft.OpenApi.Models.References /// /// Callback Object Reference: A reference to a map of possible out-of band callbacks related to the parent operation. /// - public class OpenApiCallbackReference : OpenApiCallback, IOpenApiReferenceable + public class OpenApiCallbackReference : OpenApiCallback, IOpenApiReferenceableWithTarget { #nullable enable internal OpenApiCallback _target; diff --git a/src/Microsoft.OpenApi/Models/References/OpenApiExampleReference.cs b/src/Microsoft.OpenApi/Models/References/OpenApiExampleReference.cs index d471977f6..c36c43d9a 100644 --- a/src/Microsoft.OpenApi/Models/References/OpenApiExampleReference.cs +++ b/src/Microsoft.OpenApi/Models/References/OpenApiExampleReference.cs @@ -12,7 +12,7 @@ namespace Microsoft.OpenApi.Models.References /// /// Example Object Reference. /// - public class OpenApiExampleReference : OpenApiExample, IOpenApiReferenceable + public class OpenApiExampleReference : OpenApiExample, IOpenApiReferenceableWithTarget { internal OpenApiExample _target; private readonly OpenApiReference _reference; diff --git a/src/Microsoft.OpenApi/Models/References/OpenApiHeaderReference.cs b/src/Microsoft.OpenApi/Models/References/OpenApiHeaderReference.cs index a3961be76..e8275c23c 100644 --- a/src/Microsoft.OpenApi/Models/References/OpenApiHeaderReference.cs +++ b/src/Microsoft.OpenApi/Models/References/OpenApiHeaderReference.cs @@ -12,7 +12,7 @@ namespace Microsoft.OpenApi.Models.References /// /// Header Object Reference. /// - public class OpenApiHeaderReference : OpenApiHeader, IOpenApiReferenceable + public class OpenApiHeaderReference : OpenApiHeader, IOpenApiReferenceableWithTarget { internal OpenApiHeader _target; private readonly OpenApiReference _reference; diff --git a/src/Microsoft.OpenApi/Models/References/OpenApiLinkReference.cs b/src/Microsoft.OpenApi/Models/References/OpenApiLinkReference.cs index 55574666c..05817ddc9 100644 --- a/src/Microsoft.OpenApi/Models/References/OpenApiLinkReference.cs +++ b/src/Microsoft.OpenApi/Models/References/OpenApiLinkReference.cs @@ -11,7 +11,7 @@ namespace Microsoft.OpenApi.Models.References /// /// Link Object Reference. /// - public class OpenApiLinkReference : OpenApiLink, IOpenApiReferenceable + public class OpenApiLinkReference : OpenApiLink, IOpenApiReferenceableWithTarget { internal OpenApiLink _target; private readonly OpenApiReference _reference; diff --git a/src/Microsoft.OpenApi/Models/References/OpenApiParameterReference.cs b/src/Microsoft.OpenApi/Models/References/OpenApiParameterReference.cs index c0549798f..9df1e7be2 100644 --- a/src/Microsoft.OpenApi/Models/References/OpenApiParameterReference.cs +++ b/src/Microsoft.OpenApi/Models/References/OpenApiParameterReference.cs @@ -12,7 +12,7 @@ namespace Microsoft.OpenApi.Models.References /// /// Parameter Object Reference. /// - public class OpenApiParameterReference : OpenApiParameter, IOpenApiReferenceable + public class OpenApiParameterReference : OpenApiParameter, IOpenApiReferenceableWithTarget { internal OpenApiParameter _target; private readonly OpenApiReference _reference; diff --git a/src/Microsoft.OpenApi/Models/References/OpenApiPathItemReference.cs b/src/Microsoft.OpenApi/Models/References/OpenApiPathItemReference.cs index d22c8340f..fad8922ae 100644 --- a/src/Microsoft.OpenApi/Models/References/OpenApiPathItemReference.cs +++ b/src/Microsoft.OpenApi/Models/References/OpenApiPathItemReference.cs @@ -11,7 +11,7 @@ namespace Microsoft.OpenApi.Models.References /// /// Path Item Object Reference: to describe the operations available on a single path. /// - public class OpenApiPathItemReference : OpenApiPathItem, IOpenApiReferenceable + public class OpenApiPathItemReference : OpenApiPathItem, IOpenApiReferenceableWithTarget { internal OpenApiPathItem _target; private readonly OpenApiReference _reference; diff --git a/src/Microsoft.OpenApi/Models/References/OpenApiRequestBodyReference.cs b/src/Microsoft.OpenApi/Models/References/OpenApiRequestBodyReference.cs index 89375d665..598d70310 100644 --- a/src/Microsoft.OpenApi/Models/References/OpenApiRequestBodyReference.cs +++ b/src/Microsoft.OpenApi/Models/References/OpenApiRequestBodyReference.cs @@ -11,7 +11,7 @@ namespace Microsoft.OpenApi.Models.References /// /// Request Body Object Reference. /// - public class OpenApiRequestBodyReference : OpenApiRequestBody, IOpenApiReferenceable + public class OpenApiRequestBodyReference : OpenApiRequestBody, IOpenApiReferenceableWithTarget { internal OpenApiRequestBody _target; private readonly OpenApiReference _reference; diff --git a/src/Microsoft.OpenApi/Models/References/OpenApiResponseReference.cs b/src/Microsoft.OpenApi/Models/References/OpenApiResponseReference.cs index 437d34c19..0e4ac30ac 100644 --- a/src/Microsoft.OpenApi/Models/References/OpenApiResponseReference.cs +++ b/src/Microsoft.OpenApi/Models/References/OpenApiResponseReference.cs @@ -11,7 +11,7 @@ namespace Microsoft.OpenApi.Models.References /// /// Response Object Reference. /// - public class OpenApiResponseReference : OpenApiResponse, IOpenApiReferenceable + public class OpenApiResponseReference : OpenApiResponse, IOpenApiReferenceableWithTarget { internal OpenApiResponse _target; private readonly OpenApiReference _reference; diff --git a/src/Microsoft.OpenApi/Models/References/OpenApiSchemaReference.cs b/src/Microsoft.OpenApi/Models/References/OpenApiSchemaReference.cs index b5b7fb4a1..da2f9b745 100644 --- a/src/Microsoft.OpenApi/Models/References/OpenApiSchemaReference.cs +++ b/src/Microsoft.OpenApi/Models/References/OpenApiSchemaReference.cs @@ -12,7 +12,7 @@ namespace Microsoft.OpenApi.Models.References /// /// Schema reference object /// - public class OpenApiSchemaReference : OpenApiSchema, IOpenApiReferenceable + public class OpenApiSchemaReference : OpenApiSchema, IOpenApiReferenceableWithTarget { #nullable enable private OpenApiSchema? _target; diff --git a/src/Microsoft.OpenApi/Models/References/OpenApiSecuritySchemeReference.cs b/src/Microsoft.OpenApi/Models/References/OpenApiSecuritySchemeReference.cs index 7b5064309..dcd5009b1 100644 --- a/src/Microsoft.OpenApi/Models/References/OpenApiSecuritySchemeReference.cs +++ b/src/Microsoft.OpenApi/Models/References/OpenApiSecuritySchemeReference.cs @@ -11,7 +11,7 @@ namespace Microsoft.OpenApi.Models.References /// /// Security Scheme Object Reference. /// - public class OpenApiSecuritySchemeReference : OpenApiSecurityScheme, IOpenApiReferenceable + public class OpenApiSecuritySchemeReference : OpenApiSecurityScheme, IOpenApiReferenceableWithTarget { internal OpenApiSecurityScheme _target; private readonly OpenApiReference _reference; diff --git a/src/Microsoft.OpenApi/Models/References/OpenApiTagReference.cs b/src/Microsoft.OpenApi/Models/References/OpenApiTagReference.cs index ddf7ad4e2..ae15b4085 100644 --- a/src/Microsoft.OpenApi/Models/References/OpenApiTagReference.cs +++ b/src/Microsoft.OpenApi/Models/References/OpenApiTagReference.cs @@ -12,7 +12,7 @@ namespace Microsoft.OpenApi.Models.References /// /// Tag Object Reference /// - public class OpenApiTagReference : OpenApiTag, IOpenApiReferenceable + public class OpenApiTagReference : OpenApiTag, IOpenApiReferenceableWithTarget { internal OpenApiTag _target; From 32f75a1fa3e33521e1b1fd80fcfe50adcfb363fa Mon Sep 17 00:00:00 2001 From: Maggiekimani1 Date: Mon, 20 Jan 2025 11:09:39 +0300 Subject: [PATCH 5/6] Add reusable pathItems to components --- src/Microsoft.OpenApi/Services/CopyReferences.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Microsoft.OpenApi/Services/CopyReferences.cs b/src/Microsoft.OpenApi/Services/CopyReferences.cs index c122d5132..22f1c5ad3 100644 --- a/src/Microsoft.OpenApi/Services/CopyReferences.cs +++ b/src/Microsoft.OpenApi/Services/CopyReferences.cs @@ -74,6 +74,12 @@ public override void Visit(IOpenApiReferenceable referenceable) case OpenApiSecurityScheme securityScheme: AddSecuritySchemeToComponents(securityScheme); break; + case OpenApiPathItemReference openApiPathItemReference: + AddPathItemToComponents(openApiPathItemReference.Target, openApiPathItemReference.Reference.Id); + break; + case OpenApiPathItem pathItem: + AddPathItemToComponents(pathItem); + break; default: break; } From 733185f4ea2b659cd695b797b7b3bbd4034f30be Mon Sep 17 00:00:00 2001 From: Maggiekimani1 Date: Mon, 20 Jan 2025 11:15:23 +0300 Subject: [PATCH 6/6] Add test and update API surface --- .../References/OpenApiHeaderReferenceTests.cs | 33 +++++++++++++++-- .../PublicApi/PublicApi.approved.txt | 35 +++++++++++++------ 2 files changed, 55 insertions(+), 13 deletions(-) diff --git a/test/Microsoft.OpenApi.Tests/Models/References/OpenApiHeaderReferenceTests.cs b/test/Microsoft.OpenApi.Tests/Models/References/OpenApiHeaderReferenceTests.cs index 70eca5e9e..d7fef6396 100644 --- a/test/Microsoft.OpenApi.Tests/Models/References/OpenApiHeaderReferenceTests.cs +++ b/test/Microsoft.OpenApi.Tests/Models/References/OpenApiHeaderReferenceTests.cs @@ -19,7 +19,7 @@ namespace Microsoft.OpenApi.Tests.Models.References public class OpenApiHeaderReferenceTests { // OpenApi doc with external $ref - private const string OpenApi= @" + private const string OpenApi = @" openapi: 3.0.0 info: title: Sample API @@ -149,7 +149,7 @@ public async Task SerializeHeaderReferenceAsV2JsonWorksAsync(bool produceTerseOu { // Arrange var outputStringWriter = new StringWriter(CultureInfo.InvariantCulture); - var writer = new OpenApiJsonWriter(outputStringWriter, new OpenApiJsonWriterSettings { Terse = produceTerseOutput, InlineLocalReferences = true}); + var writer = new OpenApiJsonWriter(outputStringWriter, new OpenApiJsonWriterSettings { Terse = produceTerseOutput, InlineLocalReferences = true }); // Act _localHeaderReference.SerializeAsV2(writer); @@ -158,5 +158,34 @@ public async Task SerializeHeaderReferenceAsV2JsonWorksAsync(bool produceTerseOu // Assert await Verifier.Verify(outputStringWriter).UseParameters(produceTerseOutput); } + + [Fact] + public void OpenApiHeaderTargetShouldResolveReference() + { + var doc = new OpenApiDocument + { + Components = new OpenApiComponents + { + Headers = new System.Collections.Generic.Dictionary + { + { "header1", new OpenApiHeader + { + Description = "test header", + Schema = new OpenApiSchema + { + Type = JsonSchemaType.String + } + } + } + } + } + }; + + doc.Workspace.RegisterComponents(doc); + + var headerReference = new OpenApiHeaderReference("header1", doc); + Assert.Equal("test header", headerReference.Description); + Assert.Equal(JsonSchemaType.String, headerReference.Schema.Type); + } } } diff --git a/test/Microsoft.OpenApi.Tests/PublicApi/PublicApi.approved.txt b/test/Microsoft.OpenApi.Tests/PublicApi/PublicApi.approved.txt index ecdfd05c2..101624970 100644 --- a/test/Microsoft.OpenApi.Tests/PublicApi/PublicApi.approved.txt +++ b/test/Microsoft.OpenApi.Tests/PublicApi/PublicApi.approved.txt @@ -222,6 +222,10 @@ namespace Microsoft.OpenApi.Interfaces Microsoft.OpenApi.Models.OpenApiReference Reference { get; set; } bool UnresolvedReference { get; set; } } + public interface IOpenApiReferenceableWithTarget : Microsoft.OpenApi.Interfaces.IOpenApiElement, Microsoft.OpenApi.Interfaces.IOpenApiReferenceable, Microsoft.OpenApi.Interfaces.IOpenApiSerializable + { + T Target { get; } + } public interface IOpenApiSerializable : Microsoft.OpenApi.Interfaces.IOpenApiElement { void SerializeAsV2(Microsoft.OpenApi.Writers.IOpenApiWriter writer); @@ -1095,17 +1099,19 @@ namespace Microsoft.OpenApi.Models } namespace Microsoft.OpenApi.Models.References { - public class OpenApiCallbackReference : Microsoft.OpenApi.Models.OpenApiCallback + public class OpenApiCallbackReference : Microsoft.OpenApi.Models.OpenApiCallback, Microsoft.OpenApi.Interfaces.IOpenApiElement, Microsoft.OpenApi.Interfaces.IOpenApiReferenceable, Microsoft.OpenApi.Interfaces.IOpenApiReferenceableWithTarget, Microsoft.OpenApi.Interfaces.IOpenApiSerializable { public OpenApiCallbackReference(string referenceId, Microsoft.OpenApi.Models.OpenApiDocument hostDocument, string externalResource = null) { } + public Microsoft.OpenApi.Models.OpenApiCallback Target { get; } public override System.Collections.Generic.IDictionary Extensions { get; set; } public override System.Collections.Generic.Dictionary PathItems { get; set; } public override void SerializeAsV3(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } public override void SerializeAsV31(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } } - public class OpenApiExampleReference : Microsoft.OpenApi.Models.OpenApiExample + public class OpenApiExampleReference : Microsoft.OpenApi.Models.OpenApiExample, Microsoft.OpenApi.Interfaces.IOpenApiElement, Microsoft.OpenApi.Interfaces.IOpenApiReferenceable, Microsoft.OpenApi.Interfaces.IOpenApiReferenceableWithTarget, Microsoft.OpenApi.Interfaces.IOpenApiSerializable { public OpenApiExampleReference(string referenceId, Microsoft.OpenApi.Models.OpenApiDocument hostDocument, string externalResource = null) { } + public Microsoft.OpenApi.Models.OpenApiExample Target { get; } public override string Description { get; set; } public override System.Collections.Generic.IDictionary Extensions { get; set; } public override string ExternalValue { get; set; } @@ -1114,9 +1120,10 @@ namespace Microsoft.OpenApi.Models.References public override void SerializeAsV3(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } public override void SerializeAsV31(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } } - public class OpenApiHeaderReference : Microsoft.OpenApi.Models.OpenApiHeader + public class OpenApiHeaderReference : Microsoft.OpenApi.Models.OpenApiHeader, Microsoft.OpenApi.Interfaces.IOpenApiElement, Microsoft.OpenApi.Interfaces.IOpenApiReferenceable, Microsoft.OpenApi.Interfaces.IOpenApiReferenceableWithTarget, Microsoft.OpenApi.Interfaces.IOpenApiSerializable { public OpenApiHeaderReference(string referenceId, Microsoft.OpenApi.Models.OpenApiDocument hostDocument, string externalResource = null) { } + public Microsoft.OpenApi.Models.OpenApiHeader Target { get; } public override bool AllowEmptyValue { get; set; } public override bool AllowReserved { get; set; } public override System.Collections.Generic.IDictionary Content { get; set; } @@ -1133,9 +1140,10 @@ namespace Microsoft.OpenApi.Models.References public override void SerializeAsV3(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } public override void SerializeAsV31(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } } - public class OpenApiLinkReference : Microsoft.OpenApi.Models.OpenApiLink + public class OpenApiLinkReference : Microsoft.OpenApi.Models.OpenApiLink, Microsoft.OpenApi.Interfaces.IOpenApiElement, Microsoft.OpenApi.Interfaces.IOpenApiReferenceable, Microsoft.OpenApi.Interfaces.IOpenApiReferenceableWithTarget, Microsoft.OpenApi.Interfaces.IOpenApiSerializable { public OpenApiLinkReference(string referenceId, Microsoft.OpenApi.Models.OpenApiDocument hostDocument, string externalResource = null) { } + public Microsoft.OpenApi.Models.OpenApiLink Target { get; } public override string Description { get; set; } public override System.Collections.Generic.IDictionary Extensions { get; set; } public override string OperationId { get; set; } @@ -1146,9 +1154,10 @@ namespace Microsoft.OpenApi.Models.References public override void SerializeAsV3(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } public override void SerializeAsV31(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } } - public class OpenApiParameterReference : Microsoft.OpenApi.Models.OpenApiParameter + public class OpenApiParameterReference : Microsoft.OpenApi.Models.OpenApiParameter, Microsoft.OpenApi.Interfaces.IOpenApiElement, Microsoft.OpenApi.Interfaces.IOpenApiReferenceable, Microsoft.OpenApi.Interfaces.IOpenApiReferenceableWithTarget, Microsoft.OpenApi.Interfaces.IOpenApiSerializable { public OpenApiParameterReference(string referenceId, Microsoft.OpenApi.Models.OpenApiDocument hostDocument, string externalResource = null) { } + public Microsoft.OpenApi.Models.OpenApiParameter Target { get; } public override bool AllowEmptyValue { get; set; } public override bool AllowReserved { get; set; } public override System.Collections.Generic.IDictionary Content { get; set; } @@ -1167,9 +1176,10 @@ namespace Microsoft.OpenApi.Models.References public override void SerializeAsV3(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } public override void SerializeAsV31(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } } - public class OpenApiPathItemReference : Microsoft.OpenApi.Models.OpenApiPathItem + public class OpenApiPathItemReference : Microsoft.OpenApi.Models.OpenApiPathItem, Microsoft.OpenApi.Interfaces.IOpenApiElement, Microsoft.OpenApi.Interfaces.IOpenApiReferenceable, Microsoft.OpenApi.Interfaces.IOpenApiReferenceableWithTarget, Microsoft.OpenApi.Interfaces.IOpenApiSerializable { public OpenApiPathItemReference(string referenceId, Microsoft.OpenApi.Models.OpenApiDocument hostDocument, string externalResource = null) { } + public Microsoft.OpenApi.Models.OpenApiPathItem Target { get; } public override string Description { get; set; } public override System.Collections.Generic.IDictionary Extensions { get; set; } public override System.Collections.Generic.IDictionary Operations { get; set; } @@ -1178,9 +1188,10 @@ namespace Microsoft.OpenApi.Models.References public override string Summary { get; set; } public override void SerializeAsV31(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } } - public class OpenApiRequestBodyReference : Microsoft.OpenApi.Models.OpenApiRequestBody + public class OpenApiRequestBodyReference : Microsoft.OpenApi.Models.OpenApiRequestBody, Microsoft.OpenApi.Interfaces.IOpenApiElement, Microsoft.OpenApi.Interfaces.IOpenApiReferenceable, Microsoft.OpenApi.Interfaces.IOpenApiReferenceableWithTarget, Microsoft.OpenApi.Interfaces.IOpenApiSerializable { public OpenApiRequestBodyReference(string referenceId, Microsoft.OpenApi.Models.OpenApiDocument hostDocument, string externalResource = null) { } + public Microsoft.OpenApi.Models.OpenApiRequestBody Target { get; } public override System.Collections.Generic.IDictionary Content { get; set; } public override string Description { get; set; } public override System.Collections.Generic.IDictionary Extensions { get; set; } @@ -1188,9 +1199,10 @@ namespace Microsoft.OpenApi.Models.References public override void SerializeAsV3(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } public override void SerializeAsV31(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } } - public class OpenApiResponseReference : Microsoft.OpenApi.Models.OpenApiResponse + public class OpenApiResponseReference : Microsoft.OpenApi.Models.OpenApiResponse, Microsoft.OpenApi.Interfaces.IOpenApiElement, Microsoft.OpenApi.Interfaces.IOpenApiReferenceable, Microsoft.OpenApi.Interfaces.IOpenApiReferenceableWithTarget, Microsoft.OpenApi.Interfaces.IOpenApiSerializable { public OpenApiResponseReference(string referenceId, Microsoft.OpenApi.Models.OpenApiDocument hostDocument, string externalResource = null) { } + public Microsoft.OpenApi.Models.OpenApiResponse Target { get; } public override System.Collections.Generic.IDictionary Content { get; set; } public override string Description { get; set; } public override System.Collections.Generic.IDictionary Extensions { get; set; } @@ -1200,7 +1212,7 @@ namespace Microsoft.OpenApi.Models.References public override void SerializeAsV3(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } public override void SerializeAsV31(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } } - public class OpenApiSchemaReference : Microsoft.OpenApi.Models.OpenApiSchema + public class OpenApiSchemaReference : Microsoft.OpenApi.Models.OpenApiSchema, Microsoft.OpenApi.Interfaces.IOpenApiElement, Microsoft.OpenApi.Interfaces.IOpenApiReferenceable, Microsoft.OpenApi.Interfaces.IOpenApiReferenceableWithTarget, Microsoft.OpenApi.Interfaces.IOpenApiSerializable { public OpenApiSchemaReference(string referenceId, Microsoft.OpenApi.Models.OpenApiDocument hostDocument, string externalResource = null) { } public Microsoft.OpenApi.Models.OpenApiSchema? Target { get; } @@ -1259,9 +1271,10 @@ namespace Microsoft.OpenApi.Models.References public override void SerializeAsV3(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } public override void SerializeAsV31(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } } - public class OpenApiSecuritySchemeReference : Microsoft.OpenApi.Models.OpenApiSecurityScheme + public class OpenApiSecuritySchemeReference : Microsoft.OpenApi.Models.OpenApiSecurityScheme, Microsoft.OpenApi.Interfaces.IOpenApiElement, Microsoft.OpenApi.Interfaces.IOpenApiReferenceable, Microsoft.OpenApi.Interfaces.IOpenApiReferenceableWithTarget, Microsoft.OpenApi.Interfaces.IOpenApiSerializable { public OpenApiSecuritySchemeReference(string referenceId, Microsoft.OpenApi.Models.OpenApiDocument hostDocument, string externalResource = null) { } + public Microsoft.OpenApi.Models.OpenApiSecurityScheme Target { get; } public override string BearerFormat { get; set; } public override string Description { get; set; } public override System.Collections.Generic.IDictionary Extensions { get; set; } @@ -1275,7 +1288,7 @@ namespace Microsoft.OpenApi.Models.References public override void SerializeAsV3(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } public override void SerializeAsV31(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { } } - public class OpenApiTagReference : Microsoft.OpenApi.Models.OpenApiTag, Microsoft.OpenApi.Interfaces.IOpenApiElement, Microsoft.OpenApi.Interfaces.IOpenApiReferenceable, Microsoft.OpenApi.Interfaces.IOpenApiSerializable + public class OpenApiTagReference : Microsoft.OpenApi.Models.OpenApiTag, Microsoft.OpenApi.Interfaces.IOpenApiElement, Microsoft.OpenApi.Interfaces.IOpenApiReferenceable, Microsoft.OpenApi.Interfaces.IOpenApiReferenceableWithTarget, Microsoft.OpenApi.Interfaces.IOpenApiSerializable { public OpenApiTagReference(Microsoft.OpenApi.Models.References.OpenApiTagReference source) { } public OpenApiTagReference(string referenceId, Microsoft.OpenApi.Models.OpenApiDocument hostDocument) { }