Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swagger API review parser changes to add package version in code file #7350

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
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);
}
}