swagger-ui icon indicating copy to clipboard operation
swagger-ui copied to clipboard

Path Parameter is not being passed through Request URL and Curl Command.

Open krishnaktcs opened this issue 1 year ago • 5 comments

Hi Everyone,

I am facing issues in swagger UI, all APIs are working fine in my local but not working in Production (only few APIs are working). Earlier APIs was working fine in my local and Production but suddenly It stopped working.

version: Local and Production same version I am using.

"swagger-jsdoc": "^6.2.5",
"swagger-ui-express": "^4.5.0", 
"node": "^14.17.6"

example : GET [/ABC/{First Parameter / ID}/{Second Parameter}]

Response :-

Code Details 404 Error: Not Found Response body Unrecognized response type; displaying content as text.

Download [ xyz - BackEnd Application Server ] - Unknown Comman

Request URL

https://abc.com/ABC/{First Parameter / ID}/{Second Parameter}

curl -X 'GET' \ 'https://abc.com/ABC/{First Parameter / ID}/{Second Parameter}' \ -H 'accept: /'

Anyone can help me on this?

krishnaktcs avatar May 28 '24 07:05 krishnaktcs

It's most probably because of the fact that swagger-client now utilizes spec compliant Path Templating implementation. The spec is still ambiguous about various cases like the one that probably affects you. More info https://github.com/OAI/OpenAPI-Specification/issues/3256#issuecomment-2152144357

char0n avatar Jun 06 '24 11:06 char0n

Hi @char0n,

Thanks for addressing this issue.

We were also suspecting the same. So, we tried to remove extra space from endpoints parameter names, it works for single path parameter, but it doesn't work for more than one Path-parameter.

In case of multi parameters - we could see the value only for the first param and the second param will have undefined.

example : GET [/ABC/{FirstParameter/ID}/{SecondParameter}]

FirstParameter:- 'xyz', SecondParameter;- 'jkl'

Request URL https://abc.com/ABC/xyz/{SecondParameter}

Response :- Code Details 404 Error: Not Found Response body Unrecognized response type; displaying content as text. Download [ xyz - BackEnd Application Server] - Unknown Command

we also tried GET [/abc/{firstparameterid}/{secondparameter}]

Response: same as above

Please let us know if there is any other alternative way to resolve this issue. Your help would be greatly appreciated.

Thanks.

krishnaktcs avatar Jun 07 '24 06:06 krishnaktcs

Hm then that's strange. If you have path parameters matching the template (have you changed the Parameter Object.name field?), it should just resolve. There is a test guarantying this to work: https://github.com/char0n/openapi-path-templating/blob/main/test/resolve.js#L18

char0n avatar Jun 07 '24 06:06 char0n

Hi @char0n @krishnaktcs

Facing a similar problem with path parameter and URL like /api/books/isbn={isbn} - the isbn required parameter populated on Swagger UI never gets submitted in URL or cURL in an ASP.NET Core app referencing SwaggerUI v6.6.2 NuGet (5.17.10, if i'm mapping versions correctly). It does replace the URL template value with actual value in SwaggerUI v6.5.0.

So, my question is do you recognize a URL like api/foo={bar} as a non-RFC-compliant? or is it rather a bug?

igor-tatarnikov-idt avatar Jul 09 '24 10:07 igor-tatarnikov-idt

@char0n @krishnaktcs I am also seeing this issue. Please consider prioritizing this fix as it is part of the core functionality of the product and as-is severely limits it's usability.

Using

    "node_modules/swagger-ui-express": {
      "version": "5.0.1",

Here is there relevant yaml commented in-line using swagger-js-doc , with some details changed for security.

 * /api/v2/parent/{paramOne}/child/{paramTwo}:
 *   post:
 *     security:
 *       - bearerAuth: []
 *     description: Updates the data.
 *     tags: []
 *     consumes: ["application/json"]
 *     parameters:
 *       - name: paramTwo
 *         in: path
 *         required: true
 *         description: The child ID
 *         schema:
 *           type: string
 *         example: 1
 *       - name: paramOne
 *         in: path
 *         required: true
 *         description: The parent ID
 *         schema:
 *           type: string
 *         example: 35

In my testing, only the first parameter listed is properly interpolated into the cURL statement, and this behavior is consistently observable when re-ordering the parameters.

The relevant cURL statement will be as follows:


curl -X 'POST' \
  'http://localhost:3000/api/v2/parent/{paramOne}/child/1' \

W-Lawless avatar Sep 05 '24 01:09 W-Lawless

Hello @char0n @krishnaktcs

I have recently updated Swagger UI to 5.17.14 and I am seeing regressions for all path parameters that contain the "=" sign (similar to the issue reported by @igor-tatarnikov-idt ).

My Swagger Spec looks like this: "/GetMetaInfo(EntityName='{EntityName}')" : { "get" : { "tags" : [ "Service Endpoints" ], "summary" : "", "description" : "", "operationId" : "Function_GetMetaInfo_With", "parameters" : [ { "name" : "EntityName", "in" : "path", "description" : "The fully qualified entity or complex type name", "required" : true, "schema" : { "type" : "string" } } ], "responses" : { "200" : { "description" : "Success", "content" : { "application/json" : { "schema" : { "$ref" : "#/components/schemas/MyFQN.EntityMetaInfo" } } } } } } }

I cannot revert to Swagger UI 5.17.6 because of DOMPurity library vulnerability.

falbert-ptc avatar Oct 21 '24 16:10 falbert-ptc

Can you please confirm you can still see the issues in latest SwaggerUI release?

char0n avatar Dec 03 '24 14:12 char0n

This seems to be resolved

falbert-ptc avatar Dec 03 '24 15:12 falbert-ptc

@falbert-ptc thanks for confirming. Closing this issue. Please reopen if this is not resolved.

char0n avatar Dec 04 '24 16:12 char0n