Skip to content

Commit

Permalink
Swagger API review parser changes to add package version in code file (
Browse files Browse the repository at this point in the history
…#7350)

* Swagger API review parser changes to add package version in code file
  • Loading branch information
praveenkuttappan authored Nov 30, 2023
1 parent b94f185 commit a20e301
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ public static async Task<SwaggerApiViewSpec> GenerateSwaggerApiView(Swagger swag
swaggerFilePath = swaggerFilePath
},
fileName = Path.GetFileName(swaggerFilePath),
packageName = packageName
packageName = packageName,
APIVersion = swaggerSpec.info.version
};

AddDefinitionsToCache(swaggerSpec, swaggerFilePath, schemaCache);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<ToolCommandName>swaggerAPIParser</ToolCommandName>
<TargetFramework>net7.0</TargetFramework>
<RootNamespace>SwaggerApiParser</RootNamespace>
<VersionPrefix>1.1.0</VersionPrefix>
<VersionPrefix>1.2.0</VersionPrefix>
<AssemblyName>Azure.Sdk.Tools.SwaggerApiParser</AssemblyName>
<SignAssembly>True</SignAssembly>
<InformationalVersion>$(OfficialBuildId)</InformationalVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public class CodeFile

public string PackageDisplayName { get; set; }

public string PackageVersion { get; set; }

public CodeFileToken[] Tokens { get; set; } = Array.Empty<CodeFileToken>();

public List<CodeFileToken[]> LeafSections { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public class SwaggerApiViewRoot : ITokenSerializable
public String PackageName;
public Dictionary<String, SwaggerApiViewSpec> SwaggerApiViewSpecs;
public SchemaCache schemaCache;
public String APIVersion;

public SwaggerApiViewRoot(string resourceProvider, string packageName)
{
Expand All @@ -29,6 +30,7 @@ public async Task AddSwaggerSpec(Swagger swaggerSpec, string swaggerFilePath, st
if (swaggerApiViewSpec != null)
{
this.SwaggerApiViewSpecs.Add(swaggerFilePath, swaggerApiViewSpec);
APIVersion = swaggerApiViewSpec.APIVersion;
}
}

Expand All @@ -47,6 +49,7 @@ public CodeFile GenerateCodeFile()
VersionString = "0",
Name = this.ResourceProvider,
PackageName = this.PackageName,
PackageVersion = this.APIVersion,
Navigation = this.BuildNavigationItems()
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public SwaggerApiViewSpec(string fileName)

public string fileName;
public string packageName;
public string APIVersion;


public SwaggerApiViewSpec()
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit a20e301

Please sign in to comment.