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.

Swagger path not recognized

See original GitHub issue

Hi!

When processing an example swagger definition hippie-swagger complains of an undefined path that is defined:

'use strict'

var SwaggerParser = require('swagger-parser')
var parser = new SwaggerParser()
var hippie = require('hippie-swagger')
var expect = require('chai').expect
var path = require('path')
var dereferencedSwagger

describe('Example of', function () {
  before(function (done) {
    parser.dereference('https://raw.githubusercontent.com/OAI/OpenAPI-Specification/master/examples/v2.0/json/petstore.json', function (err, api) {
      if (err) return done(err)
      dereferencedSwagger = api
      done()
    })
  })

  describe('correct usage', function () {
    it('should allow to post to /pets', function (done) {
      hippie(dereferencedSwagger)
      .json()
      .post('/pets')
      .expectStatus(200)
      .end(done)
    })
  })
})

The answer I receive is:

$ mocha index.js


  Example of
    correct usage
      1) should allow to post to /pets


  0 passing (225ms)
  1 failing

  1) Example of correct usage should allow to post to /pets:
     Error: Swagger spec does not define path: /pets
      at Client.middleware (node_modules/hippie-swagger/lib/middleware.js:15:13)
      at next (node_modules/hippie/lib/hippie/client.js:456:5)
      at Client.setup (node_modules/hippie/lib/hippie/client.js:457:5)
      at Client.prepare (node_modules/hippie/lib/hippie/client.js:364:17)
      at Client.end (node_modules/hippie/lib/hippie/client.js:382:24)
      at Context.<anonymous> (index.js:32:8)

By the way, thanks for this awesome project!

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
CacheControlcommented, Sep 9, 2017

@lcofre ah! yes you can absolutely test non-node applications this way. You just have to include the full uri in the request. This isn’t well documented and I’ll make a note to build a full fledged example for this use case.

Here’s a working snippet that I tested locally:

'use strict'

var SwaggerParser = require('swagger-parser')
var parser = new SwaggerParser()
var hippie = require('./index')
var expect = require('chai').expect
var path = require('path')
var dereferencedSwagger

describe('Example of', function () {
  before(function (done) {
    parser.dereference('https://raw.githubusercontent.com/OAI/OpenAPI-Specification/master/examples/v2.0/json/petstore.json', function (err, api) {
      if (err) return done(err)
      dereferencedSwagger = api
      done()
    })
  })

  describe('correct usage', function () {
    it('should allow to post to /pets', function (done) {
      hippie(dereferencedSwagger)
      .json()
      .post('http://localhost:3000/v1/pets')   // fully qualified url
      .expectStatus(201)
      .end(done)
    })
  })
})

And the example server (can be run by any language / backend):

var http = require('http');

//create a server object:
http.createServer(function (req, res) {
  res.statusCode = 201
  res.write(JSON.stringify({}));
  res.end();
}).listen(3000);
0reactions
lcofrecommented, Sep 9, 2017

Sorry! I supposed that with no app, it’ll try to test the “host” in the swagger definition or the server where the definition is hosted in. Is this not true?

Or in other words, can I only test NodeJS apps?

Thanks very much for your time!

Read more comments on GitHub >

github_iconTop Results From Across the Web

swagger-codegen is not recognized as an internal or external ...
It depends. If you use absolute paths, there's no need to change the PATH . If you want to use just the file...
Read more >
Path not found error for endpoint with trailing slash · Issue #899
Problem statement. Hello When I specify endpoints ending with a slash in my swagger file, at runtime when trying to reach the same...
Read more >
Paths and Operations - Swagger
API paths and operations are defined in the global paths section of the API specification. All paths are relative to the API server...
Read more >
Fix Swagger Validator errors in Power Platform connectors
The expected path is '{0}'. The dynamic properties extension item value path does not match the expected path based on the schema.
Read more >
Can't get swagger docs recognized - OutSystems
ProtocolError: The remote server returned an error: (404) Not Found. ... the url path below swagger, and the url path that points to...
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