Skip to content

Commit

Permalink
fix: OpenAPIDocument JsonSchemaDialect property is now a URI
Browse files Browse the repository at this point in the history
Signed-off-by: Vincent Biret <vibiret@microsoft.com>
  • Loading branch information
baywet committed Feb 26, 2025
1 parent 4ee1d8b commit 45977b5
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/Microsoft.OpenApi/Models/OpenApiDocument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public void RegisterComponents()
/// <summary>
/// The default value for the $schema keyword within Schema Objects contained within this OAS document. This MUST be in the form of a URI.
/// </summary>
public string? JsonSchemaDialect { get; set; }
public Uri? JsonSchemaDialect { get; set; }

/// <summary>
/// An array of Server Objects, which provide connectivity information to a target server.
Expand Down Expand Up @@ -161,7 +161,7 @@ public void SerializeAsV31(IOpenApiWriter writer)
writer.WriteProperty(OpenApiConstants.OpenApi, "3.1.1");

// jsonSchemaDialect
writer.WriteProperty(OpenApiConstants.JsonSchemaDialect, JsonSchemaDialect);
writer.WriteProperty(OpenApiConstants.JsonSchemaDialect, JsonSchemaDialect?.ToString());

SerializeInternal(writer, OpenApiSpecVersion.OpenApi3_1, (w, element) => element.SerializeAsV31(w));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ internal static partial class OpenApiV31Deserializer
} /* Version is valid field but we already parsed it */
},
{"info", (o, n, _) => o.Info = LoadInfo(n, o)},
{"jsonSchemaDialect", (o, n, _) => o.JsonSchemaDialect = n.GetScalarValue() },
{"jsonSchemaDialect", (o, n, _) => { if (n.GetScalarValue() is string {} sjsd && Uri.TryCreate(sjsd, UriKind.Absolute, out var jsd)) {o.JsonSchemaDialect = jsd;}} },
{"servers", (o, n, _) => o.Servers = n.CreateList(LoadServer, o)},
{"paths", (o, n, _) => o.Paths = LoadPaths(n, o)},
{"webhooks", (o, n, _) => o.Webhooks = n.CreateMap(LoadPathItem, o)},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ public async Task ParseDocumentsWithReusablePathItemInWebhooksSucceeds()
Title = "Webhook Example",
Version = "1.0.0"
},
JsonSchemaDialect = "http://json-schema.org/draft-07/schema#",
JsonSchemaDialect = new Uri("http://json-schema.org/draft-07/schema#"),
Webhooks = new Dictionary<string, IOpenApiPathItem>
{
["pets"] = components.PathItems["pets"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1953,7 +1953,7 @@ public async Task SerializeDocumentWithRootJsonSchemaDialectPropertyWorks()
Title = "JsonSchemaDialectTest",
Version = "1.0.0"
},
JsonSchemaDialect = "http://json-schema.org/draft-07/schema#"
JsonSchemaDialect = new Uri("http://json-schema.org/draft-07/schema#")
};

var expected = @"openapi: '3.1.1'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -718,7 +718,7 @@ namespace Microsoft.OpenApi.Models
public System.Collections.Generic.IDictionary<string, Microsoft.OpenApi.Interfaces.IOpenApiExtension>? Extensions { get; set; }
public Microsoft.OpenApi.Models.OpenApiExternalDocs? ExternalDocs { get; set; }
public Microsoft.OpenApi.Models.OpenApiInfo Info { get; set; }
public string? JsonSchemaDialect { get; set; }
public System.Uri? JsonSchemaDialect { get; set; }
public Microsoft.OpenApi.Models.OpenApiPaths Paths { get; set; }
public System.Collections.Generic.IList<Microsoft.OpenApi.Models.OpenApiSecurityRequirement>? SecurityRequirements { get; set; }
public System.Collections.Generic.IList<Microsoft.OpenApi.Models.OpenApiServer>? Servers { get; set; }
Expand Down

0 comments on commit 45977b5

Please sign in to comment.