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

Middleware should be opt-in like express #13

Closed
DaleLJefferson opened this issue Mar 3, 2016 · 2 comments
Closed

Middleware should be opt-in like express #13

DaleLJefferson opened this issue Mar 3, 2016 · 2 comments

Comments

@DaleLJefferson
Copy link

This project has been really nicely designed to be modular with separated middleware, but all of the middleware seems to be included by default. In express, koa and other frameworks all middleware is optional so you are free to add what you wish and use alternatives which allows for a rich ecosystem.

I suggest we define a middleware spec for express-openapi.

function myCoolMiddleware(apiDoc) {
    return function (req, res, next) {
        // Do stuff
        next();
    }
}

// or

function myCoolMiddleware(req, res, next) {
   const apiDoc = req.apiDoc;   
   // Do stuff
   next();
}

const openapiInstance = openapi.initialize({
});

openapiInstance.use(myCoolMiddleware);

// or

openapi.initialize({
    middleware: [myCoolMiddleware, express-openapi-defaults]
});
@DaleLJefferson DaleLJefferson changed the title Middleware should be opt in like express Middleware should be opt-in like express Mar 3, 2016
@jsdevel
Copy link
Contributor

jsdevel commented Mar 3, 2016

express-openapi has the notion of scoped middleware. Checkout https://github.com/kogosoftwarellc/express-openapi#supported-vendor-extensions.

You can accomplish what you want by doing this in your apiDoc:

'x-express-openapi-disable-middleware': true
'x-express-openapi-additional-middleware': [myCoolMiddleware, expressOpenapiDefaults]

The problem is that express-openapi-defaults directly depends on your operation doc, so it's almost necessary that it's baked in and managed with vendor extensions.

@jsdevel jsdevel closed this as completed Mar 3, 2016
@jsdevel
Copy link
Contributor

jsdevel commented Oct 18, 2018

FYI, koa-openapi is now ready.

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