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

Path not resolving correctly if the URL contains space #3516

Closed
DevyaJha opened this issue May 14, 2024 · 2 comments
Closed

Path not resolving correctly if the URL contains space #3516

DevyaJha opened this issue May 14, 2024 · 2 comments

Comments

@DevyaJha
Copy link

Q&A (please complete the following information)

  • OS: macOS
  • Environment: Node.js v18.16.0
  • Method of installation:npm
  • Swagger-Client version: 3.27.9
  • Swagger/OpenAPI version: [e.g. Swagger 2.0, OpenAPI 3.0]

Content & configuration

Describe the bug you're encountering

If the URL has spaces, then the path parameters are not resolved correctly.

To reproduce...

Steps to reproduce the behavior:

const Swagger = require('swagger-client')
const spec = {
    host: 'swagger.io',
    basePath: '/v1',
    paths: {
      '/accounts/{accountName}/resources/Task lists/operations/getTasks/{id}/orders/{order}/{itemId}': {
        get: {
          operationId: 'getMe',
          parameters: [
            {
                "name": "accountName",
                "in": "path",
                "description": "Account name",
                "required": true,
                "schema": {
                    "type": "string"
                }
            },
            {
              in: 'path',
              name: 'id',
              type: 'number',
              required: true,
            },
            {
              in: 'path',
              name: 'order',
              type: 'number',
              required: true,
            },
            {
              in: 'path',
              name: 'itemId',
              type: 'number',
              required: true,
            },
          ],
        },
      },
    },
  };

  const req = Swagger.buildRequest({
    spec,
    operationId: 'getMe',
    parameters: { accountName: 'Account 1', id: '123', order: '456', itemId: '789' },
  });


  console.log('req ---- ', req)

Current behavior

req ---- {
url: 'http://swagger.io/v1/accounts/{accountName}/resources/Task lists/operations/getTasks/{id}/orders/{order}/{itemId}',
credentials: 'same-origin',
headers: {},
method: 'GET'
}

Expected behavior

Resolved req should be -

req ---- {
url: 'http://swagger.io/v1/accounts/Account%201/resources/Task lists/operations/getTasks/123/orders/456/789',
credentials: 'same-origin',
headers: {},
method: 'GET'
}

Screenshots

Additional context or thoughts

@orionchikby
Copy link

in my case I use bower-asset/swagger-ui , and in "v5.17.7" was bug
just update to v5.17.9

@char0n
Copy link
Member

char0n commented May 15, 2024

Hi everybody,

In latest versions of swagger-client we've utilized the spec compliant OpenAPI Path template parsing.

Here is what OpenAPI stipulates about path templating:

Path templating refers to the usage of template expressions, delimited by curly braces ({}), to mark a section of a URL path as replaceable using path parameters. link

This specifies that path template forms a relative URL reference. This is what OpenAPI stipulates about relative URL reference:

Unless specified otherwise, all properties that are URLs MAY be relative references as defined by RFC3986 link

This means that parsing of path template MUST be RFC3986 compliant and thus cannot contain unencoded empty string values. As the path template with empty space doesn't qualify as valid path template, it's not being resolved.


Having said that, we didn't introduce a regression, we fixed a bug that allowed to define path templates as invalid RFC3986. Now we don't allow it anymore.

To remedy specific situation as described in the description of this issue

/accounts/{accountName}/resources/Task lists/operations/getTasks/{id}/orders/{order}/{itemId}

needs to be replaced by

/accounts/{accountName}/resources/Task%20lists/operations/getTasks/{id}/orders/{order}/{itemId}

@char0n char0n closed this as completed May 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants