Comments (3)
The problem seems to come from the interception of the res.send function done in oas-validator.js
, line 102
/* Intercepts response */
const oldSend = res.send;
res.send = function send(data) {
// here, data parameter can be either object or string
...
}
The data
parameter can either be of type object
or string
, depending on the way the response is generated:
- when using
res.send(object)
, data will be anobject
- when using
res.json(object)
, data will be a JSON encodedstring
It seems that there is not enough information in the current interceptor to differenciate these cases. Testing if data
looks like a JSON encoded string is not a solution because someone could want to use res.send()
to send an already JSON encoded string.
Intercepting also the res.json
method in oas-validator.js
seems to be tricky, because the original res.send
from Express calls res.json
internally in some cases, and res.json
calls res.send
internally too...
In my opinion, the interception should be made at a lower level, to avoid these problems. The interception itself could be made with an external library, such as express-interceptor. Using a low-level interceptor also has the benefit to allow more use cases of response generation, such as calling res.write()
directly.
from oas-tools.
Hello, Mick, I agree with what you say about intercepting responses at a lower level. Ideally, it is the res.write( )
method what should be overriden, since it is what writes the data to the stream before calling res.end( )
. I'll study how express-interceptor works and try to fix that.
from oas-tools.
Hey, any news about this?
from oas-tools.
Related Issues (20)
- How to use http query params with oas tools? HOT 3
- @oas-tools/core typescript support HOT 9
- [Suggestion] Change middleware chain order (Swagger UI not working) HOT 4
- [BUG] Dynamic routes have higher priority over static routes HOT 6
- [BUG] oas tool 3.0 fail to treat optional field in schema as option. HOT 9
- [BUG] V3 Not Backwards Compatible with V2 JSON Specification File Code HOT 1
- [BUG] Cannot convert undefined or null to object oas param file has issue HOT 2
- [BUG] File spec loading error in legacy project HOT 2
- oas tools module import issue when doing tests with jest. HOT 9
- Align js-yaml version with @oas-tools/commons HOT 1
- [BUG] oneof yaml specification is not valid json HOT 1
- [Question]: Controller & Service file naming convention HOT 2
- [SUGGESTION] Problem with default exports "Controller X does not have method Y" HOT 1
- [BUG] customHandler for errors is not working as expected HOT 2
- Basepath is removed when calling any endpoint on google cloud functions. HOT 1
- [SUGESTION] Add support for mutualTLS security handler HOT 1
- The Controller annotation requires empty line be placed after the annotation
- [BUG] Invalid JSON in params results in Internal Server Error instead of Bad Request
- [SUGESTION] Remove check of multiple http security schemes
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 oas-tools.