Skip to content

Handle number overflow during parsing of min/max values - #1480

Merged
Vincent Biret (baywet) merged 1 commit into
microsoft:vnextfrom
Robulane:users/robulane/DontCrash
Nov 22, 2023
Merged

Handle number overflow during parsing of min/max values#1480
Vincent Biret (baywet) merged 1 commit into
microsoft:vnextfrom
Robulane:users/robulane/DontCrash

Conversation

@Robulane

Copy link
Copy Markdown

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, IDictionary2 fixedFields, IDictionary2 patternFields)
at Microsoft.OpenApi.Readers.V2.OpenApiV2Deserializer.LoadSchema(ParseNode node)
at Microsoft.OpenApi.Readers.ParseNodes.MapNode.<>c__DisplayClass6_01.<CreateMap>b__0(KeyValuePair2 n)
at System.Linq.Enumerable.SelectEnumerableIterator2.MoveNext() at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerable1 source, Func2 keySelector, Func2 elementSelector, IEqualityComparer1 comparer) at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerable1 source, Func2 keySelector, Func2 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, IDictionary2 fixedFields, IDictionary2 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)

@baywetVincent Biret (baywet) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the contribution!

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@Robulane@baywet@romanbulanenko