swagger-api / swagger-ui

Swagger UI is a collection of HTML, JavaScript, and CSS assets that dynamically generate beautiful documentation from a Swagger-compliant API.
https://swagger.io
Apache License 2.0
26.57k stars 8.95k forks source link

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

Open krishnaktcs opened 5 months ago

krishnaktcs commented 5 months ago

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?

char0n commented 5 months ago

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

krishnaktcs commented 5 months ago

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.

char0n commented 5 months ago

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

igor-tatarnikov-idt commented 4 months ago

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?

W-Lawless commented 2 months ago

@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' \
falbert-ptc commented 2 weeks ago

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.