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

The example of petstore-separate deosn't work #505

Closed
lvarayut opened this issue Nov 11, 2015 · 5 comments
Closed

The example of petstore-separate deosn't work #505

lvarayut opened this issue Nov 11, 2015 · 5 comments

Comments

@lvarayut
Copy link

I'm trying to separate files and link them all together using $ref. I came across the petstore-separate example which shows how to do so. However, I got the following errors:

    API Errors:

      #/paths/~1pets/get/parameters/0/$ref: Reference could not be resolved: parameters.json#/tagsParam
      #/paths/~1pets/get/parameters/1/$ref: Reference could not be resolved: parameters.json#/limitsParam
      #/paths/~1pets/get/responses/200/schema/items/$ref: Reference could not be resolved: Pet.json
      #/paths/~1pets/get/responses/default/schema/$ref: Reference could not be resolved: ../common/Error.json
      #/paths/~1pets/post/responses/200/schema/$ref: Reference could not be resolved: Pet.json
      #/paths/~1pets/post/parameters/0/schema/$ref: Reference could not be resolved: NewPet.json
      #/paths/~1pets/post/responses/default/schema/$ref: Reference could not be resolved: ../common/Error.json
      #/paths/~1pets~1{id}/get/responses/200/schema/$ref: Reference could not be resolved: Pet.json
      #/paths/~1pets~1{id}/get/responses/default/schema/$ref: Reference could not be resolved: ../common/Error.json
      #/paths/~1pets~1{id}/delete/responses/default/schema/$ref: Reference could not be resolved: ../common/Error.json
      #/paths/~1pets/get/parameters/1/name: Parameter already defined: undefined

I'm using swagger-tools to compile my code as following:

'use strict';

var app = require('connect')();
var http = require('http');
var swaggerTools = require('swagger-tools');

var serverPort = 3000;

// swaggerRouter configuration
var options = {
  swaggerUi: '/swagger.json',
  controllers: './controllers',
  useStubs: process.env.NODE_ENV === 'development' ? true : false // Conditionally turn on stubs (mock mode)
};

// The Swagger document (require it, build it programmatically, fetch it from a URL, ...)
var swaggerDoc = require('./api/spec/swagger.json');

// Initialize the Swagger middleware
swaggerTools.initializeMiddleware(swaggerDoc, function(middleware) {
  // Interpret Swagger resources and attach metadata to request - must be first in swagger-tools middleware chain
  app.use(middleware.swaggerMetadata());

  // Validate Swagger requests
  app.use(middleware.swaggerValidator());

  // Route validated requests to appropriate controller
  app.use(middleware.swaggerRouter(options));

  // Serve the Swagger documents and Swagger UI
  app.use(middleware.swaggerUi());

  // Start the server
  http.createServer(app).listen(serverPort, function() {
    console.log('Your server is listening on port %d (http://localhost:%d)', serverPort, serverPort);
    console.log('Swagger-ui is available on http://localhost:%d/docs', serverPort);
  });
});

I have been googling for 3 hours. Any help would be appreciated.

@webron
Copy link
Member

webron commented Dec 1, 2015

@whitlockjc?

@whitlockjc
Copy link
Member

This is a known issue with swagger-tools: swagger-tools/issues/227.

@whitlockjc
Copy link
Member

There are some workarounds in that issue as well that might help unblock you but until swagger-tools@1.0.0 it likely will not be fixed.

@webron
Copy link
Member

webron commented Dec 1, 2015

Thanks @whitlockjc. @lvarayut, please follow the related issue.

@webron webron closed this as completed Dec 1, 2015
@lvarayut
Copy link
Author

lvarayut commented Dec 2, 2015

@webron @whitlockjc Alright. Thanks for your response.

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