Skip to content

Commit 14750dc

Browse files
committed
fix: allow registration of component references
1 parent 019eb99 commit 14750dc

File tree

2 files changed

+21
-20
lines changed

2 files changed

+21
-20
lines changed

src/Microsoft.OpenApi/Models/OpenApiDocument.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -587,43 +587,43 @@ public bool AddComponent<T>(string id, T componentToRegister)
587587
Components ??= new();
588588
switch (componentToRegister)
589589
{
590-
case OpenApiSchema openApiSchema:
590+
case IOpenApiSchema openApiSchema:
591591
Components.Schemas ??= new Dictionary<string, IOpenApiSchema>();
592592
Components.Schemas.Add(id, openApiSchema);
593593
break;
594-
case OpenApiParameter openApiParameter:
594+
case IOpenApiParameter openApiParameter:
595595
Components.Parameters ??= new Dictionary<string, IOpenApiParameter>();
596596
Components.Parameters.Add(id, openApiParameter);
597597
break;
598-
case OpenApiResponse openApiResponse:
598+
case IOpenApiResponse openApiResponse:
599599
Components.Responses ??= new Dictionary<string, IOpenApiResponse>();
600600
Components.Responses.Add(id, openApiResponse);
601601
break;
602-
case OpenApiRequestBody openApiRequestBody:
602+
case IOpenApiRequestBody openApiRequestBody:
603603
Components.RequestBodies ??= new Dictionary<string, IOpenApiRequestBody>();
604604
Components.RequestBodies.Add(id, openApiRequestBody);
605605
break;
606-
case OpenApiLink openApiLink:
606+
case IOpenApiLink openApiLink:
607607
Components.Links ??= new Dictionary<string, IOpenApiLink>();
608608
Components.Links.Add(id, openApiLink);
609609
break;
610-
case OpenApiCallback openApiCallback:
610+
case IOpenApiCallback openApiCallback:
611611
Components.Callbacks ??= new Dictionary<string, IOpenApiCallback>();
612612
Components.Callbacks.Add(id, openApiCallback);
613613
break;
614-
case OpenApiPathItem openApiPathItem:
614+
case IOpenApiPathItem openApiPathItem:
615615
Components.PathItems ??= new Dictionary<string, IOpenApiPathItem>();
616616
Components.PathItems.Add(id, openApiPathItem);
617617
break;
618-
case OpenApiExample openApiExample:
618+
case IOpenApiExample openApiExample:
619619
Components.Examples ??= new Dictionary<string, IOpenApiExample>();
620620
Components.Examples.Add(id, openApiExample);
621621
break;
622-
case OpenApiHeader openApiHeader:
622+
case IOpenApiHeader openApiHeader:
623623
Components.Headers ??= new Dictionary<string, IOpenApiHeader>();
624624
Components.Headers.Add(id, openApiHeader);
625625
break;
626-
case OpenApiSecurityScheme openApiSecurityScheme:
626+
case IOpenApiSecurityScheme openApiSecurityScheme:
627627
Components.SecuritySchemes ??= new Dictionary<string, IOpenApiSecurityScheme>();
628628
Components.SecuritySchemes.Add(id, openApiSecurityScheme);
629629
break;

src/Microsoft.OpenApi/Services/OpenApiWorkspace.cs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using Microsoft.OpenApi.Extensions;
88
using Microsoft.OpenApi.Interfaces;
99
using Microsoft.OpenApi.Models;
10+
using Microsoft.OpenApi.Models.Interfaces;
1011

1112
namespace Microsoft.OpenApi.Services
1213
{
@@ -165,16 +166,16 @@ public bool RegisterComponentForDocument<T>(OpenApiDocument openApiDocument, T c
165166

166167
var location = componentToRegister switch
167168
{
168-
OpenApiSchema => baseUri + ReferenceType.Schema.GetDisplayName() + ComponentSegmentSeparator + id,
169-
OpenApiParameter => baseUri + ReferenceType.Parameter.GetDisplayName() + ComponentSegmentSeparator + id,
170-
OpenApiResponse => baseUri + ReferenceType.Response.GetDisplayName() + ComponentSegmentSeparator + id,
171-
OpenApiRequestBody => baseUri + ReferenceType.RequestBody.GetDisplayName() + ComponentSegmentSeparator + id,
172-
OpenApiLink => baseUri + ReferenceType.Link.GetDisplayName() + ComponentSegmentSeparator + id,
173-
OpenApiCallback => baseUri + ReferenceType.Callback.GetDisplayName() + ComponentSegmentSeparator + id,
174-
OpenApiPathItem => baseUri + ReferenceType.PathItem.GetDisplayName() + ComponentSegmentSeparator + id,
175-
OpenApiExample => baseUri + ReferenceType.Example.GetDisplayName() + ComponentSegmentSeparator + id,
176-
OpenApiHeader => baseUri + ReferenceType.Header.GetDisplayName() + ComponentSegmentSeparator + id,
177-
OpenApiSecurityScheme => baseUri + ReferenceType.SecurityScheme.GetDisplayName() + ComponentSegmentSeparator + id,
169+
IOpenApiSchema => baseUri + ReferenceType.Schema.GetDisplayName() + ComponentSegmentSeparator + id,
170+
IOpenApiParameter => baseUri + ReferenceType.Parameter.GetDisplayName() + ComponentSegmentSeparator + id,
171+
IOpenApiResponse => baseUri + ReferenceType.Response.GetDisplayName() + ComponentSegmentSeparator + id,
172+
IOpenApiRequestBody => baseUri + ReferenceType.RequestBody.GetDisplayName() + ComponentSegmentSeparator + id,
173+
IOpenApiLink => baseUri + ReferenceType.Link.GetDisplayName() + ComponentSegmentSeparator + id,
174+
IOpenApiCallback => baseUri + ReferenceType.Callback.GetDisplayName() + ComponentSegmentSeparator + id,
175+
IOpenApiPathItem => baseUri + ReferenceType.PathItem.GetDisplayName() + ComponentSegmentSeparator + id,
176+
IOpenApiExample => baseUri + ReferenceType.Example.GetDisplayName() + ComponentSegmentSeparator + id,
177+
IOpenApiHeader => baseUri + ReferenceType.Header.GetDisplayName() + ComponentSegmentSeparator + id,
178+
IOpenApiSecurityScheme => baseUri + ReferenceType.SecurityScheme.GetDisplayName() + ComponentSegmentSeparator + id,
178179
_ => throw new ArgumentException($"Invalid component type {componentToRegister.GetType().Name}"),
179180
};
180181

0 commit comments

Comments
 (0)