krakenjs / swaggerize-express

Design-driven apis with swagger 2.0 and express.
Other
355 stars 81 forks source link

Relative paths not supported #87

Open jsdevel opened 8 years ago

jsdevel commented 8 years ago

I kept getting this with something like "$ref": "Address.json" in one of my definitions. The definition file had a sibling Address.json file in the same directory.

Here's the error: callstack-exceeded-error

Not really sure how it could work though as swaggerize-express is expecting definitions to be an object:

must-be-an-object

See the docs for reference object

swagger-relative

tlivings commented 8 years ago

If you want to use external references like this, you can use extrefs module to resolve them in advance.

That being said, we need to build support for this in directly.

krazylearner commented 8 years ago

HI i am facing same problem . The middleware is not working with documents which contain '$ref' to other json documents which are relative files. thanks

tlivings commented 8 years ago

We're working on making references resolve automatically. But the way around this is to resolve references before hand:

import Express from 'express';
import Swaggerize from 'swaggerize-express';
import Resolver from 'extrefs';

const app = Express();

Resolver(api).resolve((error, schemas) => {
    app.use(Swaggerize({ api, handlers, schemas}));

    //etc
});
jsdevel commented 8 years ago

I'm now using express-openapi, and find it's usage of jsonpath to be a lot more stable. Perhaps switching to jsonpath would make the transition smoother and resolve a lot of other validation bugs?

tlivings commented 8 years ago

We're working on conversion to use swagger-parser but integration with an asynchronous resolver requires some work to maintain consistency with the current API.