Skip to content

Commit 793abf8

Browse files
irvinesundaybaywet
andauthored
Uses SemVerVersion in place of Version to Get or Set the metadata version in the OpenAPI document (#360)
* Add new convert setting property SemVerVersion Declare Version property obsolete and update setter to set the new SemVerVersion * Update tests * Add obsolete attribute * Update release notes * Update src/Microsoft.OpenApi.OData.Reader/OpenApiConvertSettings.cs Co-authored-by: Vincent Biret <[email protected]> * Update src/Microsoft.OpenApi.OData.Reader/OpenApiConvertSettings.cs Co-authored-by: Vincent Biret <[email protected]> * Update src/Microsoft.OpenApi.OData.Reader/OpenApiConvertSettings.cs Co-authored-by: Vincent Biret <[email protected]> * Update src/Microsoft.OpenApi.OData.Reader/OpenApiConvertSettings.cs Co-authored-by: Vincent Biret <[email protected]> * PR review suggestions * - removes version cloning --------- Co-authored-by: Vincent Biret <[email protected]>
1 parent d0ec4f3 commit 793abf8

19 files changed

+38
-22
lines changed

src/Microsoft.OpenApi.OData.Reader/Generator/OpenApiInfoGenerator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ private static string GetVersion(this ODataContext context)
7575
// If no Core.SchemaVersion is present, a default version has to be provided as this is a required OpenAPI field.
7676
// TODO: https://github.com/Microsoft/OpenAPI.NET.OData/issues/2
7777

78-
return context.Settings.Version.ToString();
78+
return context.Settings.SemVerVersion;
7979
}
8080

8181
private static string GetDescription(this ODataContext context)

src/Microsoft.OpenApi.OData.Reader/Microsoft.OpenAPI.OData.Reader.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<TargetFrameworks>netstandard2.0</TargetFrameworks>
1616
<PackageId>Microsoft.OpenApi.OData</PackageId>
1717
<SignAssembly>true</SignAssembly>
18-
<Version>1.3.0-preview3</Version>
18+
<Version>1.3.0-preview4</Version>
1919
<Description>This package contains the codes you need to convert OData CSDL to Open API Document of Model.</Description>
2020
<Copyright>© Microsoft Corporation. All rights reserved.</Copyright>
2121
<PackageTags>Microsoft OpenApi OData EDM</PackageTags>
@@ -27,6 +27,7 @@
2727
- Strips namespace prefix from operation segments and aliases type cast segments #348
2828
- Return response status code 2XX for PUT operations of stream properties when UseSuccessStatusCodeRange is enabled #310
2929
- Adds $value segment to paths with entity types with base types with HasStream=true #314
30+
- Uses SemVerVersion in place of Version to Get or Set the metadata version in the OpenAPI document #346
3031
</PackageReleaseNotes>
3132
<AssemblyName>Microsoft.OpenApi.OData.Reader</AssemblyName>
3233
<AssemblyOriginatorKeyFile>..\..\tool\Microsoft.OpenApi.OData.snk</AssemblyOriginatorKeyFile>

src/Microsoft.OpenApi.OData.Reader/OpenApiConvertSettings.cs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,22 @@ public class OpenApiConvertSettings
2323
public Uri ServiceRoot { get; set; } = new Uri("http://localhost");
2424

2525
/// <summary>
26-
/// Gets/sets the metadata version.
26+
/// Get/set the metadata version.
2727
/// </summary>
28-
public Version Version { get; set; } = new Version(1, 0, 1);
28+
[Obsolete("Use SemVerVersion to Get or Set the metadata version.")]
29+
public Version Version
30+
{
31+
get => Version.TryParse(SemVerVersion, out var version) ? version : null;
32+
set
33+
{
34+
SemVerVersion = value?.ToString() ?? "1.0.1";
35+
}
36+
}
37+
38+
/// <summary>
39+
/// Get/set the metadata version.
40+
/// </summary>
41+
public string SemVerVersion { get; set; } = "1.0.0";
2942

3043
/// <summary>
3144
/// Gets/set a value indicating whether to output key as segment path.
@@ -328,7 +341,6 @@ internal OpenApiConvertSettings Clone()
328341
var newSettings = new OpenApiConvertSettings
329342
{
330343
ServiceRoot = this.ServiceRoot,
331-
Version = this.Version,
332344
EnableKeyAsSegment = this.EnableKeyAsSegment,
333345
EnableUnqualifiedCall = this.EnableUnqualifiedCall,
334346
EnableOperationPath = this.EnableOperationPath,
@@ -374,7 +386,8 @@ internal OpenApiConvertSettings Clone()
374386
EnableTypeDisambiguationForDefaultValueOfOdataTypeProperty = this.EnableTypeDisambiguationForDefaultValueOfOdataTypeProperty,
375387
AddAlternateKeyPaths = this.AddAlternateKeyPaths,
376388
NamespacePrefixToStripForInMethodPaths = this.NamespacePrefixToStripForInMethodPaths,
377-
EnableAliasForTypeCastSegments = this.EnableAliasForTypeCastSegments
389+
EnableAliasForTypeCastSegments = this.EnableAliasForTypeCastSegments,
390+
SemVerVersion = this.SemVerVersion
378391
};
379392

380393
return newSettings;

src/Microsoft.OpenApi.OData.Reader/PublicAPI.Unshipped.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ Microsoft.OpenApi.OData.OpenApiConvertSettings.NamespacePrefixToStripForInMethod
3333
Microsoft.OpenApi.OData.OpenApiConvertSettings.RefBaseCollectionPaginationCountResponse.get -> bool
3434
Microsoft.OpenApi.OData.OpenApiConvertSettings.RequireRestrictionAnnotationsToGenerateComplexPropertyPaths.get -> bool
3535
Microsoft.OpenApi.OData.OpenApiConvertSettings.RequireRestrictionAnnotationsToGenerateComplexPropertyPaths.set -> void
36+
Microsoft.OpenApi.OData.OpenApiConvertSettings.SemVerVersion.get -> string
37+
Microsoft.OpenApi.OData.OpenApiConvertSettings.SemVerVersion.set -> void
3638
Microsoft.OpenApi.OData.OpenApiConvertSettings.ShowExternalDocs.get -> bool
3739
Microsoft.OpenApi.OData.OpenApiConvertSettings.ShowExternalDocs.set -> void
3840
Microsoft.OpenApi.OData.OpenApiConvertSettings.UseSuccessStatusCodeRange.get -> bool

test/Microsoft.OpenAPI.OData.Reader.Tests/EdmModelOpenApiExtensionsTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ public void TripServiceMetadataToOpenApiJsonWorks(OpenApiSpecVersion specVersion
211211
OpenApiConvertSettings settings = new OpenApiConvertSettings
212212
{
213213
EnableKeyAsSegment = true,
214-
Version = new Version(1, 0, 1),
214+
SemVerVersion = "1.0.1",
215215
ServiceRoot = new Uri("http://services.odata.org/TrippinRESTierService"),
216216
IEEE754Compatible = true,
217217
OpenApiSpecVersion = specVersion,
@@ -246,7 +246,7 @@ public void TripServiceMetadataToOpenApiYamlWorks(OpenApiSpecVersion specVersion
246246
OpenApiConvertSettings settings = new OpenApiConvertSettings
247247
{
248248
EnableKeyAsSegment = true,
249-
Version = new Version(1, 0, 1),
249+
Version = new Version(1, 2, 3), // test that the obsolete property still works
250250
ServiceRoot = new Uri("http://services.odata.org/TrippinRESTierService"),
251251
IEEE754Compatible = true,
252252
OpenApiSpecVersion = specVersion,

test/Microsoft.OpenAPI.OData.Reader.Tests/Resources/Basic.OpenApi.V2.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"info": {
44
"title": "OData Service for namespace DefaultNs",
55
"description": "This OData service is located at http://localhost",
6-
"version": "1.0.1"
6+
"version": "1.0.0"
77
},
88
"host": "localhost",
99
"schemes": [

test/Microsoft.OpenAPI.OData.Reader.Tests/Resources/Basic.OpenApi.V2.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ swagger: '2.0'
22
info:
33
title: OData Service for namespace DefaultNs
44
description: This OData service is located at http://localhost
5-
version: 1.0.1
5+
version: 1.0.0
66
host: localhost
77
schemes:
88
- http

test/Microsoft.OpenAPI.OData.Reader.Tests/Resources/Basic.OpenApi.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"info": {
44
"title": "OData Service for namespace DefaultNs",
55
"description": "This OData service is located at http://localhost",
6-
"version": "1.0.1"
6+
"version": "1.0.0"
77
},
88
"servers": [
99
{

test/Microsoft.OpenAPI.OData.Reader.Tests/Resources/Basic.OpenApi.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ openapi: 3.0.1
22
info:
33
title: OData Service for namespace DefaultNs
44
description: This OData service is located at http://localhost
5-
version: 1.0.1
5+
version: 1.0.0
66
servers:
77
- url: http://localhost
88
paths:

test/Microsoft.OpenAPI.OData.Reader.Tests/Resources/Empty.OpenApi.V2.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"info": {
44
"title": "OData Service for namespace ",
55
"description": "This OData service is located at http://localhost",
6-
"version": "1.0.1"
6+
"version": "1.0.0"
77
},
88
"host": "localhost",
99
"schemes": [

0 commit comments

Comments
 (0)