Handle number overflow during parsing of min/max values #1480
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Sometimes developers put Double.MaxValue or Long.MaxValue asmax 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 in case of overflow. This should satisfy almost every scenario. We can revisit this if somebody really needs to have double or long here.
Fixing this exception stacktrace
ExceptionType: System.OverflowException
ExceptionMessage: Value was either too large or too small for a Decimal.
InnerExceptionType:
InnerExceptionMessage:
StackTrace:
at System.Number.ThrowOverflowOrFormatException(ParsingStatus status, TypeCode type)
at System.Decimal.Parse(String s, NumberStyles style, IFormatProvider provider)
at Microsoft.OpenApi.Readers.V2.OpenApiV2Deserializer.<>c.<.cctor>b__83_141(OpenApiSchema o, ParseNode n)
at Microsoft.OpenApi.Readers.ParseNodes.PropertyNode.ParseField[T](T parentInstance, IDictionary
2 fixedFields, IDictionary
2 patternFields)at Microsoft.OpenApi.Readers.V2.OpenApiV2Deserializer.LoadSchema(ParseNode node)
at Microsoft.OpenApi.Readers.ParseNodes.MapNode.<>c__DisplayClass6_0
1.<CreateMap>b__0(KeyValuePair
2 n)at System.Linq.Enumerable.SelectEnumerableIterator
2.MoveNext() at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerable
1 source, Func2 keySelector, Func
2 elementSelector, IEqualityComparer1 comparer) at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerable
1 source, Func2 keySelector, Func
2 elementSelector)at Microsoft.OpenApi.Readers.V2.OpenApiV2Deserializer.<>c.<.cctor>b__83_158(OpenApiSchema o, ParseNode n)
at Microsoft.OpenApi.Readers.ParseNodes.PropertyNode.ParseField[T](T parentInstance, IDictionary
2 fixedFields, IDictionary
2 patternFields)at Microsoft.OpenApi.Readers.V2.OpenApiV2Deserializer.LoadSchema(ParseNode node)
at Microsoft.OpenApi.Readers.V2.OpenApiV2VersionService.LoadElement[T](ParseNode node)
at Microsoft.OpenApi.Readers.ParsingContext.ParseFragment[T](YamlDocument yamlDocument, OpenApiSpecVersion version)
at Microsoft.OpenApi.Readers.OpenApiYamlDocumentReader.ReadFragment[T](YamlDocument input, OpenApiSpecVersion version, OpenApiDiagnostic& diagnostic)
at Microsoft.OpenApi.Readers.OpenApiTextReaderReader.ReadFragment[T](TextReader input, OpenApiSpecVersion version, OpenApiDiagnostic& diagnostic)
at Microsoft.OpenApi.Readers.OpenApiStringReader.ReadFragment[T](String input, OpenApiSpecVersion version, OpenApiDiagnostic& diagnostic)