question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Regression: Version 3 does not merge path and operation properties

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
kevinoidcommented, Mar 18, 2017

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.

0reactions
kevinoidcommented, Mar 25, 2017

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Patch drops properties that are null or are an empty array ...
edited. I see this problem starting in v3. 8.0. When a resource defines a property with null, or an array as empty, the...
Read more >
Multiple Regression - an overview | ScienceDirect Topics
The objective of multiple regression analysis is to use the independent variables whose values are known to predict the value of the single...
Read more >
Lecture notes on ridge regression - arXiv
This document is a collection of many well-known results on ridge regression. The current status of the document is 'work-in-progress' as it is...
Read more >
7 Github Actions Tricks I Wish I Knew Before I Started
Here are 7 tricks with github actions that changed my life (or at least my CI/CD pipeline). These tricks helped me create a...
Read more >
Apply SPSS Linear Regression results to predict ... - IBM
If merging these data sets is not feasible, then Method 3 can be applied. Method 1: Scoring from an XML file of the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found