Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/Microsoft.OpenApi/Models/Interfaces/IOpenApiSchema.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ public interface IOpenApiSchema : IOpenApiDescribedElement, IOpenApiReadOnlyExte
/// <summary>
/// Follow JSON Schema definition: https://tools.ietf.org/html/draft-fge-json-schema-validation-00
/// </summary>
public decimal? ExclusiveMaximum { get; }
public string? ExclusiveMaximum { get; }

/// <summary>
/// Follow JSON Schema definition: https://tools.ietf.org/html/draft-fge-json-schema-validation-00
/// </summary>
public decimal? ExclusiveMinimum { get; }
public string? ExclusiveMinimum { get; }

/// <summary>
/// Follow JSON Schema definition: https://tools.ietf.org/html/draft-fge-json-schema-validation-00
Expand All @@ -84,12 +84,12 @@ public interface IOpenApiSchema : IOpenApiDescribedElement, IOpenApiReadOnlyExte
/// <summary>
/// Follow JSON Schema definition: https://tools.ietf.org/html/draft-fge-json-schema-validation-00
/// </summary>
public decimal? Maximum { get; }
public string? Maximum { get; }

/// <summary>
/// Follow JSON Schema definition: https://tools.ietf.org/html/draft-fge-json-schema-validation-00
/// </summary>
public decimal? Minimum { get; }
public string? Minimum { get; }

/// <summary>
/// Follow JSON Schema definition: https://tools.ietf.org/html/draft-fge-json-schema-validation-00
Expand Down
51 changes: 28 additions & 23 deletions src/Microsoft.OpenApi/Models/OpenApiSchema.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,17 @@
/// <inheritdoc />
public IDictionary<string, IOpenApiSchema>? Definitions { get; set; }

private decimal? _exclusiveMaximum;
private string? _exclusiveMaximum;
/// <inheritdoc />
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;
}
Expand All @@ -73,17 +73,17 @@
/// DO NOT CHANGE THE VISIBILITY OF THIS PROPERTY TO PUBLIC
internal bool? IsExclusiveMaximum { get; set; }

private decimal? _exclusiveMinimum;
private string? _exclusiveMinimum;
/// <inheritdoc />
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;
}
Expand Down Expand Up @@ -114,9 +114,9 @@
/// <inheritdoc />
public string? Description { get; set; }

private decimal? _maximum;
private string? _maximum;
/// <inheritdoc />
public decimal? Maximum
public string? Maximum
{
get
{
Expand All @@ -132,10 +132,10 @@
}
}

private decimal? _minimum;
private string? _minimum;

/// <inheritdoc />
public decimal? Minimum
public string? Minimum
{
get
{
Expand Down Expand Up @@ -262,7 +262,7 @@
/// Initializes a copy of <see cref="IOpenApiSchema"/> object
/// </summary>
/// <param name="schema">The schema object to copy from.</param>
internal OpenApiSchema(IOpenApiSchema schema)

Check warning on line 265 in src/Microsoft.OpenApi/Models/OpenApiSchema.cs

View workflow job for this annotation

GitHub Actions / Build

Refactor this constructor to reduce its Cognitive Complexity from 20 to the 15 allowed. (https://rules.sonarsource.com/csharp/RSPEC-3776)
{
Utils.CheckArgumentNull(schema);
Title = schema.Title ?? Title;
Expand Down Expand Up @@ -334,38 +334,43 @@
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)

Check warning on line 337 in src/Microsoft.OpenApi/Models/OpenApiSchema.cs

View workflow job for this annotation

GitHub Actions / Build

Refactor this method to reduce its Cognitive Complexity from 17 to the 15 allowed. (https://rules.sonarsource.com/csharp/RSPEC-3776)

Check warning on line 337 in src/Microsoft.OpenApi/Models/OpenApiSchema.cs

View workflow job for this annotation

GitHub Actions / Build

Method has 8 parameters, which is greater than the 7 authorized. (https://rules.sonarsource.com/csharp/RSPEC-107)
{
if (version >= OpenApiSpecVersion.OpenApi3_1)
{
if (exclusiveValue.HasValue)
if (!string.IsNullOrEmpty(exclusiveValue) && exclusiveValue is not null)

Check warning on line 341 in src/Microsoft.OpenApi/Models/OpenApiSchema.cs

View workflow job for this annotation

GitHub Actions / Build

Change this condition so that it does not always evaluate to 'True'. (https://rules.sonarsource.com/csharp/RSPEC-2589)
{
// 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) && value is not null)
{
// 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) && value is not null)
{
// 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) && exclusiveValue is not null)
{
// 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) && value is not null)
{
// 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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,19 +60,19 @@ public string? Description
/// <inheritdoc/>
public IDictionary<string, IOpenApiSchema>? Definitions { get => Target?.Definitions; }
/// <inheritdoc/>
public decimal? ExclusiveMaximum { get => Target?.ExclusiveMaximum; }
public string? ExclusiveMaximum { get => Target?.ExclusiveMaximum; }
/// <inheritdoc/>
public decimal? ExclusiveMinimum { get => Target?.ExclusiveMinimum; }
public string? ExclusiveMinimum { get => Target?.ExclusiveMinimum; }
/// <inheritdoc/>
public JsonSchemaType? Type { get => Target?.Type; }
/// <inheritdoc/>
public string? Const { get => Target?.Const; }
/// <inheritdoc/>
public string? Format { get => Target?.Format; }
/// <inheritdoc/>
public decimal? Maximum { get => Target?.Maximum; }
public string? Maximum { get => Target?.Maximum; }
/// <inheritdoc/>
public decimal? Minimum { get => Target?.Minimum; }
public string? Minimum { get => Target?.Minimum; }
/// <inheritdoc/>
public int? MaxLength { get => Target?.MaxLength; }
/// <inheritdoc/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
/// </summary>
internal static partial class OpenApiV2Deserializer
{
private static readonly FixedFieldMap<OpenApiHeader> _headerFixedFields = new()

Check warning on line 20 in src/Microsoft.OpenApi/Reader/V2/OpenApiHeaderDeserializer.cs

View workflow job for this annotation

GitHub Actions / Build

Refactor this field to reduce its Cognitive Complexity from 20 to the 15 allowed. (https://rules.sonarsource.com/csharp/RSPEC-3776)
{
{
"description",
Expand Down Expand Up @@ -62,9 +62,9 @@
(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;
}
}
},
Expand All @@ -77,9 +77,9 @@
(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;
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
/// </summary>
internal static partial class OpenApiV2Deserializer
{
private static readonly FixedFieldMap<OpenApiParameter> _parameterFixedFields =

Check warning on line 21 in src/Microsoft.OpenApi/Reader/V2/OpenApiParameterDeserializer.cs

View workflow job for this annotation

GitHub Actions / Build

Refactor this field to reduce its Cognitive Complexity from 23 to the 15 allowed. (https://rules.sonarsource.com/csharp/RSPEC-3776)
new()
{
{
Expand Down Expand Up @@ -101,9 +101,9 @@
(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;
}
}
},
Expand All @@ -112,9 +112,9 @@
(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;
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
/// </summary>
internal static partial class OpenApiV2Deserializer
{
private static readonly FixedFieldMap<OpenApiSchema> _openApiSchemaFixedFields = new()

Check warning on line 22 in src/Microsoft.OpenApi/Reader/V2/OpenApiSchemaDeserializer.cs

View workflow job for this annotation

GitHub Actions / Build

Refactor this field to reduce its Cognitive Complexity from 30 to the 15 allowed. (https://rules.sonarsource.com/csharp/RSPEC-3776)
{
{
"title",
Expand All @@ -41,9 +41,9 @@
(o, n,_) =>
{
var max = n.GetScalarValue();
if (max != null)
if (!string.IsNullOrEmpty(max))
{
o.Maximum = ParserHelper.ParseDecimalWithFallbackOnOverflow(max, decimal.MaxValue);
o.Maximum = max;
}
}
},
Expand All @@ -56,9 +56,9 @@
(o, n, _) =>
{
var min = n.GetScalarValue();
if (min != null)
if (!string.IsNullOrEmpty(min))
{
o.Minimum = ParserHelper.ParseDecimalWithFallbackOnOverflow(min, decimal.MinValue);
o.Minimum = min;
}
}
},
Expand Down
10 changes: 5 additions & 5 deletions src/Microsoft.OpenApi/Reader/V3/OpenApiSchemaDeserializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
/// </summary>
internal static partial class OpenApiV3Deserializer
{
private static readonly FixedFieldMap<OpenApiSchema> _openApiSchemaFixedFields = new()

Check warning on line 22 in src/Microsoft.OpenApi/Reader/V3/OpenApiSchemaDeserializer.cs

View workflow job for this annotation

GitHub Actions / Build

Refactor this field to reduce its Cognitive Complexity from 42 to the 15 allowed. (https://rules.sonarsource.com/csharp/RSPEC-3776)
{
{
"title",
Expand All @@ -41,9 +41,9 @@
(o, n,_) =>
{
var max = n.GetScalarValue();
if (max != null)
if (!string.IsNullOrEmpty(max))
{
o.Maximum = ParserHelper.ParseDecimalWithFallbackOnOverflow(max, decimal.MaxValue);
o.Maximum = max;
}
}
},
Expand All @@ -52,13 +52,13 @@
(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;
}
}
},
Expand Down
12 changes: 6 additions & 6 deletions src/Microsoft.OpenApi/Reader/V31/OpenApiSchemaDeserializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
{
internal static partial class OpenApiV31Deserializer
{
private static readonly FixedFieldMap<OpenApiSchema> _openApiSchemaFixedFields = new()

Check warning on line 18 in src/Microsoft.OpenApi/Reader/V31/OpenApiSchemaDeserializer.cs

View workflow job for this annotation

GitHub Actions / Build

Refactor this field to reduce its Cognitive Complexity from 52 to the 15 allowed. (https://rules.sonarsource.com/csharp/RSPEC-3776)
{
{
"title",
Expand Down Expand Up @@ -65,30 +65,30 @@
(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",
Expand Down Expand Up @@ -202,7 +202,7 @@
{
var list = n.CreateSimpleList((n2, p) => n2.GetScalarValue(), doc);
JsonSchemaType combinedType = 0;
foreach(var type in list)

Check warning on line 205 in src/Microsoft.OpenApi/Reader/V31/OpenApiSchemaDeserializer.cs

View workflow job for this annotation

GitHub Actions / Build

Loops should be simplified using the "Where" LINQ method (https://rules.sonarsource.com/csharp/RSPEC-3267)
{
if (type is not null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down Expand Up @@ -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"
}
}
}
Expand Down
Loading