question-mark

Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Router middleware to dispatch based on operationId

See original GitHub issue

Issue Description

It would be nice to have a router middleware that would simplify the creation of handlers for methods based on the operationId.

The idea would be as follows.

Based on the following snippet

/pets:
    get:
      summary: List all pets
      operationId: listPets

one would create an object and use something like the following snippet to create the router.

var petrouter = {
    listPets: function(req, res, next) {
        // Do something
    }
};
app.use(middleware.router(petrouter));

Instead of having to the the following for ever method defined in the specification file

app.patch('/pets', function(req, res, next) { 
    // Do something
});

The advantage I see would be that the redundancy between what method to use (GET, PUT, …) and the exact path specification could be avoided. The only thing that maps between the swagger spec and the implementation is the operationId.

What do you think? Would this be a sensible enhancement?

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
JonnyWafflescommented, Nov 2, 2018

I too would like to know if this is a part of the swagger-express-middleware. The documentation is unclear as to how you bind operationId names to functions. The sample projects don’t see to even have js functions mapping the operationId in the YAML, so I’m not entirely sure how to wire any any of this up.

0reactions
nemanicommented, Oct 26, 2018

Is this a part of swagger-express-middleware or not?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Adding route specific middleware? · Issue #291 - GitHub
In standard express speak, I'd have had a route middleware on the user ... operationId: post parameters: - in: body name: body description: ......
Read more >
Path Operation Advanced Configuration - FastAPI
You can set the OpenAPI operationId to be used in your path operation with the parameter operation_id . You would have to make...
Read more >
How to dispatch an action when clicking on Link when using ...
So I'm thinking of a way to render based on the state whether its on edit-mode or delete-mode etc. javascript · reactjs ·...
Read more >
Express Tutorial Part 4: Routes and controllers - MDN Web Docs
Router middleware as it allows us to group the route handlers for a particular part of a site together and access them using...
Read more >
Chapter 5. Middleware - Redux in Action - liveBook · Manning
Redux middleware is code that sits between an action being dispatched and the store passing the action to the reducer and broadcasting the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found