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

modular approach #45

Closed
troymolsberry opened this issue Sep 1, 2016 · 11 comments
Closed

modular approach #45

troymolsberry opened this issue Sep 1, 2016 · 11 comments

Comments

@troymolsberry
Copy link
Contributor

Hello, thank you for the excellent framework. I have a question about using it to construct modular express applications, where multiple routes are defined in individual npm modules, and the final product is composed from these. Can I call openapi.initialize() multiple times in a single app, once for each module? This implies that instead of a single routes folder, I may have several...

@jsdevel
Copy link
Contributor

jsdevel commented Sep 1, 2016

Give me some more details for your use case. It sounds like maybe you have different versions of your API in separate directories, like api-v1/ and api-v2/ etc. If that's the case, you can definitely call .initialize() with separate instances of your app and then have a parent app that you parentApp.use(v1App) with.

@jsdevel
Copy link
Contributor

jsdevel commented Sep 1, 2016

Can I call openapi.initialize() multiple times in a single app, once for each module

I haven't tried this, but it should work.

@troymolsberry
Copy link
Contributor Author

troymolsberry commented Sep 1, 2016

My specific use case would be (company initiative #1) as a stand-alone npm module, and (company initiative #2) as a stand-alone npm module. Each of these modules would have a "routes" folder that conforms to the express-openapi format. There is a parent express project that is composed of all company initiatives (modules). Ultimately, I would like the parent api to behave exactly as though it had been built monolithically, with the rendered apiDocs, etc...

@jsdevel
Copy link
Contributor

jsdevel commented Sep 1, 2016

I see. You should be able to run initialize() multiple times on the same app then.

@troymolsberry
Copy link
Contributor Author

`var app = require('express')();
var openapi = require('express-openapi');
var async = require("async");

var modules = ['foo', 'bar'].map(function (module_name) {
return require(module_name);
});
async.eachSeries(modules, function (module, cb) {
openapi.initialize({
apiDoc: require('./api/api.js'),
app: app,
routes: module.routes_directory
});
cb();
}, function (err) {

app.use(function (err, req, res, next) {
    res.status(err.status).json(err);
});

app.listen(3000);

});
`

results in only foo routes appearing in the generated api documentation

@jsdevel
Copy link
Contributor

jsdevel commented Sep 2, 2016

results in only foo routes appearing in the generated api documentation

I see. Yea. That would be an issue.

How about if routes can accept an Array of paths? They'd have the same version prefix as outlined in your api-doc. Would that work?

@troymolsberry
Copy link
Contributor Author

absolutely would work, that was what I was originally hoping for

@jsdevel
Copy link
Contributor

jsdevel commented Sep 2, 2016

absolutely would work, that was what I was originally hoping for

Sweet! I'll try to have this implemented tonight.

jsdevel added a commit that referenced this issue Sep 2, 2016
@jsdevel
Copy link
Contributor

jsdevel commented Sep 2, 2016

@troymolsberry can you review #46?

@troymolsberry
Copy link
Contributor Author

Smoke testing passed, I will now start digging in to building a modular api with this excellent framework. Thank you for the impressively rapid attention to this enhancement. Cheers

@jsdevel
Copy link
Contributor

jsdevel commented Sep 2, 2016

published as v0.26.0 @troymolsberry !

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

2 participants