Comments (8)
You can get a JSON schema tutorial at https://json-schema.org/.
from fast-json-stringify.
I have generated but not working.
title: 'Listing Response Schema',
type: 'array',
items: {
type: 'object',
properties: {
id: {
type: 'string'
}
}
}
from fast-json-stringify.
There are several examles in https://github.com/fastify/fast-json-stringify/blob/master/test/array.test.js
from fast-json-stringify.
Yes i found them, but these examples are object array json, my example is different array object not supported ?
from fast-json-stringify.
Would you mind sending a PR with a failing unit test? Thanks.
(https://github.com/fastify/fast-json-stringify/blob/master/bench.js#L41 runs a benchmark for a very similar case)
from fast-json-stringify.
@mcollina I trying to pass an array of objects, but I'm only getting an empty array.
This is how the body schema looks like
body: {
type: "object",
properties: {
additionalImages: {
type: "array",
items: {
type: "object",
properties: {
url: { type: "string" },
name: { type: "string" },
},
},
},
},
from fast-json-stringify.
Could you add a Minimal, Reproducible Example?
Without it, we are unable to help you.
from fast-json-stringify.
Sure @Eomm , here it is
fastify.route({
method: "POST",
url: "/create",
schema: {
body: {
type: "object",
properties: {
roomName: { type: "string", minLength: 1 },
featuredImage: {
type: "object",
properties: {
url: { type: "string" },
name: { type: "string" },
},
},
additionalImages: {
type: "array",
items: {
type: "object",
properties: {
url: { type: "string" },
name: { type: "string" },
},
},
},
},
additionalProperties: false,
required: [
"roomName", "featuredImage",
],
},
response: {
201: {
type: "object",
properties: {
success: { type: "boolean" },
},
},
},
},
handler: async function (request, reply) {
client = await fastify.pg.connect();
const {
roomName,
featuredImage,
additionalImages,
}: any = request.body;
console.log(roomName); // Super deluxe room
console.log(featuredImage); // {url: "https://.............", name: "file.jpg"}
console.log(additionalImages); // []
// rest of irrelevant code
return reply.code(201).send({ success: true });
},
});
In the client, I passed values like this
const additionalImages= [{ url: "https://images.lib.com/.......", name: "hits1.jpg" }, { url: "https://images.lib.com/.......", name: "hits2.jpg" }, { url: "https://images.lib.com/.......", name: "hits3.jpg" }];
const featuredImage = { url: "https://images.lib.com/.......", name: "beats.jpg" };
const response = await fetch(
`${process.env.NEXT_PUBLIC_BASE_URL}/rooms/create`,
{
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
room_name: roomName,
additionalImages,
featuredImage,
}),
}
);
const result = await response.json();
from fast-json-stringify.
Related Issues (20)
- Recursive validation schema compiles but fails at runtime HOT 5
- error while resolving nested objects HOT 2
- `node:crypto` issues in Next.js HOT 7
- Tuple of date-time does not allow Date HOT 3
- 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
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.