express-openapi icon indicating copy to clipboard operation
express-openapi copied to clipboard

library is not picking up the paths in my express application

Open jamesone opened this issue 3 years ago • 6 comments

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",

jamesone avatar May 02 '22 00:05 jamesone

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

wesleytodd avatar May 11 '22 19:05 wesleytodd

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.

wesleytodd avatar Nov 02 '23 15:11 wesleytodd

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);

Megapixel99 avatar Nov 03 '23 15:11 Megapixel99

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 avatar Nov 03 '23 16:11 wesleytodd

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

Megapixel99 avatar Nov 06 '23 16:11 Megapixel99

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

wesleytodd avatar Nov 06 '23 17:11 wesleytodd