library is not picking up the paths in my express application
My openapi.helper.ts file (which is located in: src/helpers/:
import oapi from '@wesleytodd/openapi';
const openapi = oapi({
openapi: '1.0.0',
info: {
title: 'Rest Docs',
version: '1.0.0',
description: 'Rest description,
},
});
export default openapi;
Then inside my express app configuration file located in: src/app.ts, I am passing the openapi export to the app.use:
Note my routes are on
v1/
app.use('/v1/', routes);
app.use(openapi);
I also tried:
app.use('/v1/', openapi, routes);
I also tried adding adding openapi to my routes export. routes.use(openapi) but it still couldn't pick up the paths, like so:
routes.ts:
routes.use(`/myrouter`, openapi, farmRouter);
When trying to visit the <path>/openapi.json, it always returns an empty 'paths' object.
{
"openapi": "1.0.0",
"info": {
title: 'Rest Docs',
version: '1.0.0',
description: 'Rest description,
},
"paths": {}
}
The libs I am using are:
I am using nodejs 16 & "express": "^4.17.1",, "@wesleytodd/openapi": "^0.1.0",
Hey! At first glance this looks like a known issue with nested groups (IIRC it was nested routers). I dont think I see you post what routes looks like, is it a Router instance? Does it look like the same as this one? https://github.com/wesleytodd/express-openapi/issues/20
Hey @jamesone, are you still experienceing this issue? Any chance you could look and see if it was the same issue? We are going to work toward a 1.0.0 for this package soon and I would like to fix this if we can get confirmation about the behavior which is broken.
I ran into this issue early on too, it's similar to issue #20 but placing app.use(openapi); above all other app.use statements fixed the issue for me.
For example:
app.use('/v1/', routes);
app.use(openapi);
Should be:
app.use(openapi);
app.use('/v1/', routes);
Ah, I wonder if we need docs for this? Or do we think we should support any order for adding these and then call this a bug?
@wesleytodd I think that is up to you. I assumed placing app.use(openapi); was the intended way to use the module but if you want to support adding them in any order that is fine too.
Yeah, I am. not sure the best approach. How about we just leave this open for now, and when one of us get's to it (or we hear back) we can add tests around this behavior and decide from there what the best "fix" would be (docs or code).