Skip to content

Commit 1b353c6

Browse files
Merge branch 'bugfix#319-V2Deserializer-should-handle-invalid-host-value-gracefully' of https://github.com/senthilkumarmohan/OpenAPI.NET into bugfix#319-V2Deserializer-should-handle-invalid-host-value-gracefully
2 parents 18babce + 78c8e65 commit 1b353c6

File tree

4 files changed

+20
-17
lines changed

4 files changed

+20
-17
lines changed

src/Microsoft.OpenApi.Readers/Microsoft.OpenApi.Readers.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
33
<TargetFrameworks>net46; netstandard2.0</TargetFrameworks>
44
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
@@ -10,7 +10,7 @@
1010
<Company>Microsoft</Company>
1111
<Title>Microsoft.OpenApi.Readers</Title>
1212
<PackageId>Microsoft.OpenApi.Readers</PackageId>
13-
<Version>1.1.0</Version>
13+
<Version>1.1.1</Version>
1414
<Description>OpenAPI.NET Readers for JSON and YAML documents</Description>
1515
<Copyright>© Microsoft Corporation. All rights reserved.</Copyright>
1616
<PackageTags>OpenAPI .NET</PackageTags>

src/Microsoft.OpenApi.Readers/ParseNodes/ValueNode.cs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
// Licensed under the MIT license.
33

44
using System;
5+
using System.Globalization;
56
using Microsoft.OpenApi.Any;
6-
using Microsoft.OpenApi.Exceptions;
77
using Microsoft.OpenApi.Readers.Exceptions;
88
using SharpYaml.Serialization;
99

@@ -52,28 +52,26 @@ public override IOpenApiAny CreateAny()
5252
return new OpenApiBoolean(false);
5353
}
5454

55-
if (int.TryParse(value, out var intValue))
55+
// The NumberStyles below are the default ones based on
56+
// https://docs.microsoft.com/en-us/dotnet/api/?view=netframework-4.7.2
57+
if (int.TryParse(value, NumberStyles.Integer, CultureInfo.InvariantCulture, out var intValue))
5658
{
5759
return new OpenApiInteger(intValue);
5860
}
5961

60-
if (long.TryParse(value, out var longValue))
62+
if (long.TryParse(value, NumberStyles.Integer, CultureInfo.InvariantCulture, out var longValue))
6163
{
62-
return
63-
new OpenApiLong(
64-
longValue);
64+
return new OpenApiLong(longValue);
6565
}
6666

67-
if (double.TryParse(value, out var dblValue))
67+
if (double.TryParse(value, NumberStyles.Float | NumberStyles.AllowThousands, CultureInfo.InvariantCulture, out var doubleValue))
6868
{
69-
return
70-
new OpenApiDouble(
71-
dblValue); // Note(darrmi): This may be better as decimal. Further investigation required.
69+
return new OpenApiDouble(doubleValue);
7270
}
7371

74-
if (DateTimeOffset.TryParse(value, out var datetimeValue))
72+
if (DateTimeOffset.TryParse(value, CultureInfo.InvariantCulture, DateTimeStyles.None, out var dateTimeValue))
7573
{
76-
return new OpenApiDateTime(datetimeValue);
74+
return new OpenApiDateTime(dateTimeValue);
7775
}
7876

7977
// if we can't identify the type of value, return it as string.

src/Microsoft.OpenApi/Microsoft.OpenApi.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<Company>Microsoft</Company>
1111
<Title>Microsoft.OpenApi</Title>
1212
<PackageId>Microsoft.OpenApi</PackageId>
13-
<Version>1.1.0</Version>
13+
<Version>1.1.1</Version>
1414
<Description>.NET models with JSON and YAML writers for OpenAPI specification</Description>
1515
<Copyright>© Microsoft Corporation. All rights reserved.</Copyright>
1616
<PackageTags>OpenAPI .NET</PackageTags>

test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiDocumentTests.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
using System.Globalization;
66
using System.Threading;
77
using FluentAssertions;
8+
using Microsoft.OpenApi.Any;
89
using Microsoft.OpenApi.Exceptions;
910
using Microsoft.OpenApi.Models;
10-
using Microsoft.OpenApi.Readers.Exceptions;
1111
using Xunit;
1212

1313
namespace Microsoft.OpenApi.Readers.Tests.V2Tests
@@ -86,6 +86,7 @@ public void ParseDocumentWithDifferentCultureShouldSucceed(string culture)
8686
info:
8787
title: Simple Document
8888
version: 0.9.1
89+
x-extension: 2.335
8990
definitions:
9091
sampleSchema:
9192
type: object
@@ -105,7 +106,11 @@ public void ParseDocumentWithDifferentCultureShouldSucceed(string culture)
105106
Info = new OpenApiInfo
106107
{
107108
Title = "Simple Document",
108-
Version = "0.9.1"
109+
Version = "0.9.1",
110+
Extensions =
111+
{
112+
["x-extension"] = new OpenApiDouble(2.335)
113+
}
109114
},
110115
Components = new OpenApiComponents()
111116
{

0 commit comments

Comments
 (0)