Comments (10)
I would love to have the feedback of @grahamj, @BigstickCarpet and others.
from swagger-tools.
Are you saying that swaggerMetadata should overwrite req.params
?
from swagger-tools.
I'm asking your opinion on the matter. Long story short, I namespaced the parameters swaggerMetadata processed to req.swagger.params
just so I didn't muck with req.params
. I've gotten some feedback that this could be a little unintuitive and so I wanted to get some feedback on it. What are your thoughts right now about this?
from swagger-tools.
Ah, ok. Thanks for the clarification. I actually like the way it is now. For a few reasons:
- Everything else that swaggerMetadata adds to
req
is namespaced underreq.swagger
, so this is consistent behavior. The docs pretty clearly point this out, so IMHO, RTFM. - Modifying
req.params
directly could break other middleware. By namespacing all of swaggerMetadata's stuff underreq.swagger
, you're guaranteed to play nice with other middleware. - If people really want the Swagger params directly on the
req
object, then they can easily add this snippet to their app:
app.use(function(req, res, next) {
if (req.swagger.params)
req.params = req.swagger.params;
next();
});
from swagger-tools.
+1
from swagger-tools.
Ok so I was the one who suggested it to Jeremy from an "outsider" perspective. My take was that it's one less thing for me to think when I am in controllers since I am so used to req.blah for requests in regular node app.
Coming from Java background, I was thinking something equivalent to:
import swagger.request;
var p = request.params;
from swagger-tools.
I can definitely see why it would be desirable to have Swagger's param data directly at req.params
, but the main issue is that it would break any middleware that expects the "normal" req.params
object. Since swagger-tools needs to work for a variety of different use-cases, it really needs to play nice with other middleware.
That said, if you're not using any other third-party middleware that relies on req.params
, then it's totally safe for you to use the middleware snippet that I posted above, which will overwrite req.params
with the Swagger param data
from swagger-tools.
Cool. @whitlockjc I think it can be closed then.
from swagger-tools.
I know this is coming in late, but I thought I would offer a bit more feedback:
- Swagger-tools utilizes tools to set req.query and req.body, but it avoids req.params? Seems like it's breaking the pattern...
- Node Express prevents modifying the req.params with middleware, so the suggestion by BigstickCarpet to add middleware would not work.
- I think a simple solution would be to modify swagger-router.js to add:
var swaggerParamsToParams = function(req){
_.forEach(req.swagger.params, function(param, key){
if (param.schema.in === 'path')
req.params[key] = param.value;
})
}
just before calling the handler. That wouldn't break any middleware, but it would also allow the use of the more common req.params variable
from swagger-tools.
-
swagger-tools does nothing of the sort regarding
req.body
orreq.query
. The server middleware is responsible for these things. And while swagger-tools provides default middleware for you so things just work, it's up to you to own this if need be.req.swagger
is the only object swagger-tools creates/manipulates -
swagger-tools does not alter
req.params
-
I don't know that we have a problem here so the solution doesn't make much sense to me
from swagger-tools.
Related Issues (20)
- Error: Response validation failed: void does not allow a value
- update lodash HOT 1
- request/response body schema referenced in swagger is not getting validating
- Swagger Error: Not a valid parameter definition for Multi part file type
- middleware swaggerSecurity unable to access res object HOT 1
- swagger-tools app not logging http requests to console
- Swagger ui with a reverse proxy - apiDocsPrefix not in use
- swagger tools typescript Controller issue
- swagger-tools does not support with webpack HOT 1
- Swagger-tools express 5.x support
- Doesn't work with type module in package.json
- $ref url encoding issue
- how to overwrite multer storage engine used in SwaggerMetaData - HELP!
- swagger 3.0? HOT 2
- Array items validation is not getting picked by swagger-codegen-maven-plugin 2.4.5
- How/Where does swagger route urls to swagger.json paths ?
- Is there an example of how to use supertest with swagger-tools?
- Vulnerability in validator package HOT 6
- Vulnerability in dicer package HOT 1
- Create New issue
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from swagger-tools.