From 71ff997459ea422163a74acd08c105f93b95584e Mon Sep 17 00:00:00 2001 From: Maggiekimani1 Date: Tue, 8 Apr 2025 16:10:59 +0300 Subject: [PATCH 1/5] fix: read (Exclusive)Maximum and (Exclusive)Minimum values as strings and write their raw values --- .../Models/Interfaces/IOpenApiSchema.cs | 8 +-- src/Microsoft.OpenApi/Models/OpenApiSchema.cs | 51 ++++++++++--------- .../References/OpenApiSchemaReference.cs | 8 +-- .../Reader/V2/OpenApiHeaderDeserializer.cs | 8 +-- .../Reader/V2/OpenApiParameterDeserializer.cs | 8 +-- .../Reader/V2/OpenApiSchemaDeserializer.cs | 8 +-- .../Reader/V3/OpenApiSchemaDeserializer.cs | 10 ++-- .../Reader/V31/OpenApiSchemaDeserializer.cs | 12 ++--- 8 files changed, 59 insertions(+), 54 deletions(-) diff --git a/src/Microsoft.OpenApi/Models/Interfaces/IOpenApiSchema.cs b/src/Microsoft.OpenApi/Models/Interfaces/IOpenApiSchema.cs index 954e6b094..a960f2a5a 100644 --- a/src/Microsoft.OpenApi/Models/Interfaces/IOpenApiSchema.cs +++ b/src/Microsoft.OpenApi/Models/Interfaces/IOpenApiSchema.cs @@ -56,12 +56,12 @@ public interface IOpenApiSchema : IOpenApiDescribedElement, IOpenApiReadOnlyExte /// /// Follow JSON Schema definition: https://tools.ietf.org/html/draft-fge-json-schema-validation-00 /// - public decimal? ExclusiveMaximum { get; } + public string? ExclusiveMaximum { get; } /// /// Follow JSON Schema definition: https://tools.ietf.org/html/draft-fge-json-schema-validation-00 /// - public decimal? ExclusiveMinimum { get; } + public string? ExclusiveMinimum { get; } /// /// Follow JSON Schema definition: https://tools.ietf.org/html/draft-fge-json-schema-validation-00 @@ -84,12 +84,12 @@ public interface IOpenApiSchema : IOpenApiDescribedElement, IOpenApiReadOnlyExte /// /// Follow JSON Schema definition: https://tools.ietf.org/html/draft-fge-json-schema-validation-00 /// - public decimal? Maximum { get; } + public string? Maximum { get; } /// /// Follow JSON Schema definition: https://tools.ietf.org/html/draft-fge-json-schema-validation-00 /// - public decimal? Minimum { get; } + public string? Minimum { get; } /// /// Follow JSON Schema definition: https://tools.ietf.org/html/draft-fge-json-schema-validation-00 diff --git a/src/Microsoft.OpenApi/Models/OpenApiSchema.cs b/src/Microsoft.OpenApi/Models/OpenApiSchema.cs index 6f5014f07..e3fcbfcaa 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiSchema.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiSchema.cs @@ -44,17 +44,17 @@ public class OpenApiSchema : IOpenApiExtensible, IOpenApiSchema /// public IDictionary? Definitions { get; set; } - private decimal? _exclusiveMaximum; + private string? _exclusiveMaximum; /// - public decimal? ExclusiveMaximum + public string? ExclusiveMaximum { get { - if (_exclusiveMaximum.HasValue) + if (!string.IsNullOrEmpty(_exclusiveMaximum)) { return _exclusiveMaximum; } - if (IsExclusiveMaximum == true && _maximum.HasValue) + if (IsExclusiveMaximum == true && !string.IsNullOrEmpty(_maximum)) { return _maximum; } @@ -73,17 +73,17 @@ public decimal? ExclusiveMaximum /// DO NOT CHANGE THE VISIBILITY OF THIS PROPERTY TO PUBLIC internal bool? IsExclusiveMaximum { get; set; } - private decimal? _exclusiveMinimum; + private string? _exclusiveMinimum; /// - public decimal? ExclusiveMinimum + public string? ExclusiveMinimum { get { - if (_exclusiveMinimum.HasValue) + if (!string.IsNullOrEmpty(_exclusiveMinimum)) { return _exclusiveMinimum; } - if (IsExclusiveMinimum == true && _minimum.HasValue) + if (IsExclusiveMinimum == true && !string.IsNullOrEmpty(_minimum)) { return _minimum; } @@ -114,9 +114,9 @@ public decimal? ExclusiveMinimum /// public string? Description { get; set; } - private decimal? _maximum; + private string? _maximum; /// - public decimal? Maximum + public string? Maximum { get { @@ -132,10 +132,10 @@ public decimal? Maximum } } - private decimal? _minimum; + private string? _minimum; /// - public decimal? Minimum + public string? Minimum { get { @@ -334,38 +334,43 @@ public void SerializeAsV3(IOpenApiWriter writer) SerializeInternal(writer, OpenApiSpecVersion.OpenApi3_0, (writer, element) => element.SerializeAsV3(writer)); } - private static void SerializeBounds(IOpenApiWriter writer, OpenApiSpecVersion version, string propertyName, string exclusivePropertyName, string isExclusivePropertyName, decimal? value, decimal? exclusiveValue, bool? isExclusiveValue) + private static void SerializeBounds(IOpenApiWriter writer, OpenApiSpecVersion version, string propertyName, string exclusivePropertyName, string isExclusivePropertyName, string? value, string? exclusiveValue, bool? isExclusiveValue) { if (version >= OpenApiSpecVersion.OpenApi3_1) { - if (exclusiveValue.HasValue) + if (!string.IsNullOrEmpty(exclusiveValue) && exclusiveValue is not null) { // was explicitly set in the document or object model - writer.WriteProperty(exclusivePropertyName, exclusiveValue.Value); + writer.WritePropertyName(exclusivePropertyName); + writer.WriteRaw(exclusiveValue); } - else if (isExclusiveValue == true && value.HasValue) + else if (isExclusiveValue == true && !string.IsNullOrEmpty(value)) { // came from parsing an old document - writer.WriteProperty(exclusivePropertyName, value); + writer.WritePropertyName(exclusivePropertyName); + writer.WriteRaw(value!); } - else if (value.HasValue) + else if (!string.IsNullOrEmpty(value)) { // was explicitly set in the document or object model - writer.WriteProperty(propertyName, value); + writer.WritePropertyName(propertyName); + writer.WriteRaw(value!); } } else { - if (exclusiveValue.HasValue) + if (!string.IsNullOrEmpty(exclusiveValue)) { // was explicitly set in a new document being downcast or object model - writer.WriteProperty(propertyName, exclusiveValue.Value); + writer.WritePropertyName(propertyName); + writer.WriteRaw(exclusiveValue!); writer.WriteProperty(isExclusivePropertyName, true); } - else if (value.HasValue) + else if (!string.IsNullOrEmpty(value)) { // came from parsing an old document, we're just mirroring the information - writer.WriteProperty(propertyName, value); + writer.WritePropertyName(propertyName); + writer.WriteRaw(value!); if (isExclusiveValue.HasValue) writer.WriteProperty(isExclusivePropertyName, isExclusiveValue.Value); } diff --git a/src/Microsoft.OpenApi/Models/References/OpenApiSchemaReference.cs b/src/Microsoft.OpenApi/Models/References/OpenApiSchemaReference.cs index e8ce0d907..fb817f56b 100644 --- a/src/Microsoft.OpenApi/Models/References/OpenApiSchemaReference.cs +++ b/src/Microsoft.OpenApi/Models/References/OpenApiSchemaReference.cs @@ -60,9 +60,9 @@ public string? Description /// public IDictionary? Definitions { get => Target?.Definitions; } /// - public decimal? ExclusiveMaximum { get => Target?.ExclusiveMaximum; } + public string? ExclusiveMaximum { get => Target?.ExclusiveMaximum; } /// - public decimal? ExclusiveMinimum { get => Target?.ExclusiveMinimum; } + public string? ExclusiveMinimum { get => Target?.ExclusiveMinimum; } /// public JsonSchemaType? Type { get => Target?.Type; } /// @@ -70,9 +70,9 @@ public string? Description /// public string? Format { get => Target?.Format; } /// - public decimal? Maximum { get => Target?.Maximum; } + public string? Maximum { get => Target?.Maximum; } /// - public decimal? Minimum { get => Target?.Minimum; } + public string? Minimum { get => Target?.Minimum; } /// public int? MaxLength { get => Target?.MaxLength; } /// diff --git a/src/Microsoft.OpenApi/Reader/V2/OpenApiHeaderDeserializer.cs b/src/Microsoft.OpenApi/Reader/V2/OpenApiHeaderDeserializer.cs index 4c156c2cc..9e9ff4b97 100644 --- a/src/Microsoft.OpenApi/Reader/V2/OpenApiHeaderDeserializer.cs +++ b/src/Microsoft.OpenApi/Reader/V2/OpenApiHeaderDeserializer.cs @@ -62,9 +62,9 @@ internal static partial class OpenApiV2Deserializer (o, n, _) => { var max = n.GetScalarValue(); - if (max != null) + if (!string.IsNullOrEmpty(max)) { - GetOrCreateSchema(o).Maximum = ParserHelper.ParseDecimalWithFallbackOnOverflow(max, decimal.MaxValue); + GetOrCreateSchema(o).Maximum = max; } } }, @@ -77,9 +77,9 @@ internal static partial class OpenApiV2Deserializer (o, n, _) => { var min = n.GetScalarValue(); - if (min != null) + if (!string.IsNullOrEmpty(min)) { - GetOrCreateSchema(o).Minimum = ParserHelper.ParseDecimalWithFallbackOnOverflow(min, decimal.MinValue); + GetOrCreateSchema(o).Minimum = min; } } }, diff --git a/src/Microsoft.OpenApi/Reader/V2/OpenApiParameterDeserializer.cs b/src/Microsoft.OpenApi/Reader/V2/OpenApiParameterDeserializer.cs index 61f3b49b1..f2fb7ce6b 100644 --- a/src/Microsoft.OpenApi/Reader/V2/OpenApiParameterDeserializer.cs +++ b/src/Microsoft.OpenApi/Reader/V2/OpenApiParameterDeserializer.cs @@ -101,9 +101,9 @@ internal static partial class OpenApiV2Deserializer (o, n, t) => { var min = n.GetScalarValue(); - if (min != null) + if (!string.IsNullOrEmpty(min)) { - GetOrCreateSchema(o).Minimum = ParserHelper.ParseDecimalWithFallbackOnOverflow(min, decimal.MinValue); + GetOrCreateSchema(o).Minimum = min; } } }, @@ -112,9 +112,9 @@ internal static partial class OpenApiV2Deserializer (o, n, t) => { var max = n.GetScalarValue(); - if (max != null) + if (!string.IsNullOrEmpty(max)) { - GetOrCreateSchema(o).Maximum = ParserHelper.ParseDecimalWithFallbackOnOverflow(max, decimal.MaxValue); + GetOrCreateSchema(o).Maximum = max; } } }, diff --git a/src/Microsoft.OpenApi/Reader/V2/OpenApiSchemaDeserializer.cs b/src/Microsoft.OpenApi/Reader/V2/OpenApiSchemaDeserializer.cs index 5597ed1b7..a3fb1153d 100644 --- a/src/Microsoft.OpenApi/Reader/V2/OpenApiSchemaDeserializer.cs +++ b/src/Microsoft.OpenApi/Reader/V2/OpenApiSchemaDeserializer.cs @@ -41,9 +41,9 @@ internal static partial class OpenApiV2Deserializer (o, n,_) => { var max = n.GetScalarValue(); - if (max != null) + if (!string.IsNullOrEmpty(max)) { - o.Maximum = ParserHelper.ParseDecimalWithFallbackOnOverflow(max, decimal.MaxValue); + o.Maximum = max; } } }, @@ -56,9 +56,9 @@ internal static partial class OpenApiV2Deserializer (o, n, _) => { var min = n.GetScalarValue(); - if (min != null) + if (!string.IsNullOrEmpty(min)) { - o.Minimum = ParserHelper.ParseDecimalWithFallbackOnOverflow(min, decimal.MinValue); + o.Minimum = min; } } }, diff --git a/src/Microsoft.OpenApi/Reader/V3/OpenApiSchemaDeserializer.cs b/src/Microsoft.OpenApi/Reader/V3/OpenApiSchemaDeserializer.cs index 464d6b1b5..85e418b7f 100644 --- a/src/Microsoft.OpenApi/Reader/V3/OpenApiSchemaDeserializer.cs +++ b/src/Microsoft.OpenApi/Reader/V3/OpenApiSchemaDeserializer.cs @@ -41,9 +41,9 @@ internal static partial class OpenApiV3Deserializer (o, n,_) => { var max = n.GetScalarValue(); - if (max != null) + if (!string.IsNullOrEmpty(max)) { - o.Maximum = ParserHelper.ParseDecimalWithFallbackOnOverflow(max, decimal.MaxValue); + o.Maximum = max; } } }, @@ -52,13 +52,13 @@ internal static partial class OpenApiV3Deserializer (o, n, _) => o.IsExclusiveMaximum = bool.Parse(n.GetScalarValue()) }, { - "minimum", + "minimum", (o, n, _) => { var min = n.GetScalarValue(); - if (min != null) + if (!string.IsNullOrEmpty(min)) { - o.Minimum = ParserHelper.ParseDecimalWithFallbackOnOverflow(min, decimal.MinValue); + o.Minimum = min; } } }, diff --git a/src/Microsoft.OpenApi/Reader/V31/OpenApiSchemaDeserializer.cs b/src/Microsoft.OpenApi/Reader/V31/OpenApiSchemaDeserializer.cs index 717a6e68f..020472c7a 100644 --- a/src/Microsoft.OpenApi/Reader/V31/OpenApiSchemaDeserializer.cs +++ b/src/Microsoft.OpenApi/Reader/V31/OpenApiSchemaDeserializer.cs @@ -65,30 +65,30 @@ internal static partial class OpenApiV31Deserializer (o, n,_) => { var max = n.GetScalarValue(); - if (max != null) + if (!string.IsNullOrEmpty(max)) { - o.Maximum = ParserHelper.ParseDecimalWithFallbackOnOverflow(max, decimal.MaxValue); + o.Maximum = max; } } }, { "exclusiveMaximum", - (o, n, _) => o.ExclusiveMaximum = ParserHelper.ParseDecimalWithFallbackOnOverflow(n.GetScalarValue(), decimal.MaxValue) + (o, n, _) => o.ExclusiveMaximum = n.GetScalarValue() }, { "minimum", (o, n, _) => { var min = n.GetScalarValue(); - if (min != null) + if (!string.IsNullOrEmpty(min)) { - o.Minimum = ParserHelper.ParseDecimalWithFallbackOnOverflow(min, decimal.MinValue); + o.Minimum = min; } } }, { "exclusiveMinimum", - (o, n, _) => o.ExclusiveMinimum = ParserHelper.ParseDecimalWithFallbackOnOverflow(n.GetScalarValue(), decimal.MaxValue) + (o, n, _) => o.ExclusiveMinimum = n.GetScalarValue() }, { "maxLength", From ff8b6504ce6dd3a0bb7c28c85039e6fccca5cb60 Mon Sep 17 00:00:00 2001 From: Maggiekimani1 Date: Tue, 8 Apr 2025 16:11:28 +0300 Subject: [PATCH 2/5] chore: clean up tests --- .../V2Tests/OpenApiDocumentTests.cs | 4 ++-- .../V31Tests/OpenApiSchemaTests.cs | 8 ++++---- .../V3Tests/OpenApiSchemaTests.cs | 6 +++--- .../Models/OpenApiOperationTests.cs | 16 ++++++++-------- .../Models/OpenApiSchemaTests.cs | 8 ++++---- 5 files changed, 21 insertions(+), 21 deletions(-) diff --git a/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiDocumentTests.cs b/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiDocumentTests.cs index f76e3311c..6bf41959c 100644 --- a/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiDocumentTests.cs +++ b/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiDocumentTests.cs @@ -62,8 +62,8 @@ public void ParseDocumentWithDifferentCultureShouldSucceed(string culture) var expectedPropertySchema = new OpenApiSchema() { Type = JsonSchemaType.Number, - Minimum = (decimal)100.54, - ExclusiveMaximum = (decimal)60000000.35, + Minimum = "100.54", + ExclusiveMaximum = "60000000.35", }; Assert.Equivalent(expectedPropertySchema, samplePropertySchema); diff --git a/test/Microsoft.OpenApi.Readers.Tests/V31Tests/OpenApiSchemaTests.cs b/test/Microsoft.OpenApi.Readers.Tests/V31Tests/OpenApiSchemaTests.cs index f7b219f97..838ecbff2 100644 --- a/test/Microsoft.OpenApi.Readers.Tests/V31Tests/OpenApiSchemaTests.cs +++ b/test/Microsoft.OpenApi.Readers.Tests/V31Tests/OpenApiSchemaTests.cs @@ -239,22 +239,22 @@ public async Task ParseAdvancedV31SchemaShouldSucceed() ["six"] = new OpenApiSchema() { Description = "exclusiveMinimum true", - ExclusiveMinimum = 10 + ExclusiveMinimum = "10" }, ["seven"] = new OpenApiSchema() { Description = "exclusiveMinimum false", - Minimum = 10 + Minimum = "10" }, ["eight"] = new OpenApiSchema() { Description = "exclusiveMaximum true", - ExclusiveMaximum = 20 + ExclusiveMaximum = "20" }, ["nine"] = new OpenApiSchema() { Description = "exclusiveMaximum false", - Maximum = 20 + Maximum = "20" }, ["ten"] = new OpenApiSchema() { diff --git a/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiSchemaTests.cs b/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiSchemaTests.cs index cdc80e603..0ea179f56 100644 --- a/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiSchemaTests.cs +++ b/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiSchemaTests.cs @@ -250,8 +250,8 @@ public async Task ParseBasicSchemaWithReferenceShouldSucceed() ["code"] = new OpenApiSchema() { Type = JsonSchemaType.Integer, - Minimum = 100, - Maximum = 600 + Minimum = "100", + Maximum = "600" }, ["message"] = new OpenApiSchema() { @@ -369,7 +369,7 @@ public async Task ParseAdvancedSchemaWithReferenceShouldSucceed() Format = "int32", Description = "the size of the pack the dog is from", Default = 0, - Minimum = 0 + Minimum = "0" } } } diff --git a/test/Microsoft.OpenApi.Tests/Models/OpenApiOperationTests.cs b/test/Microsoft.OpenApi.Tests/Models/OpenApiOperationTests.cs index 33730484b..d7315d5ab 100644 --- a/test/Microsoft.OpenApi.Tests/Models/OpenApiOperationTests.cs +++ b/test/Microsoft.OpenApi.Tests/Models/OpenApiOperationTests.cs @@ -51,8 +51,8 @@ public class OpenApiOperationTests Schema = new OpenApiSchema() { Type = JsonSchemaType.Number, - Minimum = 5, - Maximum = 10 + Minimum = "5", + Maximum = "10" } } } @@ -69,8 +69,8 @@ public class OpenApiOperationTests Schema = new OpenApiSchema() { Type = JsonSchemaType.Number, - Minimum = 5, - Maximum = 10 + Minimum = "5", + Maximum = "10" } } } @@ -125,8 +125,8 @@ public class OpenApiOperationTests Schema = new OpenApiSchema() { Type = JsonSchemaType.Number, - Minimum = 5, - Maximum = 10 + Minimum = "5", + Maximum = "10" } } } @@ -143,8 +143,8 @@ public class OpenApiOperationTests Schema = new OpenApiSchema() { Type = JsonSchemaType.Number, - Minimum = 5, - Maximum = 10 + Minimum = "5", + Maximum = "10" } } } diff --git a/test/Microsoft.OpenApi.Tests/Models/OpenApiSchemaTests.cs b/test/Microsoft.OpenApi.Tests/Models/OpenApiSchemaTests.cs index 9fc3dcebb..bc0056c5a 100644 --- a/test/Microsoft.OpenApi.Tests/Models/OpenApiSchemaTests.cs +++ b/test/Microsoft.OpenApi.Tests/Models/OpenApiSchemaTests.cs @@ -29,8 +29,8 @@ public class OpenApiSchemaTests { Title = "title1", MultipleOf = 3, - Maximum = 42, - ExclusiveMinimum = 10, + Maximum = "42", + ExclusiveMinimum = "10", Default = 15, Type = JsonSchemaType.Integer | JsonSchemaType.Null, @@ -146,8 +146,8 @@ public class OpenApiSchemaTests { Title = "title1", MultipleOf = 3, - Maximum = 42, - ExclusiveMinimum = 10, + Maximum = "42", + ExclusiveMinimum = "10", Default = 15, Type = JsonSchemaType.Integer | JsonSchemaType.Null, From 601064b2ec1284b15120f7ff7fcdba24f0d666a1 Mon Sep 17 00:00:00 2001 From: Maggiekimani1 Date: Tue, 8 Apr 2025 16:17:12 +0300 Subject: [PATCH 3/5] chore: update public API --- .../PublicApi/PublicApi.approved.txt | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/test/Microsoft.OpenApi.Tests/PublicApi/PublicApi.approved.txt b/test/Microsoft.OpenApi.Tests/PublicApi/PublicApi.approved.txt index 755a9e17e..140cfd46c 100644 --- a/test/Microsoft.OpenApi.Tests/PublicApi/PublicApi.approved.txt +++ b/test/Microsoft.OpenApi.Tests/PublicApi/PublicApi.approved.txt @@ -429,8 +429,8 @@ namespace Microsoft.OpenApi.Models.Interfaces System.Collections.Generic.IList? Enum { get; } System.Text.Json.Nodes.JsonNode? Example { get; } System.Collections.Generic.IList? Examples { get; } - decimal? ExclusiveMaximum { get; } - decimal? ExclusiveMinimum { get; } + string? ExclusiveMaximum { get; } + string? ExclusiveMinimum { get; } Microsoft.OpenApi.Models.OpenApiExternalDocs? ExternalDocs { get; } string? Format { get; } string? Id { get; } @@ -438,11 +438,11 @@ namespace Microsoft.OpenApi.Models.Interfaces int? MaxItems { get; } int? MaxLength { get; } int? MaxProperties { get; } - decimal? Maximum { get; } + string? Maximum { get; } int? MinItems { get; } int? MinLength { get; } int? MinProperties { get; } - decimal? Minimum { get; } + string? Minimum { get; } decimal? MultipleOf { get; } Microsoft.OpenApi.Models.Interfaces.IOpenApiSchema? Not { get; } System.Collections.Generic.IList? OneOf { get; } @@ -1031,8 +1031,8 @@ namespace Microsoft.OpenApi.Models public System.Collections.Generic.IList? Enum { get; set; } public System.Text.Json.Nodes.JsonNode? Example { get; set; } public System.Collections.Generic.IList? Examples { get; set; } - public decimal? ExclusiveMaximum { get; set; } - public decimal? ExclusiveMinimum { get; set; } + public string? ExclusiveMaximum { get; set; } + public string? ExclusiveMinimum { get; set; } public System.Collections.Generic.IDictionary? Extensions { get; set; } public Microsoft.OpenApi.Models.OpenApiExternalDocs? ExternalDocs { get; set; } public string? Format { get; set; } @@ -1041,11 +1041,11 @@ namespace Microsoft.OpenApi.Models public int? MaxItems { get; set; } public int? MaxLength { get; set; } public int? MaxProperties { get; set; } - public decimal? Maximum { get; set; } + public string? Maximum { get; set; } public int? MinItems { get; set; } public int? MinLength { get; set; } public int? MinProperties { get; set; } - public decimal? Minimum { get; set; } + public string? Minimum { get; set; } public decimal? MultipleOf { get; set; } public Microsoft.OpenApi.Models.Interfaces.IOpenApiSchema? Not { get; set; } public System.Collections.Generic.IList? OneOf { get; set; } @@ -1363,8 +1363,8 @@ namespace Microsoft.OpenApi.Models.References public System.Collections.Generic.IList? Enum { get; } public System.Text.Json.Nodes.JsonNode? Example { get; } public System.Collections.Generic.IList? Examples { get; } - public decimal? ExclusiveMaximum { get; } - public decimal? ExclusiveMinimum { get; } + public string? ExclusiveMaximum { get; } + public string? ExclusiveMinimum { get; } public System.Collections.Generic.IDictionary? Extensions { get; } public Microsoft.OpenApi.Models.OpenApiExternalDocs? ExternalDocs { get; } public string? Format { get; } @@ -1373,11 +1373,11 @@ namespace Microsoft.OpenApi.Models.References public int? MaxItems { get; } public int? MaxLength { get; } public int? MaxProperties { get; } - public decimal? Maximum { get; } + public string? Maximum { get; } public int? MinItems { get; } public int? MinLength { get; } public int? MinProperties { get; } - public decimal? Minimum { get; } + public string? Minimum { get; } public decimal? MultipleOf { get; } public Microsoft.OpenApi.Models.Interfaces.IOpenApiSchema? Not { get; } public System.Collections.Generic.IList? OneOf { get; } From f96ed12b1dc27e35c6c3644633eeed3251f2c307 Mon Sep 17 00:00:00 2001 From: Maggiekimani1 Date: Tue, 8 Apr 2025 16:25:15 +0300 Subject: [PATCH 4/5] chore: remove bang operators for consistency --- src/Microsoft.OpenApi/Models/OpenApiSchema.cs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Microsoft.OpenApi/Models/OpenApiSchema.cs b/src/Microsoft.OpenApi/Models/OpenApiSchema.cs index e3fcbfcaa..8c1f5d596 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiSchema.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiSchema.cs @@ -344,33 +344,33 @@ private static void SerializeBounds(IOpenApiWriter writer, OpenApiSpecVersion ve writer.WritePropertyName(exclusivePropertyName); writer.WriteRaw(exclusiveValue); } - else if (isExclusiveValue == true && !string.IsNullOrEmpty(value)) + else if (isExclusiveValue == true && !string.IsNullOrEmpty(value) && value is not null) { // came from parsing an old document writer.WritePropertyName(exclusivePropertyName); - writer.WriteRaw(value!); + writer.WriteRaw(value); } - else if (!string.IsNullOrEmpty(value)) + else if (!string.IsNullOrEmpty(value) && value is not null) { // was explicitly set in the document or object model writer.WritePropertyName(propertyName); - writer.WriteRaw(value!); + writer.WriteRaw(value); } } else { - if (!string.IsNullOrEmpty(exclusiveValue)) + if (!string.IsNullOrEmpty(exclusiveValue) && exclusiveValue is not null) { // was explicitly set in a new document being downcast or object model writer.WritePropertyName(propertyName); - writer.WriteRaw(exclusiveValue!); + writer.WriteRaw(exclusiveValue); writer.WriteProperty(isExclusivePropertyName, true); } - else if (!string.IsNullOrEmpty(value)) + else if (!string.IsNullOrEmpty(value) && value is not null) { // came from parsing an old document, we're just mirroring the information writer.WritePropertyName(propertyName); - writer.WriteRaw(value!); + writer.WriteRaw(value); if (isExclusiveValue.HasValue) writer.WriteProperty(isExclusivePropertyName, isExclusiveValue.Value); } From 5fa3bfb63b08949843af45a2b7c1451b9c6cd75d Mon Sep 17 00:00:00 2001 From: Maggiekimani1 Date: Tue, 8 Apr 2025 16:53:48 +0300 Subject: [PATCH 5/5] chore: remove depracated class and tests --- .../Reader/ParseNodes/ParserHelper.cs | 35 ------------------- .../ParseNodes/ParserHelperTests.cs | 25 ------------- 2 files changed, 60 deletions(-) delete mode 100644 src/Microsoft.OpenApi/Reader/ParseNodes/ParserHelper.cs delete mode 100644 test/Microsoft.OpenApi.Readers.Tests/ParseNodes/ParserHelperTests.cs diff --git a/src/Microsoft.OpenApi/Reader/ParseNodes/ParserHelper.cs b/src/Microsoft.OpenApi/Reader/ParseNodes/ParserHelper.cs deleted file mode 100644 index 030572f68..000000000 --- a/src/Microsoft.OpenApi/Reader/ParseNodes/ParserHelper.cs +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT license. - -using System; -using System.Globalization; - -namespace Microsoft.OpenApi.Reader.ParseNodes -{ - /// - /// Useful tools to parse data - /// - internal class ParserHelper - { - /// - /// Parses decimal in invariant culture. - /// If the decimal is too big or small, it returns the default value - /// - /// Note: sometimes developers put Double.MaxValue or Long.MaxValue as min/max values for numbers in json schema even if their numbers are not expected to be that big/small. - /// As we have already released the library with Decimal type for Max/Min, let's not introduce the breaking change and just fallback to Decimal.Max / Min. This should satisfy almost every scenario. - /// We can revisit this if somebody really needs to have double or long here. - /// - /// - public static decimal ParseDecimalWithFallbackOnOverflow(string value, decimal defaultValue) - { - try - { - return decimal.Parse(value, NumberStyles.Float, CultureInfo.InvariantCulture); - } - catch (OverflowException) - { - return defaultValue; - } - } - } -} diff --git a/test/Microsoft.OpenApi.Readers.Tests/ParseNodes/ParserHelperTests.cs b/test/Microsoft.OpenApi.Readers.Tests/ParseNodes/ParserHelperTests.cs deleted file mode 100644 index 4e3500d6b..000000000 --- a/test/Microsoft.OpenApi.Readers.Tests/ParseNodes/ParserHelperTests.cs +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT license. - -using System.Globalization; -using Microsoft.OpenApi.Reader.ParseNodes; -using Xunit; - -namespace Microsoft.OpenApi.Readers.Tests.ParseNodes -{ - [Collection("DefaultSettings")] - public class ParserHelperTests - { - [Fact] - public void ParseDecimalWithFallbackOnOverflow_ReturnsParsedValue() - { - Assert.Equal(23434, ParserHelper.ParseDecimalWithFallbackOnOverflow("23434", 10)); - } - - [Fact] - public void ParseDecimalWithFallbackOnOverflow_Overflows_ReturnsFallback() - { - Assert.Equal(10, ParserHelper.ParseDecimalWithFallbackOnOverflow(double.MaxValue.ToString(CultureInfo.InvariantCulture), 10)); - } - } -}