Skip to content

Commit 69cf2c5

Browse files
authored
Merge pull request #84 from Microsoft/dm/version-parsing
Change Info.Version to string to support various date formats
2 parents edd878b + 9367844 commit 69cf2c5

File tree

5 files changed

+23
-5
lines changed

5 files changed

+23
-5
lines changed

src/Microsoft.OpenApi.Readers/V2/OpenApiInfoDeserializer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ internal static partial class OpenApiV2Deserializer
5252
{
5353
"version", (o, n) =>
5454
{
55-
o.Version = new Version(n.GetScalarValue());
55+
o.Version = n.GetScalarValue();
5656
}
5757
}
5858
};

src/Microsoft.OpenApi.Readers/V3/OpenApiInfoDeserializer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ internal static partial class OpenApiV3Deserializer
2727
{
2828
"version", (o, n) =>
2929
{
30-
o.Version = new Version(n.GetScalarValue());
30+
o.Version = n.GetScalarValue();
3131
}
3232
},
3333
{

src/Microsoft.OpenApi/Models/OpenApiInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public class OpenApiInfo : OpenApiElement, IOpenApiExtension
2929
/// <summary>
3030
/// REQUIRED. The version of the OpenAPI document.
3131
/// </summary>
32-
public Version Version { get; set; } = new Version(1, 0);
32+
public string Version { get; set; } = "1.0";
3333

3434
/// <summary>
3535
/// A URL to the Terms of Service for the API. MUST be in the format of a URL.

test/Microsoft.OpenApi.Tests/ExampleTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public void WriteResponseExample()
2323
Info = new OpenApiInfo()
2424
{
2525
Title = "test",
26-
Version = new Version(1, 0)
26+
Version = "1.0"
2727
}
2828
};
2929

test/Microsoft.OpenApi.Tests/Models/OpenApiInfoTests.cs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public class OpenApiInfoTests
2222
TermsOfService = new Uri("http://example.com/terms/"),
2323
Contact = OpenApiContactTests.AdvanceContact,
2424
License = OpenApiLicenseTests.AdvanceLicense,
25-
Version = new Version(1, 1, 1),
25+
Version = "1.1.1",
2626
Extensions = new Dictionary<string, IOpenApiAny>
2727
{
2828
{ "x-updated", new OpenApiString("metadata") }
@@ -166,5 +166,23 @@ public void SerializeAdvanceInfoAsYamlWorks(OpenApiSpecVersion version, string e
166166
expected = expected.MakeLineBreaksEnvironmentNeutral();
167167
actual.Should().Be(expected);
168168
}
169+
170+
[Fact]
171+
public void InfoVersionShouldAcceptDateStyledAsVersions()
172+
{
173+
var info = new OpenApiInfo() {
174+
Version = "2017-03-01"
175+
};
176+
177+
var actual = info.Serialize(OpenApiSpecVersion.OpenApi3_0, OpenApiFormat.Yaml).MakeLineBreaksEnvironmentNeutral();
178+
179+
var expected =
180+
@"title: Default Title
181+
version: 2017-03-01"
182+
.MakeLineBreaksEnvironmentNeutral();
183+
184+
actual.Should().Be(expected);
185+
186+
}
169187
}
170188
}

0 commit comments

Comments
 (0)