Something went wrong. Try again.
プレイグラウンド、サンドボックス、使い捨てスクリプト置き場
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107#!/usr/bin/env -S deno run -Aimport fastify from "npm:fastify";// import { parse as jsonParse } from "npm:secure-json-parse";
const server = fastify({ logger: true });
server.get("/anyOf", { schema: { querystring: { type: "object", properties: { array: { anyOf: [ { type: "array", items: { type: "string" } }, { type: "string" }, ], }, }, required: ["array"], }, }, handler({ query }) { console.log({ ...query }); return "ok"; },});
server.get("/oneOf", { schema: { querystring: { type: "object", properties: { array: { oneOf: [ { type: "array", items: { type: "string" } }, { type: "string" }, ], }, }, required: ["array"], }, }, handler({ query }) { console.log({ ...query }); return "ok"; },});
// validawait server.inject(`/anyOf?array=a`);
// invalid: querystring/array must match exactly one schema in oneOfawait server.inject(`/oneOf?array=a`);
/*server.get("/array", { schema: { querystring: { type: "object", properties: { array: { type: "array", items: { type: "string" } } }, required: ["array"], }, }, async preValidation(req) { req.query.array = [req.query.array].flat().flatMap((s) => { try { const parsed = jsonParse(s); return Array.isArray(parsed) ? parsed : [s]; } catch { return [s]; } }); }, handler({ query }) { console.log({ ...query }); return "ok"; },});
// validawait server.inject(`/array?array=["123",4]`);*/
/*server.get("/dateTime", { schema: { querystring: { type: "object", properties: { dateTime: { type: "string", format: "date-time" } }, required: ["dateTime"], }, }, handler() { return "ok"; },});
// validawait server.inject("/dateTime?dateTime=2021-09-10T15:30:00Z");
// valid: fasitfy@4.22.2, invalid fastify@5.1.0: querystring/dateTime must match format "date-time"await server.inject("/dateTime?dateTime=2021-09-10T15:30:00");
// invalid: querystring/dateTime must match format "date-time"await server.inject("/dateTime?dateTime=2021-09-10");*/