Comments (8)
I suspect this is an unexpected side effect of #53 @erykwarren. :(
from exegesis.
(Also, thanks for the detailed error report!)
from exegesis.
🎉 This issue has been resolved in version 1.2.0 🎉
The release is available on:
Your semantic-release bot 📦🚀
from exegesis.
@jwalton Sorry for having introduced this bug :( . For what it is worth, swagger-tool did also parse the JSON to do the validation.
from exegesis.
from exegesis.
If the body is an object you could store it somewhere else before stringifying it and then validate that as an optimization.
from exegesis.
It's not quite that simple unfortunately. The thing that makes it complicated is that you can write a toJSON
function on an object that will control how it is serialized:
const foo = {toJSON() {return "bar";}};
JSON.stringify({foo}); // returns '{"foo":"bar"}'
We're using ajv
to do schema validation, and unfortunately it doesn't call into toJSON
for us. So if you try:
const Ajv = require('ajv');
const ajv = new Ajv();
const validate = ajv.compile({
type: 'object',
properties: {
myString: {type: "string"}
}
});
validate({myString: 'bar'}); // passes
validate({myString: foo}); // fails
And, at first glance, you might think "Why would anyone care about this weird esoteric feature of JSON stringifiers?" But, if you use MongoDB (as a lot of node.js folks do), ObjectId is an object, with a toJSON() that converts it into a string.
So if there's an object with a toJSON()
, we actually need to convert your response to JSON (or at least that object) and then parse it back before we can validate it. So we need to know ahead of time that you're not using any objects with toJSON()
, or we need to traverse the response tree and check to see if you have any objects with toJSON()
, or we need to give up and just do this for every response. :P
from exegesis.
You could do something like this (using lodash
for brevity):
_.cloneDeepWith(body, (value, key) => {
if ('toJSON' in value && _.isFunction(value.toJSON)) {
return value.toJSON(key);
}
return undefined;
}
Question is of course, if this will be faster than serializing/deserializing and up to what size.
Maybe just not worth the hassle.
from exegesis.
Related Issues (20)
- Validation error of request body when oneOf is used HOT 5
- Crash with recursive definition in referenced OpenAPI file is back again
- Does not work well with newest json-ptr (1.3.1) HOT 2
- Your .dependabot/config.yml contained invalid details HOT 1
- Export class from controller HOT 2
- Could not find controller if controller is a .ts file HOT 2
- Can we access "ExegesisContext" at express middleware(app.use) not controllers/*.ts HOT 1
- How to filter the request body by only passing the defined requestBody schema? HOT 2
- Security vulnerability in `json-ptr` HOT 4
- Exegesis 3.0.0 using updated ajv outputs issues with OpenAPI spec, but 2.0.0 did not HOT 5
- res.redirect not supported HOT 3
- Is OpenAPI 3.1 supported?
- Bump json-ptr to fix security vulnerability HOT 1
- Support for additional string formats HOT 2
- json-schema-ref-parser dependency breaks node engine < 17 HOT 3
- How to use exegesis with multipart/form-data?
- Mime-types HOT 2
- Query parameters not being validated. HOT 1
- Loading is too slow due to schema compilation HOT 2
- Skip/bypass response validation HOT 2
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 exegesis.