Skip to content

Commit 452a6b9

Browse files
committed
fix: openapischema schema property is now a Uri
Signed-off-by: Vincent Biret <[email protected]>
1 parent 45977b5 commit 452a6b9

File tree

6 files changed

+12
-11
lines changed

6 files changed

+12
-11
lines changed

src/Microsoft.OpenApi/Models/Interfaces/IOpenApiSchema.cs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Collections.Generic;
1+
using System;
2+
using System.Collections.Generic;
23
using System.Text.Json.Nodes;
34
using Microsoft.OpenApi.Interfaces;
45

@@ -19,7 +20,7 @@ public interface IOpenApiSchema : IOpenApiDescribedElement, IOpenApiSerializable
1920
/// <summary>
2021
/// $schema, a JSON Schema dialect identifier. Value must be a URI
2122
/// </summary>
22-
public string Schema { get; }
23+
public Uri Schema { get; }
2324

2425
/// <summary>
2526
/// $id - Identifies a schema resource with its canonical URI.

src/Microsoft.OpenApi/Models/OpenApiSchema.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public class OpenApiSchema : IOpenApiReferenceable, IOpenApiExtensible, IOpenApi
2424
public string Title { get; set; }
2525

2626
/// <inheritdoc />
27-
public string Schema { get; set; }
27+
public Uri Schema { get; set; }
2828

2929
/// <inheritdoc />
3030
public string Id { get; set; }
@@ -400,7 +400,7 @@ public void SerializeAsV2(IOpenApiWriter writer)
400400
internal void WriteJsonSchemaKeywords(IOpenApiWriter writer)
401401
{
402402
writer.WriteProperty(OpenApiConstants.Id, Id);
403-
writer.WriteProperty(OpenApiConstants.DollarSchema, Schema);
403+
writer.WriteProperty(OpenApiConstants.DollarSchema, Schema?.ToString());
404404
writer.WriteProperty(OpenApiConstants.Comment, Comment);
405405
writer.WriteProperty(OpenApiConstants.Const, Const);
406406
writer.WriteOptionalMap(OpenApiConstants.Vocabulary, Vocabulary, (w, s) => w.WriteValue(s));

src/Microsoft.OpenApi/Models/References/OpenApiSchemaReference.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public string Description
5252
/// <inheritdoc/>
5353
public string Title { get => Target?.Title; }
5454
/// <inheritdoc/>
55-
public string Schema { get => Target?.Schema; }
55+
public Uri Schema { get => Target?.Schema; }
5656
/// <inheritdoc/>
5757
public string Id { get => Target?.Id; }
5858
/// <inheritdoc/>

src/Microsoft.OpenApi/Reader/V31/OpenApiSchemaDeserializer.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ internal static partial class OpenApiV31Deserializer
2323
},
2424
{
2525
"$schema",
26-
(o, n, _) => o.Schema = n.GetScalarValue()
26+
(o, n, _) => { if (n.GetScalarValue() is string {} sSchema && Uri.TryCreate(sSchema, UriKind.Absolute, out var schema)) {o.Schema = schema;}}
2727
},
2828
{
2929
"$id",

test/Microsoft.OpenApi.Readers.Tests/V31Tests/OpenApiSchemaTests.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public async Task ParseBasicV31SchemaShouldSucceed()
3838
var expectedObject = new OpenApiSchema()
3939
{
4040
Id = "https://example.com/arrays.schema.json",
41-
Schema = "https://json-schema.org/draft/2020-12/schema",
41+
Schema = new Uri("https://json-schema.org/draft/2020-12/schema"),
4242
Description = "A representation of a person, company, organization, or place",
4343
Type = JsonSchemaType.Object,
4444
Properties = new Dictionary<string, IOpenApiSchema>
@@ -124,7 +124,7 @@ public void ParseSchemaWithTypeArrayWorks()
124124
var expected = new OpenApiSchema()
125125
{
126126
Id = "https://example.com/arrays.schema.json",
127-
Schema = "https://json-schema.org/draft/2020-12/schema",
127+
Schema = new Uri("https://json-schema.org/draft/2020-12/schema"),
128128
Description = "A representation of a person, company, organization, or place",
129129
Type = JsonSchemaType.Object | JsonSchemaType.Null
130130
};

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ namespace Microsoft.OpenApi.Models.Interfaces
451451
System.Collections.Generic.IDictionary<string, Microsoft.OpenApi.Models.Interfaces.IOpenApiSchema> Properties { get; }
452452
bool ReadOnly { get; }
453453
System.Collections.Generic.ISet<string> Required { get; }
454-
string Schema { get; }
454+
System.Uri Schema { get; }
455455
string Title { get; }
456456
Microsoft.OpenApi.Models.JsonSchemaType? Type { get; }
457457
bool UnEvaluatedProperties { get; }
@@ -1056,7 +1056,7 @@ namespace Microsoft.OpenApi.Models
10561056
public System.Collections.Generic.IDictionary<string, Microsoft.OpenApi.Models.Interfaces.IOpenApiSchema> Properties { get; set; }
10571057
public bool ReadOnly { get; set; }
10581058
public System.Collections.Generic.ISet<string> Required { get; set; }
1059-
public string Schema { get; set; }
1059+
public System.Uri Schema { get; set; }
10601060
public string Title { get; set; }
10611061
public Microsoft.OpenApi.Models.JsonSchemaType? Type { get; set; }
10621062
public bool UnEvaluatedProperties { get; set; }
@@ -1409,7 +1409,7 @@ namespace Microsoft.OpenApi.Models.References
14091409
public System.Collections.Generic.IDictionary<string, Microsoft.OpenApi.Models.Interfaces.IOpenApiSchema> Properties { get; }
14101410
public bool ReadOnly { get; }
14111411
public System.Collections.Generic.ISet<string> Required { get; }
1412-
public string Schema { get; }
1412+
public System.Uri Schema { get; }
14131413
public string Title { get; }
14141414
public Microsoft.OpenApi.Models.JsonSchemaType? Type { get; }
14151415
public bool UnEvaluatedProperties { get; }

0 commit comments

Comments
 (0)