Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
22 changes: 10 additions & 12 deletions src/Microsoft.OpenApi.Readers/ParseNodes/ValueNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// Licensed under the MIT license.

using System;
using System.Globalization;
using Microsoft.OpenApi.Any;
using Microsoft.OpenApi.Exceptions;
using Microsoft.OpenApi.Readers.Exceptions;
using SharpYaml.Serialization;

Expand Down Expand Up @@ -52,28 +52,26 @@ public override IOpenApiAny CreateAny()
return new OpenApiBoolean(false);
}

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

if (long.TryParse(value, out var longValue))
if (long.TryParse(value, NumberStyles.Integer, CultureInfo.InvariantCulture, out var longValue))
{
return
new OpenApiLong(
longValue);
return new OpenApiLong(longValue);
}

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

if (DateTimeOffset.TryParse(value, out var datetimeValue))
if (DateTimeOffset.TryParse(value, CultureInfo.InvariantCulture, DateTimeStyles.None, out var dateTimeValue))
{
return new OpenApiDateTime(datetimeValue);
return new OpenApiDateTime(dateTimeValue);
}

// if we can't identify the type of value, return it as string.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
using System.Globalization;
using System.Threading;
using FluentAssertions;
using Microsoft.OpenApi.Any;
using Microsoft.OpenApi.Exceptions;
using Microsoft.OpenApi.Models;
using Microsoft.OpenApi.Readers.Exceptions;
using Xunit;

namespace Microsoft.OpenApi.Readers.Tests.V2Tests
Expand Down Expand Up @@ -86,6 +86,7 @@ public void ParseDocumentWithDifferentCultureShouldSucceed(string culture)
info:
title: Simple Document
version: 0.9.1
x-extension: 2.335
definitions:
sampleSchema:
type: object
Expand All @@ -105,7 +106,11 @@ public void ParseDocumentWithDifferentCultureShouldSucceed(string culture)
Info = new OpenApiInfo
{
Title = "Simple Document",
Version = "0.9.1"
Version = "0.9.1",
Extensions =
{
["x-extension"] = new OpenApiDouble(2.335)
}
},
Components = new OpenApiComponents()
{
Expand Down