Skip to content

Commit eb1891a

Browse files
baywetCopilot
andcommitted
fix(library): use x-jsonschema schema extensions
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent c62769a commit eb1891a

6 files changed

Lines changed: 56 additions & 56 deletions

File tree

src/Microsoft.OpenApi/Models/OpenApiConstants.cs

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -136,14 +136,14 @@ public static class OpenApiConstants
136136
public const string UnevaluatedProperties = "unevaluatedProperties";
137137

138138
/// <summary>
139-
/// Extension: x-oai-unevaluatedProperties
139+
/// Extension: x-jsonschema-unevaluatedProperties
140140
/// </summary>
141-
public const string UnevaluatedPropertiesExtension = "x-oai-unevaluatedProperties";
141+
public const string UnevaluatedPropertiesExtension = "x-jsonschema-unevaluatedProperties";
142142

143143
/// <summary>
144-
/// Legacy extension: x-jsonschema-unevaluatedProperties
144+
/// Legacy extension: x-oai-unevaluatedProperties
145145
/// </summary>
146-
public const string LegacyUnevaluatedPropertiesExtension = "x-jsonschema-unevaluatedProperties";
146+
public const string LegacyUnevaluatedPropertiesExtension = "x-oai-unevaluatedProperties";
147147

148148
/// <summary>
149149
/// Field: Version
@@ -841,49 +841,49 @@ public static class OpenApiConstants
841841
public const string DependentRequired = "dependentRequired";
842842

843843
/// <summary>
844-
/// Extension: x-oai-$anchor
844+
/// Extension: x-jsonschema-$anchor
845845
/// </summary>
846-
public const string AnchorExtension = "x-oai-$anchor";
846+
public const string AnchorExtension = "x-jsonschema-$anchor";
847847

848848
/// <summary>
849-
/// Extension: x-oai-propertyNames
849+
/// Extension: x-jsonschema-propertyNames
850850
/// </summary>
851-
public const string PropertyNamesExtension = "x-oai-propertyNames";
851+
public const string PropertyNamesExtension = "x-jsonschema-propertyNames";
852852

853853
/// <summary>
854-
/// Extension: x-oai-dependentSchemas
854+
/// Extension: x-jsonschema-dependentSchemas
855855
/// </summary>
856-
public const string DependentSchemasExtension = "x-oai-dependentSchemas";
856+
public const string DependentSchemasExtension = "x-jsonschema-dependentSchemas";
857857

858858
/// <summary>
859-
/// Extension: x-oai-if
859+
/// Extension: x-jsonschema-if
860860
/// </summary>
861-
public const string IfExtension = "x-oai-if";
861+
public const string IfExtension = "x-jsonschema-if";
862862

863863
/// <summary>
864-
/// Extension: x-oai-then
864+
/// Extension: x-jsonschema-then
865865
/// </summary>
866-
public const string ThenExtension = "x-oai-then";
866+
public const string ThenExtension = "x-jsonschema-then";
867867

868868
/// <summary>
869-
/// Extension: x-oai-else
869+
/// Extension: x-jsonschema-else
870870
/// </summary>
871-
public const string ElseExtension = "x-oai-else";
871+
public const string ElseExtension = "x-jsonschema-else";
872872

873873
/// <summary>
874-
/// Extension: x-oai-contentEncoding
874+
/// Extension: x-jsonschema-contentEncoding
875875
/// </summary>
876-
public const string ContentEncodingExtension = "x-oai-contentEncoding";
876+
public const string ContentEncodingExtension = "x-jsonschema-contentEncoding";
877877

878878
/// <summary>
879-
/// Extension: x-oai-contentMediaType
879+
/// Extension: x-jsonschema-contentMediaType
880880
/// </summary>
881-
public const string ContentMediaTypeExtension = "x-oai-contentMediaType";
881+
public const string ContentMediaTypeExtension = "x-jsonschema-contentMediaType";
882882

883883
/// <summary>
884-
/// Extension: x-oai-contentSchema
884+
/// Extension: x-jsonschema-contentSchema
885885
/// </summary>
886-
public const string ContentSchemaExtension = "x-oai-contentSchema";
886+
public const string ContentSchemaExtension = "x-jsonschema-contentSchema";
887887

888888
#region V2.0
889889

src/Microsoft.OpenApi/Models/OpenApiSchema.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -931,14 +931,14 @@ private void SerializeAsV2(
931931
if (UnevaluatedPropertiesSchema is not null)
932932
{
933933
writer.WriteOptionalObject(
934-
OpenApiConstants.LegacyUnevaluatedPropertiesExtension,
934+
OpenApiConstants.UnevaluatedPropertiesExtension,
935935
UnevaluatedPropertiesSchema,
936936
(w, s) => s.SerializeAsV2(w));
937937
}
938938
// Write boolean false as extension if explicitly set to false
939939
else if (!UnevaluatedProperties)
940940
{
941-
writer.WritePropertyName(OpenApiConstants.LegacyUnevaluatedPropertiesExtension);
941+
writer.WritePropertyName(OpenApiConstants.UnevaluatedPropertiesExtension);
942942
writer.WriteValue(false);
943943
}
944944
}

src/Microsoft.OpenApi/PublicAPI.Shipped.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2022,7 +2022,7 @@ virtual Microsoft.OpenApi.OpenApiXml.SerializeAsV3(Microsoft.OpenApi.IOpenApiWri
20222022
virtual Microsoft.OpenApi.OpenApiXml.SerializeAsV31(Microsoft.OpenApi.IOpenApiWriter! writer) -> void
20232023
virtual Microsoft.OpenApi.OpenApiXml.SerializeAsV32(Microsoft.OpenApi.IOpenApiWriter! writer) -> void
20242024
const Microsoft.OpenApi.OpenApiConstants.OAuth2MetadataUrl = "oauth2MetadataUrl" -> string!
2025-
const Microsoft.OpenApi.OpenApiConstants.UnevaluatedPropertiesExtension = "x-oai-unevaluatedProperties" -> string!
2025+
const Microsoft.OpenApi.OpenApiConstants.UnevaluatedPropertiesExtension = "x-jsonschema-unevaluatedProperties" -> string!
20262026
Microsoft.OpenApi.IOAuth2MetadataProvider
20272027
Microsoft.OpenApi.IOAuth2MetadataProvider.OAuth2MetadataUrl.get -> System.Uri?
20282028
Microsoft.OpenApi.IOpenApiSchemaWithUnevaluatedProperties

src/Microsoft.OpenApi/PublicAPI.Unshipped.txt

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
#nullable enable
22
const Microsoft.OpenApi.OpenApiConstants.Anchor = "$anchor" -> string!
3-
const Microsoft.OpenApi.OpenApiConstants.AnchorExtension = "x-oai-$anchor" -> string!
3+
const Microsoft.OpenApi.OpenApiConstants.AnchorExtension = "x-jsonschema-$anchor" -> string!
44
const Microsoft.OpenApi.OpenApiConstants.ContentEncoding = "contentEncoding" -> string!
5-
const Microsoft.OpenApi.OpenApiConstants.ContentEncodingExtension = "x-oai-contentEncoding" -> string!
5+
const Microsoft.OpenApi.OpenApiConstants.ContentEncodingExtension = "x-jsonschema-contentEncoding" -> string!
66
const Microsoft.OpenApi.OpenApiConstants.ContentMediaType = "contentMediaType" -> string!
7-
const Microsoft.OpenApi.OpenApiConstants.ContentMediaTypeExtension = "x-oai-contentMediaType" -> string!
7+
const Microsoft.OpenApi.OpenApiConstants.ContentMediaTypeExtension = "x-jsonschema-contentMediaType" -> string!
88
const Microsoft.OpenApi.OpenApiConstants.ContentSchema = "contentSchema" -> string!
9-
const Microsoft.OpenApi.OpenApiConstants.ContentSchemaExtension = "x-oai-contentSchema" -> string!
9+
const Microsoft.OpenApi.OpenApiConstants.ContentSchemaExtension = "x-jsonschema-contentSchema" -> string!
1010
const Microsoft.OpenApi.OpenApiConstants.DependentSchemas = "dependentSchemas" -> string!
11-
const Microsoft.OpenApi.OpenApiConstants.DependentSchemasExtension = "x-oai-dependentSchemas" -> string!
11+
const Microsoft.OpenApi.OpenApiConstants.DependentSchemasExtension = "x-jsonschema-dependentSchemas" -> string!
1212
const Microsoft.OpenApi.OpenApiConstants.Else = "else" -> string!
13-
const Microsoft.OpenApi.OpenApiConstants.ElseExtension = "x-oai-else" -> string!
13+
const Microsoft.OpenApi.OpenApiConstants.ElseExtension = "x-jsonschema-else" -> string!
1414
const Microsoft.OpenApi.OpenApiConstants.If = "if" -> string!
15-
const Microsoft.OpenApi.OpenApiConstants.IfExtension = "x-oai-if" -> string!
16-
const Microsoft.OpenApi.OpenApiConstants.LegacyUnevaluatedPropertiesExtension = "x-jsonschema-unevaluatedProperties" -> string!
15+
const Microsoft.OpenApi.OpenApiConstants.IfExtension = "x-jsonschema-if" -> string!
16+
const Microsoft.OpenApi.OpenApiConstants.LegacyUnevaluatedPropertiesExtension = "x-oai-unevaluatedProperties" -> string!
1717
const Microsoft.OpenApi.OpenApiConstants.PropertyNames = "propertyNames" -> string!
18-
const Microsoft.OpenApi.OpenApiConstants.PropertyNamesExtension = "x-oai-propertyNames" -> string!
18+
const Microsoft.OpenApi.OpenApiConstants.PropertyNamesExtension = "x-jsonschema-propertyNames" -> string!
1919
const Microsoft.OpenApi.OpenApiConstants.Then = "then" -> string!
20-
const Microsoft.OpenApi.OpenApiConstants.ThenExtension = "x-oai-then" -> string!
20+
const Microsoft.OpenApi.OpenApiConstants.ThenExtension = "x-jsonschema-then" -> string!
2121
Microsoft.OpenApi.IOpenApiSchemaMissingProperties
2222
Microsoft.OpenApi.IOpenApiSchemaMissingProperties.Anchor.get -> string?
2323
Microsoft.OpenApi.IOpenApiSchemaMissingProperties.ContentEncoding.get -> string?

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -182,28 +182,28 @@ public void ParseDictionarySchemaShouldSucceed()
182182
public void ParseSchemaWithOaiCompatibilityKeywordsShouldSucceed()
183183
{
184184
var schemaJson = @"{
185-
""x-oai-$anchor"": ""root"",
186-
""x-oai-unevaluatedProperties"": false,
187-
""x-oai-contentEncoding"": ""base64"",
188-
""x-oai-contentMediaType"": ""application/jwt"",
189-
""x-oai-contentSchema"": {
185+
""x-jsonschema-$anchor"": ""root"",
186+
""x-jsonschema-unevaluatedProperties"": false,
187+
""x-jsonschema-contentEncoding"": ""base64"",
188+
""x-jsonschema-contentMediaType"": ""application/jwt"",
189+
""x-jsonschema-contentSchema"": {
190190
""type"": ""array""
191191
},
192-
""x-oai-propertyNames"": {
192+
""x-jsonschema-propertyNames"": {
193193
""pattern"": ""^[a-z]+$""
194194
},
195-
""x-oai-dependentSchemas"": {
195+
""x-jsonschema-dependentSchemas"": {
196196
""token"": {
197197
""type"": ""string""
198198
}
199199
},
200-
""x-oai-if"": {
200+
""x-jsonschema-if"": {
201201
""required"": [""token""]
202202
},
203-
""x-oai-then"": {
203+
""x-jsonschema-then"": {
204204
""minProperties"": 1
205205
},
206-
""x-oai-else"": {
206+
""x-jsonschema-else"": {
207207
""maxProperties"": 0
208208
}
209209
}";

test/Microsoft.OpenApi.Tests/Models/OpenApiSchemaTests.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1315,7 +1315,7 @@ public async Task SerializeUnevaluatedPropertiesAsExtensionInV2()
13151315
[Fact]
13161316
public async Task SerializeUnevaluatedPropertiesAsExtensionInV3()
13171317
{
1318-
var expected = @"{ ""x-oai-unevaluatedProperties"": false }";
1318+
var expected = @"{ ""x-jsonschema-unevaluatedProperties"": false }";
13191319
var schema = new OpenApiSchema
13201320
{
13211321
UnevaluatedProperties = false
@@ -1346,7 +1346,7 @@ public async Task SerializeUnevaluatedPropertiesSchemaAsExtensionInV2()
13461346
[Fact]
13471347
public async Task SerializeUnevaluatedPropertiesSchemaAsExtensionInV3()
13481348
{
1349-
var expected = @"{ ""x-oai-unevaluatedProperties"": { ""type"": ""string"" } }";
1349+
var expected = @"{ ""x-jsonschema-unevaluatedProperties"": { ""type"": ""string"" } }";
13501350
var schema = new OpenApiSchema
13511351
{
13521352
UnevaluatedPropertiesSchema = new OpenApiSchema
@@ -1438,29 +1438,29 @@ public async Task SerializeMissingPropertiesEmitsOaiExtensionsInV3()
14381438
{
14391439
var expected = JsonNode.Parse("""
14401440
{
1441-
"x-oai-$anchor": "root",
1442-
"x-oai-contentEncoding": "base64",
1443-
"x-oai-contentMediaType": "application/jwt",
1444-
"x-oai-contentSchema": {
1441+
"x-jsonschema-$anchor": "root",
1442+
"x-jsonschema-contentEncoding": "base64",
1443+
"x-jsonschema-contentMediaType": "application/jwt",
1444+
"x-jsonschema-contentSchema": {
14451445
"type": "array"
14461446
},
1447-
"x-oai-propertyNames": {
1447+
"x-jsonschema-propertyNames": {
14481448
"pattern": "^[a-z]+$"
14491449
},
1450-
"x-oai-dependentSchemas": {
1450+
"x-jsonschema-dependentSchemas": {
14511451
"token": {
14521452
"type": "string"
14531453
}
14541454
},
1455-
"x-oai-if": {
1455+
"x-jsonschema-if": {
14561456
"required": [
14571457
"token"
14581458
]
14591459
},
1460-
"x-oai-then": {
1460+
"x-jsonschema-then": {
14611461
"minProperties": 1
14621462
},
1463-
"x-oai-else": {
1463+
"x-jsonschema-else": {
14641464
"maxProperties": 0
14651465
}
14661466
}

0 commit comments

Comments
 (0)