From aef61a70c09a5bd5d4402a887d3d2c1eb1018f1e Mon Sep 17 00:00:00 2001 From: Aaron Date: Fri, 14 Apr 2023 13:50:01 -0700 Subject: [PATCH] Ensure ApiPath does not get a NullReferenceExcepton when copying common parameters to operation method parameters. (#5914) Previously, when the operation method does not have any parameters a null refference exception occurs when attempting to copy the common parameters to the operation metod. --- .../SwaggerApiParser/SwaggerSpec/ApiPath.cs | 5 +++++ .../SwaggerApiParserTest/fixtures/azureopenai.json | 13 +++++-------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/tools/apiview/parsers/swagger-api-parser/SwaggerApiParser/SwaggerSpec/ApiPath.cs b/tools/apiview/parsers/swagger-api-parser/SwaggerApiParser/SwaggerSpec/ApiPath.cs index 9221de5672a..d4e19940ae5 100644 --- a/tools/apiview/parsers/swagger-api-parser/SwaggerApiParser/SwaggerSpec/ApiPath.cs +++ b/tools/apiview/parsers/swagger-api-parser/SwaggerApiParser/SwaggerSpec/ApiPath.cs @@ -36,6 +36,11 @@ public Dictionary operations { if (this.parameters != null) { + if (operation.parameters == null) + { + operation.parameters = new List(); + } + operation.parameters.AddRange(this.parameters); } ret.Add(method, operation); diff --git a/tools/apiview/parsers/swagger-api-parser/SwaggerApiParserTest/fixtures/azureopenai.json b/tools/apiview/parsers/swagger-api-parser/SwaggerApiParserTest/fixtures/azureopenai.json index 034e5dd6417..c068825b347 100644 --- a/tools/apiview/parsers/swagger-api-parser/SwaggerApiParserTest/fixtures/azureopenai.json +++ b/tools/apiview/parsers/swagger-api-parser/SwaggerApiParserTest/fixtures/azureopenai.json @@ -7,6 +7,11 @@ }, "paths": { "/deployments": { + "parameters": [ + { + "$ref": "#/parameters/apiVersionQueryParameter" + } + ], "get": { "tags": [ "Deployments:" @@ -16,11 +21,6 @@ "produces": [ "application/json" ], - "parameters": [ - { - "$ref": "#/parameters/apiVersionQueryParameter" - } - ], "responses": { "200": { "description": "Success", @@ -54,9 +54,6 @@ "application/json" ], "parameters": [ - { - "$ref": "#/parameters/apiVersionQueryParameter" - }, { "in": "body", "name": "body",