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.

Alterative route declaration

See original GitHub issue

The only thing I don’t like about express-openapi is the “convention based programming”, I found very confusing and limiting.

I would prefer a simple javascript api doc with embedded handlers.

openapi.initialize({
    app: app,
    swagger: '2.0',
    basePath: '/v1',
    info: {
        title: 'App',
        version: '1.0.0',
    },
    paths: {
        '/users': {
            get: {
                parameters: [],
                responses: {
                    200: {
                        description: 'Get all users',
                        schema: {
                            type: 'array',
                            items: {
                                title: 'User',
                                type: 'object',
                                properties: {
                                    name: {
                                        type: 'string'
                                    }
                                }
                            },
                        }
                    }
                },
                handler(req, res) {
                    res.json([{name: 'Dale'}]);
                }
            },
            post: {
                handler(req, res) {
                    res.status(201);
                }
            }
        },
        '/users/{userId}': {
            get: {
                handler(req, res) {
                    res.json({name: 'Dale'});
                }
            }
        }
    }
});

You can use modules to split up the code, you have the full javascript language to generate routes or do whatever you like.

openapi.initialize({
    app: app,
    swagger: '2.0',
    basePath: '/v1',
    info: {
        title: 'App',
        version: '1.0.0',
    },
    paths: {
        '/users': require('./routes/users'),
        '/messages': {
            'get': require('./routes/messages').get
        },
        '/books': createCrudEndpoints("Books"),
        ...require('./lotsOfEndpointsUsingSpread')
    }
});

The existing convention based system could be used to build this structure internally.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:1
  • Comments:13 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
mika-fischercommented, Oct 17, 2016

Yes, that also sounds fine, I’ll see if I can implement this this week.

1reaction
jsdevelcommented, Mar 21, 2016

Re-opening as express-openapi should aim to be as un-opinionated as possible to follow express’s purpose Fast, unopinionated, minimalist web framework for Node.js.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Alternate route - Wikipedia
Alternate routes were created as a means of connecting a town (or towns) desired to be on a route that had been routed...
Read more >
Certificate Pathways & Routes - Florida Department of Education
Florida offers a number of traditional and alternative educator preparation routes that lead to full Professional certification. Some routes are direct ...
Read more >
Couldn't find a route declaration in src/app/app ... - GitHub
fix steps: add a routes declaration : image. then you can run. ng g @scullyio/init:blog. or. ng generate @scullyio/init:markdown ...
Read more >
Road manager - proposing an alternate route | NHVR
Plot the alternate route using the mapping tool within the NHVR Portal under the 'ROUTE MANAGEMENT' tab. Refer to the Route Planner page...
Read more >
Common Routing Tasks - Angular
This topic describes how to implement many of the common tasks associated with adding the Angular router to your application.
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