Skip to content

Commit d92509f

Browse files
committed
More cleanup
1 parent 1410672 commit d92509f

File tree

7 files changed

+21
-8
lines changed

7 files changed

+21
-8
lines changed

src/Microsoft.OpenApi.Readers/V2/OpenApiDocumentDeserializer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ private static void RegisterComponentsSchemasInGlobalRegistry(IDictionary<string
321321

322322
foreach (var schema in schemas)
323323
{
324-
var refUri = new Uri($"http://everything.json/definitions/{schema.Key}");
324+
var refUri = new Uri(OpenApiConstants.v2ReferenceUri + schema.Key);
325325
SchemaRegistry.Global.Register(refUri, schema.Value);
326326
}
327327
}

src/Microsoft.OpenApi.Readers/V31/OpenApiComponentsDeserializer.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
using System.Text.Json.Nodes;
2-
using System.Text.Json;
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT license.
3+
34
using System;
45
using Json.Schema;
56
using Microsoft.OpenApi.Extensions;
@@ -43,7 +44,7 @@ public static OpenApiComponents LoadComponents(ParseNode node)
4344

4445
foreach (var schema in components.Schemas)
4546
{
46-
var refUri = new Uri($"http://everything.json/components/schemas/{schema.Key}");
47+
var refUri = new Uri(OpenApiConstants.v3ReferenceUri + schema.Key);
4748
SchemaRegistry.Global.Register(refUri, schema.Value);
4849
}
4950

src/Microsoft.OpenApi/Models/OpenApiConstants.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -595,6 +595,16 @@ public static class OpenApiConstants
595595
/// </summary>
596596
public static readonly Uri defaultUrl = new Uri("http://localhost/");
597597

598+
/// <summary>
599+
/// Field: V3 JsonSchema Reference Uri
600+
/// </summary>
601+
public const string v3ReferenceUri = "https://everything.json/components/schemas/";
602+
603+
/// <summary>
604+
/// Field: V2 JsonSchema Reference Uri
605+
/// </summary>
606+
public const string v2ReferenceUri = "https://everything.json/definitions/";
607+
598608
#region V2.0
599609

600610
/// <summary>

src/Microsoft.OpenApi/Services/OpenApiReferenceResolver.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ private Dictionary<string, JsonSchema> ResolveJsonSchemas(IDictionary<string, Js
245245
/// <returns></returns>
246246
public JsonSchema ResolveJsonSchemaReference(Uri reference, string description = null, string summary = null)
247247
{
248-
var refUri = $"http://everything.json{reference.OriginalString.Split('#').LastOrDefault()}";
248+
var refUri = $"https://everything.json{reference.OriginalString.Split('#').LastOrDefault()}";
249249
var resolvedSchema = (JsonSchema)SchemaRegistry.Global.Get(new Uri(refUri));
250250

251251
if (resolvedSchema != null)

src/Microsoft.OpenApi/Services/OpenApiWorkspace.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ public JsonSchema ResolveJsonSchemaReference(Uri reference)
155155
{
156156
foreach (var jsonSchema in doc.Components.Schemas)
157157
{
158-
var refUri = new Uri($"http://everything.json/components/schemas/{jsonSchema.Key}");
158+
var refUri = new Uri(OpenApiConstants.v3ReferenceUri + jsonSchema.Key);
159159
SchemaRegistry.Global.Register(refUri, jsonSchema.Value);
160160
}
161161

test/Microsoft.OpenApi.Tests/PublicApi/PublicApi.approved.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,8 @@ namespace Microsoft.OpenApi.Models
460460
public const string Wrapped = "wrapped";
461461
public const string WriteOnly = "writeOnly";
462462
public const string Xml = "xml";
463+
public const string v2ReferenceUri = "https://everything.json/definitions/";
464+
public const string v3ReferenceUri = "https://everything.json/components/schemas/";
463465
public static readonly System.Uri defaultUrl;
464466
public static readonly System.Version version2_0;
465467
public static readonly System.Version version3_0_0;

test/Microsoft.OpenApi.Tests/Workspaces/OpenApiWorkspaceTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public void OpenApiWorkspacesCanResolveExternalReferences()
8080

8181
workspace.AddDocument(location, doc);
8282

83-
var schema = workspace.ResolveJsonSchemaReference(new Uri("http://everything.json/common#/components/schemas/test"));
83+
var schema = workspace.ResolveJsonSchemaReference(new Uri("https://everything.json/common#/components/schemas/test"));
8484

8585
Assert.NotNull(schema);
8686
Assert.Equal("The referenced one", schema.GetDescription());
@@ -147,7 +147,7 @@ public void OpenApiWorkspacesCanResolveReferencesToDocumentFragments()
147147
workspace.AddSchemaFragment("fragment", schemaFragment);
148148

149149
// Act
150-
var schema = workspace.ResolveJsonSchemaReference(new Uri("http://everything.json/common#/components/schemas/test"));
150+
var schema = workspace.ResolveJsonSchemaReference(new Uri("https://everything.json/common#/components/schemas/test"));
151151

152152
// Assert
153153
Assert.NotNull(schema);

0 commit comments

Comments
 (0)