-
Notifications
You must be signed in to change notification settings - Fork 31
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
express.Router with with two methods on one path does not display middleswares list correctly #81
Comments
Just as one example of what could be done: Changing the const addEndpoints = function (currentEndpoints, endpointsToAdd) {
// endpointsToAdd.forEach((newEndpoint) => {
// const existingEndpoint = currentEndpoints.find(
// (item) => item.path === newEndpoint.path
// )
//
// if (existingEndpoint !== undefined) {
// const newMethods = newEndpoint.methods.filter(
// (method) => !existingEndpoint.methods.includes(method)
// )
//
// existingEndpoint.methods = existingEndpoint.methods.concat(newMethods)
// } else {
// currentEndpoints.push(newEndpoint)
// }
// })
currentEndpoints.push(...endpointsToAdd);
return currentEndpoints
} We would than have the following output: [
{
path: '/users',
methods: [ 'GET' ],
middlewares: [ 'authorize', 'listUsers' ]
},
{
path: '/users',
methods: [ 'POST' ],
middlewares: [ 'authorize', 'createUser' ]
},
{
path: '/users/:id',
methods: [ 'GET' ],
middlewares: [ 'authorize', 'getUserById' ]
},
{
path: '/teams',
methods: [ 'GET' ],
middlewares: [ 'authorize', 'listUsers' ]
},
{
path: '/teams',
methods: [ 'POST' ],
middlewares: [ 'authorize', 'createUser' ]
},
{
path: '/teams/:id',
methods: [ 'GET' ],
middlewares: [ 'authorize', 'getUserById' ]
}
] |
Thank for taking your time in documenting this. I agree with you, but I'm not sure about the output format (that is something that has bugged me for quite a while). I agree that we need to change the output but it will be a breaking change. My proposal for the structure is to use the same structure that OpenApi v3.1 uses for documenting an API (avoiding to use names or verbs for the keys in order to keep the contracts to be iterable):
|
@AlbertoFdzM I'm very interested in getting this fixed. As it stands, this is more of a "get all routes" and not "get all endpoints" module. At least if you care about getting the list of middleware. But this module is also downloaded a lot, and it makes sense to me to fix this instead of creating another branch. Since this is a breaking change, moving to a v7 seems like a good move. But it seems like it should be easy enough to get done. It looks like migonos0 already created a working solution, though I've not verified it personally. If you want help adjusting the tests, I'm happy to do that. Edit: I don't want to jump in on this if you are no longer maintaining the repo, so that's why I asked first. |
Please check the following example to understand better what I do mean by the title of this issue.
The response would be the following:
In the first endpoint, we have the path
/users
, with the methodsGET
andPOST
. That is correct.Now, the middlewares list is incorrect: we should also have
createUser
added in the list.I would have two suggestions as a possibility:
Thank you for the time for reading this issue, and please leave any comment if you have any questions.
The text was updated successfully, but these errors were encountered: