diff --git a/tools/apiview/parsers/swagger-api-parser/SwaggerApiParser/CHANGELOG b/tools/apiview/parsers/swagger-api-parser/SwaggerApiParser/CHANGELOG index f15a96c78cf..5ab83a5e8b2 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.3.0 (12-12-2023) ++ Support local schema reference in another referred swagger file + ## 1.2.0 (11-29-2023) + Added API version as PackageVersion in code file. diff --git a/tools/apiview/parsers/swagger-api-parser/SwaggerApiParser/SwaggerAPIViewGenerator.cs b/tools/apiview/parsers/swagger-api-parser/SwaggerApiParser/SwaggerAPIViewGenerator.cs index 1b912a6f437..c6281824754 100644 --- a/tools/apiview/parsers/swagger-api-parser/SwaggerApiParser/SwaggerAPIViewGenerator.cs +++ b/tools/apiview/parsers/swagger-api-parser/SwaggerApiParser/SwaggerAPIViewGenerator.cs @@ -173,6 +173,7 @@ public static async Task GenerateSwaggerApiView(Swagger swag { var resp = response; var referenceSwaggerFilePath = swaggerFilePath; + string referencePath = ""; if (response.IsRefObject()) { @@ -180,11 +181,14 @@ public static async Task GenerateSwaggerApiView(Swagger swag if (resp == null) { resp = (Response)schemaCache.GetResponseFromCache(response.@ref, swaggerFilePath); + // Update reference path if referenced object is in another swagger file + if (response.IsRefObject() && !response.@ref.StartsWith("#")) + referencePath = response.@ref; } if (resp == null) { - var referencePath = response.@ref; + referencePath = response.@ref; do { if (!Path.IsPathFullyQualified(referencePath)) @@ -216,7 +220,13 @@ public static async Task GenerateSwaggerApiView(Swagger swag { if (schema.IsRefObject()) { - var referencePath = schema.@ref; + // Update swagger file path to correct file if schema reference is local but parent itself is in another swagger file + if (schema.@ref.StartsWith("#") && !string.IsNullOrEmpty(referencePath)) + { + referenceSwaggerFilePath = Utils.GetReferencedSwaggerFile(referencePath, referenceSwaggerFilePath); + } + + referencePath = schema.@ref; do { referenceSwaggerFilePath = Utils.GetReferencedSwaggerFile(referencePath, referenceSwaggerFilePath); diff --git a/tools/apiview/parsers/swagger-api-parser/SwaggerApiParser/SwaggerApiParser.csproj b/tools/apiview/parsers/swagger-api-parser/SwaggerApiParser/SwaggerApiParser.csproj index a535c1f8768..420e137fc84 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.2.0 + 1.3.0 Azure.Sdk.Tools.SwaggerApiParser True $(OfficialBuildId)