diff --git a/src/Microsoft.OpenApi/Models/OpenApiSchema.cs b/src/Microsoft.OpenApi/Models/OpenApiSchema.cs index f50c0192f..416cd7dba 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiSchema.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiSchema.cs @@ -104,6 +104,14 @@ public string? ExclusiveMinimum /// public JsonSchemaType? Type { get; set; } + // x-nullable is filtered out by deserializers, but keep the check here in case it gets added from user code. + private bool IsNullable => + (Type.HasValue && Type.Value.HasFlag(JsonSchemaType.Null)) || + Extensions is not null && + Extensions.TryGetValue(OpenApiConstants.NullableExtension, out var nullExtRawValue) && + nullExtRawValue is JsonNodeExtension { Node: JsonNode jsonNode } && + jsonNode.GetValueKind() is JsonValueKind.True; + /// public string? Const { get; set; } @@ -437,7 +445,7 @@ private void SerializeInternal(IOpenApiWriter writer, OpenApiSpecVersion version writer.WriteOptionalCollection(OpenApiConstants.Enum, Enum, (nodeWriter, s) => nodeWriter.WriteAny(s)); // type - SerializeTypeProperty(Type, writer, version); + SerializeTypeProperty(writer, version); // allOf writer.WriteOptionalCollection(OpenApiConstants.AllOf, AllOf, callback); @@ -479,6 +487,12 @@ private void SerializeInternal(IOpenApiWriter writer, OpenApiSpecVersion version // default writer.WriteOptionalObject(OpenApiConstants.Default, Default, (w, d) => w.WriteAny(d)); + // nullable + if (version == OpenApiSpecVersion.OpenApi3_0) + { + SerializeNullable(writer, version); + } + // discriminator writer.WriteOptionalObject(OpenApiConstants.Discriminator, Discriminator, callback); @@ -619,7 +633,7 @@ private void SerializeAsV2( writer.WriteStartObject(); // type - SerializeTypeProperty(Type, writer, OpenApiSpecVersion.OpenApi2_0); + SerializeTypeProperty(writer, OpenApiSpecVersion.OpenApi2_0); // description writer.WriteProperty(OpenApiConstants.Description, Description); @@ -742,68 +756,36 @@ private void SerializeAsV2( // example writer.WriteOptionalObject(OpenApiConstants.Example, Example, (w, e) => w.WriteAny(e)); + // x-nullable extension + SerializeNullable(writer, OpenApiSpecVersion.OpenApi2_0); + // extensions writer.WriteExtensions(Extensions, OpenApiSpecVersion.OpenApi2_0); writer.WriteEndObject(); } - private void SerializeTypeProperty(JsonSchemaType? type, IOpenApiWriter writer, OpenApiSpecVersion version) + private void SerializeTypeProperty(IOpenApiWriter writer, OpenApiSpecVersion version) { - // check whether nullable is true for upcasting purposes - var isNullable = (Type.HasValue && Type.Value.HasFlag(JsonSchemaType.Null)) || - Extensions is not null && - Extensions.TryGetValue(OpenApiConstants.NullableExtension, out var nullExtRawValue) && - nullExtRawValue is JsonNodeExtension { Node: JsonNode jsonNode } && - jsonNode.GetValueKind() is JsonValueKind.True; - if (type is null) + if (Type is null) { - if (version is OpenApiSpecVersion.OpenApi3_0 && isNullable) - { - writer.WriteProperty(OpenApiConstants.Nullable, true); - } + return; } - else if (!HasMultipleTypes(type.Value)) - { - switch (version) - { - case OpenApiSpecVersion.OpenApi3_1 when isNullable: - UpCastSchemaTypeToV31(type.Value, writer); - break; - case OpenApiSpecVersion.OpenApi3_0 when isNullable && type.Value == JsonSchemaType.Null: - writer.WriteProperty(OpenApiConstants.Nullable, true); - writer.WriteProperty(OpenApiConstants.Type, JsonSchemaType.Object.ToFirstIdentifier()); - break; - case OpenApiSpecVersion.OpenApi3_0 when isNullable && type.Value != JsonSchemaType.Null: - writer.WriteProperty(OpenApiConstants.Nullable, true); - writer.WriteProperty(OpenApiConstants.Type, type.Value.ToFirstIdentifier()); - break; - default: - writer.WriteProperty(OpenApiConstants.Type, type.Value.ToFirstIdentifier()); - break; - } - } - else + var unifiedType = IsNullable ? Type.Value | JsonSchemaType.Null : Type.Value; + var typeWithoutNull = unifiedType & ~JsonSchemaType.Null; + + switch (version) { - // type - if (version is OpenApiSpecVersion.OpenApi2_0 || version is OpenApiSpecVersion.OpenApi3_0) - { - DowncastTypeArrayToV2OrV3(type.Value, writer, version); - } - else - { - var list = (from JsonSchemaType flag in jsonSchemaTypeValues - where type.Value.HasFlag(flag) - select flag).ToList(); - writer.WriteOptionalCollection(OpenApiConstants.Type, list, (w, s) => + case OpenApiSpecVersion.OpenApi2_0 or OpenApiSpecVersion.OpenApi3_0: + if (typeWithoutNull != 0 && !HasMultipleTypes(typeWithoutNull)) { - foreach (var item in s.ToIdentifiers()) - { - w.WriteValue(item); - } - }); - } + writer.WriteProperty(OpenApiConstants.Type, typeWithoutNull.ToFirstIdentifier()); + } + break; + default: + WriteUnifiedSchemaType(unifiedType, writer); + break; } } @@ -815,20 +797,17 @@ private static bool IsPowerOfTwo(int x) private static bool HasMultipleTypes(JsonSchemaType schemaType) { var schemaTypeNumeric = (int)schemaType; - return !IsPowerOfTwo(schemaTypeNumeric) && // Boolean, Integer, Number, String, Array, Object - schemaTypeNumeric != (int)JsonSchemaType.Null; + return !IsPowerOfTwo(schemaTypeNumeric); } - private static void UpCastSchemaTypeToV31(JsonSchemaType type, IOpenApiWriter writer) + private static void WriteUnifiedSchemaType(JsonSchemaType type, IOpenApiWriter writer) { - // create a new array and insert the type and "null" as values - var temporaryType = type | JsonSchemaType.Null; - var list = (from JsonSchemaType flag in jsonSchemaTypeValues// Check if the flag is set in 'type' using a bitwise AND operation - where temporaryType.HasFlag(flag) - select flag.ToFirstIdentifier()).ToList(); - if (list.Count > 1) + var array = (from JsonSchemaType flag in jsonSchemaTypeValues + where type.HasFlag(flag) + select flag.ToFirstIdentifier()).ToArray(); + if (array.Length > 1) { - writer.WriteOptionalCollection(OpenApiConstants.Type, list, (w, s) => + writer.WriteOptionalCollection(OpenApiConstants.Type, array, (w, s) => { if (!string.IsNullOrEmpty(s) && s is not null) { @@ -838,54 +817,32 @@ where temporaryType.HasFlag(flag) } else { - writer.WriteProperty(OpenApiConstants.Type, list[0]); + writer.WriteProperty(OpenApiConstants.Type, array[0]); } } -#if NET5_0_OR_GREATER - private static readonly Array jsonSchemaTypeValues = System.Enum.GetValues(); -#else - private static readonly Array jsonSchemaTypeValues = System.Enum.GetValues(typeof(JsonSchemaType)); -#endif - - private static void DowncastTypeArrayToV2OrV3(JsonSchemaType schemaType, IOpenApiWriter writer, OpenApiSpecVersion version) + private void SerializeNullable(IOpenApiWriter writer, OpenApiSpecVersion version) { - /* If the array has one non-null value, emit Type as string - * If the array has one null value, emit x-nullable as true - * If the array has two values, one null and one non-null, emit Type as string and x-nullable as true - * If the array has more than two values or two non-null values, do not emit type - * */ - - var nullableProp = version.Equals(OpenApiSpecVersion.OpenApi2_0) - ? OpenApiConstants.NullableExtension - : OpenApiConstants.Nullable; - - if (!HasMultipleTypes(schemaType & ~JsonSchemaType.Null) && (schemaType & JsonSchemaType.Null) == JsonSchemaType.Null) // checks for two values and one is null - { - foreach (JsonSchemaType flag in jsonSchemaTypeValues) - { - // Skip if the flag is not set or if it's the Null flag - if (schemaType.HasFlag(flag) && flag != JsonSchemaType.Null) - { - // Write the non-null flag value to the writer - writer.WriteProperty(OpenApiConstants.Type, flag.ToFirstIdentifier()); - } - } - writer.WriteProperty(nullableProp, true); - } - else if (!HasMultipleTypes(schemaType)) + if (IsNullable) { - if (schemaType is JsonSchemaType.Null) - { - writer.WriteProperty(nullableProp, true); - } - else + switch (version) { - writer.WriteProperty(OpenApiConstants.Type, schemaType.ToFirstIdentifier()); + case OpenApiSpecVersion.OpenApi2_0: + writer.WriteProperty(OpenApiConstants.NullableExtension, true); + break; + case OpenApiSpecVersion.OpenApi3_0: + writer.WriteProperty(OpenApiConstants.Nullable, true); + break; } } } +#if NET5_0_OR_GREATER + private static readonly Array jsonSchemaTypeValues = System.Enum.GetValues(); +#else + private static readonly Array jsonSchemaTypeValues = System.Enum.GetValues(typeof(JsonSchemaType)); +#endif + /// public IOpenApiSchema CreateShallowCopy() { diff --git a/src/Microsoft.OpenApi/Reader/V2/OpenApiSchemaDeserializer.cs b/src/Microsoft.OpenApi/Reader/V2/OpenApiSchemaDeserializer.cs index a3fb1153d..23abd587b 100644 --- a/src/Microsoft.OpenApi/Reader/V2/OpenApiSchemaDeserializer.cs +++ b/src/Microsoft.OpenApi/Reader/V2/OpenApiSchemaDeserializer.cs @@ -271,6 +271,16 @@ public static IOpenApiSchema LoadSchema(ParseNode node, OpenApiDocument hostDocu propertyNode.ParseField(schema, _openApiSchemaFixedFields, _openApiSchemaPatternFields, hostDocument); } + if (schema.Extensions is not null && schema.Extensions.ContainsKey(OpenApiConstants.NullableExtension)) + { + if (schema.Type.HasValue) + schema.Type |= JsonSchemaType.Null; + else + schema.Type = JsonSchemaType.Null; + + schema.Extensions.Remove(OpenApiConstants.NullableExtension); + } + return schema; } } diff --git a/src/Microsoft.OpenApi/Reader/V3/OpenApiSchemaDeserializer.cs b/src/Microsoft.OpenApi/Reader/V3/OpenApiSchemaDeserializer.cs index 85e418b7f..5e18fd502 100644 --- a/src/Microsoft.OpenApi/Reader/V3/OpenApiSchemaDeserializer.cs +++ b/src/Microsoft.OpenApi/Reader/V3/OpenApiSchemaDeserializer.cs @@ -159,7 +159,7 @@ internal static partial class OpenApiV3Deserializer "type", (o, n, _) => { var type = n.GetScalarValue()?.ToJsonSchemaType(); - // so we don't loose the value from nullable + // so we don't lose the value from nullable if (o.Type.HasValue) o.Type |= type; else @@ -307,6 +307,16 @@ public static IOpenApiSchema LoadSchema(ParseNode node, OpenApiDocument hostDocu propertyNode.ParseField(schema, _openApiSchemaFixedFields, _openApiSchemaPatternFields, hostDocument); } + if (schema.Extensions is not null && schema.Extensions.ContainsKey(OpenApiConstants.NullableExtension)) + { + if (schema.Type.HasValue) + schema.Type |= JsonSchemaType.Null; + else + schema.Type = JsonSchemaType.Null; + + schema.Extensions.Remove(OpenApiConstants.NullableExtension); + } + return schema; } } diff --git a/src/Microsoft.OpenApi/Reader/V31/OpenApiSchemaDeserializer.cs b/src/Microsoft.OpenApi/Reader/V31/OpenApiSchemaDeserializer.cs index 71265aa8c..0a87ab5b8 100644 --- a/src/Microsoft.OpenApi/Reader/V31/OpenApiSchemaDeserializer.cs +++ b/src/Microsoft.OpenApi/Reader/V31/OpenApiSchemaDeserializer.cs @@ -286,7 +286,10 @@ internal static partial class OpenApiV31Deserializer var nullable = bool.Parse(value); if (nullable) // if nullable, convert type into an array of type(s) and null { - o.Type |= JsonSchemaType.Null; + if (o.Type.HasValue) + o.Type |= JsonSchemaType.Null; + else + o.Type = JsonSchemaType.Null; } } } @@ -392,8 +395,11 @@ public static IOpenApiSchema LoadSchema(ParseNode node, OpenApiDocument hostDocu if (schema.Extensions is not null && schema.Extensions.ContainsKey(OpenApiConstants.NullableExtension)) { - var type = schema.Type; - schema.Type = type | JsonSchemaType.Null; + if (schema.Type.HasValue) + schema.Type |= JsonSchemaType.Null; + else + schema.Type = JsonSchemaType.Null; + schema.Extensions.Remove(OpenApiConstants.NullableExtension); } diff --git a/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiSchemaTests.cs b/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiSchemaTests.cs index b4dfae059..bb81366c1 100644 --- a/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiSchemaTests.cs +++ b/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiSchemaTests.cs @@ -2,18 +2,19 @@ // Licensed under the MIT license. using System.IO; -using FluentAssertions; -using Microsoft.OpenApi.Reader.V2; -using Xunit; -using Microsoft.OpenApi.Reader.ParseNodes; -using Microsoft.OpenApi.Models; -using Microsoft.OpenApi.Extensions; using System.Text.Json.Nodes; -using System.Collections.Generic; +using System.Threading.Tasks; +using FluentAssertions; using FluentAssertions.Equivalency; +using Microsoft.OpenApi.Extensions; +using Microsoft.OpenApi.Models; using Microsoft.OpenApi.Models.References; +using Microsoft.OpenApi.Reader; +using Microsoft.OpenApi.Reader.ParseNodes; +using Microsoft.OpenApi.Reader.V2; +using Microsoft.OpenApi.Tests; using Microsoft.OpenApi.Writers; -using Microsoft.OpenApi.Models.Interfaces; +using Xunit; namespace Microsoft.OpenApi.Readers.Tests.V2Tests { @@ -98,6 +99,7 @@ public void ParseSchemaWithEnumShouldSucceed() .Excluding((IMemberInfo memberInfo) => memberInfo.Path.EndsWith("Parent"))); } + [Fact] public void PropertiesReferenceShouldWork() { @@ -152,5 +154,42 @@ public void PropertiesReferenceShouldWork() ); Assert.True(JsonNode.DeepEquals(JsonNode.Parse(json), expected)); } + + [Fact] + public async Task SerializeSchemaWithNullableShouldSucceed() + { + // Arrange + var expected = @"type: string +x-nullable: true"; + + var path = Path.Combine(SampleFolderPath, "schemaWithNullableExtension.yaml"); + + // Act + var schema = await OpenApiModelFactory.LoadAsync(path, OpenApiSpecVersion.OpenApi2_0, new(), SettingsFixture.ReaderSettings); + + var writer = new StringWriter(); + schema.SerializeAsV2(new OpenApiYamlWriter(writer)); + var schemaString = writer.ToString(); + + Assert.Equal(expected.MakeLineBreaksEnvironmentNeutral(), schemaString.MakeLineBreaksEnvironmentNeutral()); + } + + [Fact] + public async Task SerializeSchemaWithOnlyNullableShouldSucceed() + { + // Arrange + var expected = @"x-nullable: true"; + + var path = Path.Combine(SampleFolderPath, "schemaWithOnlyNullableExtension.yaml"); + + // Act + var schema = await OpenApiModelFactory.LoadAsync(path, OpenApiSpecVersion.OpenApi2_0, new(), SettingsFixture.ReaderSettings); + + var writer = new StringWriter(); + schema.SerializeAsV2(new OpenApiYamlWriter(writer)); + var schemaString = writer.ToString(); + + Assert.Equal(expected.MakeLineBreaksEnvironmentNeutral(), schemaString.MakeLineBreaksEnvironmentNeutral()); + } } } diff --git a/test/Microsoft.OpenApi.Readers.Tests/V2Tests/Samples/OpenApiSchema/schemaWithNullableExtension.yaml b/test/Microsoft.OpenApi.Readers.Tests/V2Tests/Samples/OpenApiSchema/schemaWithNullableExtension.yaml new file mode 100644 index 000000000..e9bfbd513 --- /dev/null +++ b/test/Microsoft.OpenApi.Readers.Tests/V2Tests/Samples/OpenApiSchema/schemaWithNullableExtension.yaml @@ -0,0 +1,2 @@ +type: string +x-nullable: true \ No newline at end of file diff --git a/test/Microsoft.OpenApi.Readers.Tests/V2Tests/Samples/OpenApiSchema/schemaWithOnlyNullableExtension.yaml b/test/Microsoft.OpenApi.Readers.Tests/V2Tests/Samples/OpenApiSchema/schemaWithOnlyNullableExtension.yaml new file mode 100644 index 000000000..4c7740909 --- /dev/null +++ b/test/Microsoft.OpenApi.Readers.Tests/V2Tests/Samples/OpenApiSchema/schemaWithOnlyNullableExtension.yaml @@ -0,0 +1 @@ +x-nullable: true \ No newline at end of file diff --git a/test/Microsoft.OpenApi.Readers.Tests/V31Tests/OpenApiSchemaTests.cs b/test/Microsoft.OpenApi.Readers.Tests/V31Tests/OpenApiSchemaTests.cs index 9ccb8d0ee..6277f1755 100644 --- a/test/Microsoft.OpenApi.Readers.Tests/V31Tests/OpenApiSchemaTests.cs +++ b/test/Microsoft.OpenApi.Readers.Tests/V31Tests/OpenApiSchemaTests.cs @@ -384,8 +384,7 @@ public async Task SerializeV2SchemaWithNullableExtensionAsV31Works() // Arrange var expected = @"type: - 'null' - - string -x-nullable: true"; + - string"; var path = Path.Combine(SampleFolderPath, "schemaWithNullableExtension.yaml"); @@ -407,7 +406,7 @@ public void SerializeSchemaWithTypeArrayAndNullableDoesntEmitType() - ""int"" nullable: true"; - var expected = @"{ }"; + var expected = @"x-nullable: true"; var schema = OpenApiModelFactory.Parse(input, OpenApiSpecVersion.OpenApi3_1, new(), out _, "yaml", SettingsFixture.ReaderSettings); diff --git a/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiSchemaTests.cs b/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiSchemaTests.cs index 34cd2f9ca..55b403a8b 100644 --- a/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiSchemaTests.cs +++ b/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiSchemaTests.cs @@ -3,21 +3,22 @@ using System.Collections.Generic; using System.IO; +using System.Net.Http; using System.Text.Json.Nodes; +using System.Threading.Tasks; using FluentAssertions; -using Microsoft.OpenApi.Models; +using FluentAssertions.Equivalency; using Microsoft.OpenApi.Extensions; -using SharpYaml.Serialization; -using Xunit; +using Microsoft.OpenApi.Models; +using Microsoft.OpenApi.Models.References; using Microsoft.OpenApi.Reader; using Microsoft.OpenApi.Reader.ParseNodes; using Microsoft.OpenApi.Reader.V3; -using FluentAssertions.Equivalency; -using Microsoft.OpenApi.Models.References; -using System.Threading.Tasks; -using System.Net.Http; +using Microsoft.OpenApi.Tests; +using Microsoft.OpenApi.Writers; using Microsoft.OpenApi.YamlReader; -using Microsoft.OpenApi.Models.Interfaces; +using SharpYaml.Serialization; +using Xunit; namespace Microsoft.OpenApi.Readers.Tests.V3Tests { @@ -445,5 +446,42 @@ public async Task ParseExternalReferenceSchemaShouldSucceed() Assert.Equivalent(expectedComponents, components); } + + [Fact] + public async Task SerializeSchemaWithNullableShouldSucceed() + { + // Arrange + var expected = @"type: string +nullable: true"; + + var path = Path.Combine(SampleFolderPath, "schemaWithNullable.yaml"); + + // Act + var schema = await OpenApiModelFactory.LoadAsync(path, OpenApiSpecVersion.OpenApi3_0, new(), SettingsFixture.ReaderSettings); + + var writer = new StringWriter(); + schema.SerializeAsV3(new OpenApiYamlWriter(writer)); + var schemaString = writer.ToString(); + + Assert.Equal(expected.MakeLineBreaksEnvironmentNeutral(), schemaString.MakeLineBreaksEnvironmentNeutral()); + } + + [Fact] + public async Task SerializeSchemaWithOnlyNullableShouldSucceed() + { + // Arrange + var expected = @"nullable: true"; + + var path = Path.Combine(SampleFolderPath, "schemaWithOnlyNullable.yaml"); + + // Act + var schema = await OpenApiModelFactory.LoadAsync(path, OpenApiSpecVersion.OpenApi3_0, new(), SettingsFixture.ReaderSettings); + + var writer = new StringWriter(); + schema.SerializeAsV3(new OpenApiYamlWriter(writer)); + var schemaString = writer.ToString(); + + Assert.Equal(expected.MakeLineBreaksEnvironmentNeutral(), schemaString.MakeLineBreaksEnvironmentNeutral()); + } } } diff --git a/test/Microsoft.OpenApi.Readers.Tests/V3Tests/Samples/OpenApiSchema/schemaWithNullable.yaml b/test/Microsoft.OpenApi.Readers.Tests/V3Tests/Samples/OpenApiSchema/schemaWithNullable.yaml new file mode 100644 index 000000000..913c768d3 --- /dev/null +++ b/test/Microsoft.OpenApi.Readers.Tests/V3Tests/Samples/OpenApiSchema/schemaWithNullable.yaml @@ -0,0 +1,2 @@ +type: string +nullable: true \ No newline at end of file diff --git a/test/Microsoft.OpenApi.Readers.Tests/V3Tests/Samples/OpenApiSchema/schemaWithOnlyNullable.yaml b/test/Microsoft.OpenApi.Readers.Tests/V3Tests/Samples/OpenApiSchema/schemaWithOnlyNullable.yaml new file mode 100644 index 000000000..689dd14b7 --- /dev/null +++ b/test/Microsoft.OpenApi.Readers.Tests/V3Tests/Samples/OpenApiSchema/schemaWithOnlyNullable.yaml @@ -0,0 +1 @@ +nullable: true \ No newline at end of file diff --git a/test/Microsoft.OpenApi.Tests/Models/OpenApiSchemaTests.SerializeReferencedSchemaAsV3JsonWorksAsync_produceTerseOutput=False.verified.txt b/test/Microsoft.OpenApi.Tests/Models/OpenApiSchemaTests.SerializeReferencedSchemaAsV3JsonWorksAsync_produceTerseOutput=False.verified.txt index aac504993..b431f1607 100644 --- a/test/Microsoft.OpenApi.Tests/Models/OpenApiSchemaTests.SerializeReferencedSchemaAsV3JsonWorksAsync_produceTerseOutput=False.verified.txt +++ b/test/Microsoft.OpenApi.Tests/Models/OpenApiSchemaTests.SerializeReferencedSchemaAsV3JsonWorksAsync_produceTerseOutput=False.verified.txt @@ -5,8 +5,8 @@ "minimum": 10, "exclusiveMinimum": true, "type": "integer", - "nullable": true, "default": 15, + "nullable": true, "externalDocs": { "url": "http://example.com/externalDocs" } diff --git a/test/Microsoft.OpenApi.Tests/Models/OpenApiSchemaTests.SerializeReferencedSchemaAsV3JsonWorksAsync_produceTerseOutput=True.verified.txt b/test/Microsoft.OpenApi.Tests/Models/OpenApiSchemaTests.SerializeReferencedSchemaAsV3JsonWorksAsync_produceTerseOutput=True.verified.txt index 3ed4ce5c8..d71a5f0a8 100644 --- a/test/Microsoft.OpenApi.Tests/Models/OpenApiSchemaTests.SerializeReferencedSchemaAsV3JsonWorksAsync_produceTerseOutput=True.verified.txt +++ b/test/Microsoft.OpenApi.Tests/Models/OpenApiSchemaTests.SerializeReferencedSchemaAsV3JsonWorksAsync_produceTerseOutput=True.verified.txt @@ -1 +1 @@ -{"title":"title1","multipleOf":3,"maximum":42,"minimum":10,"exclusiveMinimum":true,"type":"integer","nullable":true,"default":15,"externalDocs":{"url":"http://example.com/externalDocs"}} \ No newline at end of file +{"title":"title1","multipleOf":3,"maximum":42,"minimum":10,"exclusiveMinimum":true,"type":"integer","default":15,"nullable":true,"externalDocs":{"url":"http://example.com/externalDocs"}} \ No newline at end of file diff --git a/test/Microsoft.OpenApi.Tests/Models/OpenApiSchemaTests.SerializeReferencedSchemaAsV3WithoutReferenceJsonWorksAsync_produceTerseOutput=False.verified.txt b/test/Microsoft.OpenApi.Tests/Models/OpenApiSchemaTests.SerializeReferencedSchemaAsV3WithoutReferenceJsonWorksAsync_produceTerseOutput=False.verified.txt index aac504993..b431f1607 100644 --- a/test/Microsoft.OpenApi.Tests/Models/OpenApiSchemaTests.SerializeReferencedSchemaAsV3WithoutReferenceJsonWorksAsync_produceTerseOutput=False.verified.txt +++ b/test/Microsoft.OpenApi.Tests/Models/OpenApiSchemaTests.SerializeReferencedSchemaAsV3WithoutReferenceJsonWorksAsync_produceTerseOutput=False.verified.txt @@ -5,8 +5,8 @@ "minimum": 10, "exclusiveMinimum": true, "type": "integer", - "nullable": true, "default": 15, + "nullable": true, "externalDocs": { "url": "http://example.com/externalDocs" } diff --git a/test/Microsoft.OpenApi.Tests/Models/OpenApiSchemaTests.SerializeReferencedSchemaAsV3WithoutReferenceJsonWorksAsync_produceTerseOutput=True.verified.txt b/test/Microsoft.OpenApi.Tests/Models/OpenApiSchemaTests.SerializeReferencedSchemaAsV3WithoutReferenceJsonWorksAsync_produceTerseOutput=True.verified.txt index 3ed4ce5c8..d71a5f0a8 100644 --- a/test/Microsoft.OpenApi.Tests/Models/OpenApiSchemaTests.SerializeReferencedSchemaAsV3WithoutReferenceJsonWorksAsync_produceTerseOutput=True.verified.txt +++ b/test/Microsoft.OpenApi.Tests/Models/OpenApiSchemaTests.SerializeReferencedSchemaAsV3WithoutReferenceJsonWorksAsync_produceTerseOutput=True.verified.txt @@ -1 +1 @@ -{"title":"title1","multipleOf":3,"maximum":42,"minimum":10,"exclusiveMinimum":true,"type":"integer","nullable":true,"default":15,"externalDocs":{"url":"http://example.com/externalDocs"}} \ No newline at end of file +{"title":"title1","multipleOf":3,"maximum":42,"minimum":10,"exclusiveMinimum":true,"type":"integer","default":15,"nullable":true,"externalDocs":{"url":"http://example.com/externalDocs"}} \ No newline at end of file diff --git a/test/Microsoft.OpenApi.Tests/Models/OpenApiSchemaTests.SerializeSchemaWRequiredPropertiesAsV2JsonWorksAsync_produceTerseOutput=False.verified.txt b/test/Microsoft.OpenApi.Tests/Models/OpenApiSchemaTests.SerializeSchemaWRequiredPropertiesAsV2JsonWorksAsync_produceTerseOutput=False.verified.txt index e30457226..d3fc6366f 100644 --- a/test/Microsoft.OpenApi.Tests/Models/OpenApiSchemaTests.SerializeSchemaWRequiredPropertiesAsV2JsonWorksAsync_produceTerseOutput=False.verified.txt +++ b/test/Microsoft.OpenApi.Tests/Models/OpenApiSchemaTests.SerializeSchemaWRequiredPropertiesAsV2JsonWorksAsync_produceTerseOutput=False.verified.txt @@ -1,6 +1,5 @@ { "type": "object", - "x-nullable": true, "title": "title1", "required": [ "property1" @@ -39,5 +38,6 @@ }, "externalDocs": { "url": "http://example.com/externalDocs" - } + }, + "x-nullable": true } \ No newline at end of file diff --git a/test/Microsoft.OpenApi.Tests/Models/OpenApiSchemaTests.SerializeSchemaWRequiredPropertiesAsV2JsonWorksAsync_produceTerseOutput=True.verified.txt b/test/Microsoft.OpenApi.Tests/Models/OpenApiSchemaTests.SerializeSchemaWRequiredPropertiesAsV2JsonWorksAsync_produceTerseOutput=True.verified.txt index d5d9596f0..5cb705531 100644 --- a/test/Microsoft.OpenApi.Tests/Models/OpenApiSchemaTests.SerializeSchemaWRequiredPropertiesAsV2JsonWorksAsync_produceTerseOutput=True.verified.txt +++ b/test/Microsoft.OpenApi.Tests/Models/OpenApiSchemaTests.SerializeSchemaWRequiredPropertiesAsV2JsonWorksAsync_produceTerseOutput=True.verified.txt @@ -1 +1 @@ -{"type":"object","x-nullable":true,"title":"title1","required":["property1"],"properties":{"property1":{"required":["property3"],"properties":{"property2":{"type":"integer"},"property3":{"type":"string","maxLength":15}}},"property4":{"properties":{"property5":{"properties":{"property6":{"type":"boolean"}}},"property7":{"type":"string","minLength":2}},"readOnly":true}},"externalDocs":{"url":"http://example.com/externalDocs"}} \ No newline at end of file +{"type":"object","title":"title1","required":["property1"],"properties":{"property1":{"required":["property3"],"properties":{"property2":{"type":"integer"},"property3":{"type":"string","maxLength":15}}},"property4":{"properties":{"property5":{"properties":{"property6":{"type":"boolean"}}},"property7":{"type":"string","minLength":2}},"readOnly":true}},"externalDocs":{"url":"http://example.com/externalDocs"},"x-nullable":true} \ No newline at end of file