From a20e301f44ae1d7db7e918a3c23070b2053121c7 Mon Sep 17 00:00:00 2001 From: Praven Kuttappan <55455725+praveenkuttappan@users.noreply.github.com> Date: Thu, 30 Nov 2023 12:26:19 -0500 Subject: [PATCH] Swagger API review parser changes to add package version in code file (#7350) * Swagger API review parser changes to add package version in code file --- .../swagger-api-parser/SwaggerApiParser/CHANGELOG | 3 +++ .../SwaggerApiParser/SwaggerAPIViewGenerator.cs | 3 ++- .../SwaggerApiParser/SwaggerApiParser.csproj | 2 +- .../SwaggerApiParser/SwaggerApiView/CodeFile.cs | 2 ++ .../SwaggerApiView/SwaggerApiViewRoot.cs | 3 +++ .../SwaggerApiView/SwaggerApiViewSpec.cs | 2 ++ .../SwaggerApiParserTest/SwaggerAPIViewTest.cs | 13 +++++++++++++ 7 files changed, 26 insertions(+), 2 deletions(-) diff --git a/tools/apiview/parsers/swagger-api-parser/SwaggerApiParser/CHANGELOG b/tools/apiview/parsers/swagger-api-parser/SwaggerApiParser/CHANGELOG index 8641633aa0a..f15a96c78cf 100644 --- a/tools/apiview/parsers/swagger-api-parser/SwaggerApiParser/CHANGELOG +++ b/tools/apiview/parsers/swagger-api-parser/SwaggerApiParser/CHANGELOG @@ -1,5 +1,8 @@ # Release History +## 1.2.0 (11-29-2023) ++ Added API version as PackageVersion in code file. + ## 1.1.0 (6-26-2023) + Disabled flatteneing of nested model. + Updated definitions to include models all referenced models diff --git a/tools/apiview/parsers/swagger-api-parser/SwaggerApiParser/SwaggerAPIViewGenerator.cs b/tools/apiview/parsers/swagger-api-parser/SwaggerApiParser/SwaggerAPIViewGenerator.cs index af722a18839..1b912a6f437 100644 --- a/tools/apiview/parsers/swagger-api-parser/SwaggerApiParser/SwaggerAPIViewGenerator.cs +++ b/tools/apiview/parsers/swagger-api-parser/SwaggerApiParser/SwaggerAPIViewGenerator.cs @@ -32,7 +32,8 @@ public static async Task GenerateSwaggerApiView(Swagger swag swaggerFilePath = swaggerFilePath }, fileName = Path.GetFileName(swaggerFilePath), - packageName = packageName + packageName = packageName, + APIVersion = swaggerSpec.info.version }; AddDefinitionsToCache(swaggerSpec, swaggerFilePath, schemaCache); diff --git a/tools/apiview/parsers/swagger-api-parser/SwaggerApiParser/SwaggerApiParser.csproj b/tools/apiview/parsers/swagger-api-parser/SwaggerApiParser/SwaggerApiParser.csproj index 48e50a17fb8..a535c1f8768 100644 --- a/tools/apiview/parsers/swagger-api-parser/SwaggerApiParser/SwaggerApiParser.csproj +++ b/tools/apiview/parsers/swagger-api-parser/SwaggerApiParser/SwaggerApiParser.csproj @@ -6,7 +6,7 @@ swaggerAPIParser net7.0 SwaggerApiParser - 1.1.0 + 1.2.0 Azure.Sdk.Tools.SwaggerApiParser True $(OfficialBuildId) diff --git a/tools/apiview/parsers/swagger-api-parser/SwaggerApiParser/SwaggerApiView/CodeFile.cs b/tools/apiview/parsers/swagger-api-parser/SwaggerApiParser/SwaggerApiView/CodeFile.cs index ab8e9084914..58ef317b0f7 100644 --- a/tools/apiview/parsers/swagger-api-parser/SwaggerApiParser/SwaggerApiView/CodeFile.cs +++ b/tools/apiview/parsers/swagger-api-parser/SwaggerApiParser/SwaggerApiView/CodeFile.cs @@ -28,6 +28,8 @@ public class CodeFile public string PackageDisplayName { get; set; } + public string PackageVersion { get; set; } + public CodeFileToken[] Tokens { get; set; } = Array.Empty(); public List LeafSections { get; set; } diff --git a/tools/apiview/parsers/swagger-api-parser/SwaggerApiParser/SwaggerApiView/SwaggerApiViewRoot.cs b/tools/apiview/parsers/swagger-api-parser/SwaggerApiParser/SwaggerApiView/SwaggerApiViewRoot.cs index c6eb2ee6c9b..a8d7a27a0d3 100644 --- a/tools/apiview/parsers/swagger-api-parser/SwaggerApiParser/SwaggerApiView/SwaggerApiViewRoot.cs +++ b/tools/apiview/parsers/swagger-api-parser/SwaggerApiParser/SwaggerApiView/SwaggerApiViewRoot.cs @@ -13,6 +13,7 @@ public class SwaggerApiViewRoot : ITokenSerializable public String PackageName; public Dictionary SwaggerApiViewSpecs; public SchemaCache schemaCache; + public String APIVersion; public SwaggerApiViewRoot(string resourceProvider, string packageName) { @@ -29,6 +30,7 @@ public async Task AddSwaggerSpec(Swagger swaggerSpec, string swaggerFilePath, st if (swaggerApiViewSpec != null) { this.SwaggerApiViewSpecs.Add(swaggerFilePath, swaggerApiViewSpec); + APIVersion = swaggerApiViewSpec.APIVersion; } } @@ -47,6 +49,7 @@ public CodeFile GenerateCodeFile() VersionString = "0", Name = this.ResourceProvider, PackageName = this.PackageName, + PackageVersion = this.APIVersion, Navigation = this.BuildNavigationItems() }; diff --git a/tools/apiview/parsers/swagger-api-parser/SwaggerApiParser/SwaggerApiView/SwaggerApiViewSpec.cs b/tools/apiview/parsers/swagger-api-parser/SwaggerApiParser/SwaggerApiView/SwaggerApiViewSpec.cs index 33f023823c3..b2f8b6c5395 100644 --- a/tools/apiview/parsers/swagger-api-parser/SwaggerApiParser/SwaggerApiView/SwaggerApiViewSpec.cs +++ b/tools/apiview/parsers/swagger-api-parser/SwaggerApiParser/SwaggerApiView/SwaggerApiViewSpec.cs @@ -17,6 +17,7 @@ public SwaggerApiViewSpec(string fileName) public string fileName; public string packageName; + public string APIVersion; public SwaggerApiViewSpec() @@ -100,6 +101,7 @@ public CodeFile GenerateCodeFile() VersionString = "0", Name = this.fileName, PackageName = this.packageName, + PackageVersion = this.APIVersion, Navigation = new NavigationItem[] { this.BuildNavigationItem() } }; return ret; diff --git a/tools/apiview/parsers/swagger-api-parser/SwaggerApiParserTest/SwaggerAPIViewTest.cs b/tools/apiview/parsers/swagger-api-parser/SwaggerApiParserTest/SwaggerAPIViewTest.cs index aa29cefad9a..8c9c4205e17 100644 --- a/tools/apiview/parsers/swagger-api-parser/SwaggerApiParserTest/SwaggerAPIViewTest.cs +++ b/tools/apiview/parsers/swagger-api-parser/SwaggerApiParserTest/SwaggerAPIViewTest.cs @@ -278,4 +278,17 @@ public async Task TestCommunicationEmailWithHeaderParameters() await codeFile.SerializeAsync(writer); } + + [Fact] + public async Task TestCodeFilePackageVersion() + { + const string runCommandFilePath = "./fixtures/runCommands.json"; + var swaggerSpec = await SwaggerDeserializer.Deserialize(runCommandFilePath); + + SwaggerApiViewRoot root = new SwaggerApiViewRoot("Microsoft.Compute", "Microsoft.Compute"); + await root.AddSwaggerSpec(swaggerSpec, Path.GetFullPath(runCommandFilePath), "Microsoft.Compute"); + + var codeFile = root.GenerateCodeFile(); + Assert.Equal("2021-11-01", codeFile.PackageVersion); + } }