Coder Social home page Coder Social logo

modular approach about open-api HOT 11 CLOSED

kogosoftwarellc avatar kogosoftwarellc commented on August 17, 2024 1
modular approach

from open-api.

Comments (11)

jsdevel avatar jsdevel commented on August 17, 2024

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.

from open-api.

jsdevel avatar jsdevel commented on August 17, 2024

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

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

from open-api.

troymolsberry avatar troymolsberry commented on August 17, 2024

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...

from open-api.

jsdevel avatar jsdevel commented on August 17, 2024

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

from open-api.

troymolsberry avatar troymolsberry commented on August 17, 2024

`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

from open-api.

jsdevel avatar jsdevel commented on August 17, 2024

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?

from open-api.

troymolsberry avatar troymolsberry commented on August 17, 2024

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

from open-api.

jsdevel avatar jsdevel commented on August 17, 2024

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

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

from open-api.

jsdevel avatar jsdevel commented on August 17, 2024

@troymolsberry can you review #46?

from open-api.

troymolsberry avatar troymolsberry commented on August 17, 2024

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

from open-api.

jsdevel avatar jsdevel commented on August 17, 2024

published as v0.26.0 @troymolsberry !

from open-api.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.