lukeed / polka

A micro web server so fast, it'll make you dance! :dancers:
MIT License
5.39k stars 172 forks source link

OpenAPI Integration #130

Open Dindaleon opened 4 years ago

Dindaleon commented 4 years ago

Is it possible to have a swagger plugin for polka? Or maybe an alternative...

lukeed commented 4 years ago

Yes, there will be an OpenAPI integration, but not as part of 1.0.

I can't tell if it makes sense as a plugin or if it should be a larger framework that builds upon Polka. I'm leaning towards the latter because in order for OpenAPI to make sense (and work) it has to be strictly implemented.

jgod commented 3 years ago

A first step could be getting a "plugin" (PR) for https://github.com/PayU/openapi-validator-middleware, which already supports express, koa, and fastify. It looks like we're missing req.baseUrl and req.route.path that it relies on from express, whenever I try to just import it and use it in express-mode.

Something like this to make it compatible:

function reqEnhancer(req, res, next) {
  req.baseUrl = "";
  req.route = {
    path: req.path,
  };
  next();
}
jgod commented 3 years ago

(I have that library working with this setup)