Alterative route declaration
See original GitHub issueThe 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:
- Created 8 years ago
- Reactions:1
- Comments:13 (11 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Yes, that also sounds fine, I’ll see if I can implement this this week.
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
.