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

library is not picking up the paths in my express application #30

Open
jamesone opened this issue May 2, 2022 · 6 comments
Open

library is not picking up the paths in my express application #30

jamesone opened this issue May 2, 2022 · 6 comments

Comments

@jamesone
Copy link

jamesone commented May 2, 2022

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

@wesleytodd
Copy link
Owner

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? #20

@wesleytodd
Copy link
Owner

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.

@Megapixel99
Copy link
Collaborator

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

@wesleytodd
Copy link
Owner

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?

@Megapixel99
Copy link
Collaborator

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

@wesleytodd
Copy link
Owner

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

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

3 participants