Comments (6)
Thanks for reporting! Would you mind to share an example of what it is not working for you?
from fast-json-stringify.
Sure! Here's an exmaple:
const ajv = require("ajv")();
const server = require("fastify")();
ajv.setFormat("test", /[a-z]{24}/);
server.setSchemaCompiler(schema => ajv.compile(schema));
server.post("/", {
schema: {
response: {
"200": {
type: "object";
properties: {
test: {
type: "string",
format: "test"
}
}
}
}
}
}, async (req, res) => ({}));
server.listen();
Results in an error similar to:
I realise that it would have made more sense to open this on the main Fastify repository first, apologies! But as I was reading the code for Fastify I (think) I tracked it down to the fact that it uses this package to compile the response schemas.
from fast-json-stringify.
The problem is that this module is not used to validate the responses before sending them. It is used to render them. As such, it does not know anything about your format, it would in fact be totally ignored even if you pass it through. We use AJV to validate that your schema is valid JSON schema.
Passing in a custom AJV would remove the error, but it will just make that ignored.
from fast-json-stringify.
That makes sense, and I don't want any validation, I'd just like to be able to use a schema that I use in both the request and response (because they share the same data) but have the custom format ignored when it is used in the response.
I've realised that there is an alternative to passing in a custom Ajv instance but instead use the option unknownFormats: "ignore"
on the internal Ajv instance of this package, which would allow custom formats in the response schema but ignore them.
from fast-json-stringify.
I've realised that there is an alternative to passing in a custom Ajv instance but instead use the option unknownFormats: "ignore" instead which would allow custom formats in the response schema but ignore them.
I think we should add this to fast-json-stringify ajv config.
from fast-json-stringify.
Yes that's what I was thinking. 👍
I'll open a PR. Thanks for the quick responses. 😄
from fast-json-stringify.
Related Issues (20)
- Issue with custom keyword not working in fast-json-stringify HOT 11
- Response schema compiler generated validation code does not check for null values on optional object fields HOT 9
- lack of strictSchema in ajv options results in silent typos
- merged schema cache is messed up HOT 2
- emit CJS/ESM syntax in standalone mode based on AJV code options HOT 1
- When `asString` receives `undefined` an exception is thrown HOT 2
- Date coercion isn't supported by TypeScript types HOT 4
- allOf Schema and additionalProperties result in unexpected result HOT 10
- asStringSmall seem slower than JSON.stringify
- Fast json stringify vs JSON stringify HOT 3
- Release a new version with "merged" performance improvements HOT 2
- chunking/Readable stringify HOT 4
- Support of JSON Schema draft 8 (2019-09) HOT 3
- Date type is giving error - Error: schema is invalid: data/properties/updated_at/type must be equal to one of the allowed values HOT 4
- Release new version with improved performance
- JSON schema with single quote in property name fails to be processed when the property is required
- Ref error on recursive type (typebox) usage HOT 1
- validator.js in constructor validateSchema is always false and ajvOption overriden HOT 1
- bug: array input does not work (uncaught error) HOT 1
- Multiple fields with anyOf and self ref causes Maximum call stack size exceeded HOT 1
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 fast-json-stringify.