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

Regression: Version 3 does not merge path and operation properties #965

Closed
kevinoid opened this issue Mar 18, 2017 · 6 comments
Closed

Regression: Version 3 does not merge path and operation properties #965

kevinoid opened this issue Mar 18, 2017 · 6 comments

Comments

@kevinoid
Copy link
Contributor

In a specification where parameters are defined on both the path and the operation, the parameters from the path appear to be ignored. For example:

'use strict';

const assert = require('assert');
const http = require('http');
const SwaggerClient = require('swagger-client');

const TEST_HOST = 'localhost';
const TEST_ID = 123;
const TEST_PORT = 8888;

http
  .createServer((req, res) => {
    assert.strictEqual(req.url, `/cars/${TEST_ID}`);
    res.writeHead(200, {'Content-Type': 'application/json'});
    res.end('{}');
  })
  .listen(TEST_PORT, TEST_HOST, () => {
    new SwaggerClient({
      usePromise: true,
      spec: {
        swagger: '2.0',
        info: {
          title: 'Path Parameter API',
          version: '1.0.0'
        },
        host: `${TEST_HOST}:${TEST_PORT}`,
        schemes: [
          'http'
        ],
        paths: {
          '/cars/{carId}': {
            parameters: [
              {
                name: 'carId',
                in: 'path',
                type: 'number',
                required: true
              }
            ],
            get: {
              operationId: 'getCar',
              parameters: [
                {
                  name: 'clean',
                  in: 'query',
                  type: 'boolean'
                }
              ],
              responses: {
                200: {
                  description: 'A car',
                  schema: {
                    type: 'object'
                  }
                }
              }
            }
          }
        }
      }
    })
      .then(client => client.apis.default.getCar({carId: TEST_ID}))
      .then(
        () => {
          console.log('It works.');
          process.exit();
        },
        err => {
          console.error(err);
          process.exit(1);
        }
      );
  });

With swagger-js version 3.0.1 this fails with AssertionError: '/cars/%7BcarId%7D' === '/cars/123' while swagger-js version 2.1.32 prints It works.. I bisected the regression to 7678d40, but that's obviously not very helpful since almost everything was replaced in that commit.

Thanks,
Kevin

@webron
Copy link
Contributor

webron commented Mar 18, 2017

@kevinoid Thanks for the report. This is a complete rewrite so previous code may not be relevant. I was sure we had a test for this case, but we'll definitely look into it.

@kevinoid
Copy link
Contributor Author

Great, thanks @webron!

@webron
Copy link
Contributor

webron commented Mar 18, 2017

Thanks for reporting the issue. Please report new ones as you find them. If you can help us with writing tests and even fixes PRs, that would be appreciated. We hope to formalize a process for it later this week.

@kevinoid
Copy link
Contributor Author

Will do. So far this is the only issue I've noticed.

I actually started writing a test for this one but got bogged down when the test behaved differently than calling the API directly (looks like parameters is moved out of the path object somewhere outside of the buildRequest function used in the tests, but I could be wrong on that). I'll try to send a test and/or fix with future issues.

@saharj
Copy link
Contributor

saharj commented Mar 23, 2017

I'm still working on this and trying to solve the issue.
The interesting thing I've found is that if you put path-parameters after get like below:

paths: {
  '/cars/{carId}': {
    get: {
      operationId: 'getCar',
      parameters: [
        {
          name: 'clean',
          in: 'query',
          type: 'boolean'
        }
      ],
      responses: {
        200: {
          description: 'A car',
          schema: {
            type: 'object'
          }
        }
      }
    },
    parameters: [
      {
        name: 'carId',
        in: 'path',
        type: 'number',
        required: true
      }
    ]
  }
}

the URL will have the {carId} in it, but the query parameter clean won't get included in the URL.

@kevinoid
Copy link
Contributor Author

Thanks @saharj and @buunguyen! The fix is working well for me with v3.0.3.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants