@zuplo/cli 6.71.22 → 6.71.25
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/node_modules/@fastify/fast-json-stringify-compiler/.github/dependabot.yml +42 -2
- package/node_modules/@fastify/fast-json-stringify-compiler/.github/workflows/ci.yml +6 -1
- package/node_modules/@fastify/fast-json-stringify-compiler/.github/workflows/lock-threads.yml +19 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/LICENSE +1 -1
- package/node_modules/@fastify/fast-json-stringify-compiler/README.md +1 -1
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/.gitattributes +2 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/.github/dependabot.yml +13 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/.github/workflows/ci.yml +33 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/.github/workflows/lock-threads.yml +19 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/LICENSE +22 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/README.md +742 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/benchmark/bench-cmp-branch.js +116 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/benchmark/bench-cmp-lib.js +339 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/benchmark/bench-thread.js +33 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/benchmark/bench.js +391 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/build/build-schema-validator.js +26 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/eslint.config.js +9 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/examples/example.js +81 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/examples/server.js +42 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/index.js +1308 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/lib/location.js +24 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/lib/merge-schemas.js +9 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/lib/schema-validator.js +1134 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/lib/serializer.js +141 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/lib/standalone.js +34 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/lib/validator.js +96 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/package.json +89 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/additionalProperties.test.js +332 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/allof.test.js +751 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/any.test.js +231 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/anyof.test.js +812 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/array.test.js +688 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/asNumber.test.js +13 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/basic.test.js +400 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/bigint.test.js +76 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/clean-cache.test.js +47 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/const.test.js +314 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/date.test.js +639 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/debug-mode.test.js +130 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/defaults.test.js +376 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/enum.test.js +37 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/fix-604.test.js +25 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/fixtures/.keep +0 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/if-then-else.test.js +540 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/inferType.test.js +92 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/infinity.test.js +55 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/integer.test.js +194 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/invalidSchema.test.js +38 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/issue-479.test.js +57 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/issue-793.test.js +107 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/issue-794.test.js +177 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/issue-836.test.js +183 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/json-add-comma.test.js +57 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/json-schema-test-suite/README.md +10 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/json-schema-test-suite/draft4/required.json +54 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/json-schema-test-suite/draft4.test.js +12 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/json-schema-test-suite/draft6/required.json +70 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/json-schema-test-suite/draft6.test.js +12 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/json-schema-test-suite/draft7/required.json +70 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/json-schema-test-suite/draft7.test.js +12 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/json-schema-test-suite/util.js +31 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/missing-values.test.js +88 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/multi-type-serializer.test.js +19 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/nestedObjects.test.js +63 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/nullable.test.js +543 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/oneof.test.js +510 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/patternProperties.test.js +168 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/recursion.test.js +245 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/ref.json +12 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/ref.test.js +2077 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/regex.test.js +32 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/required.test.js +204 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/requiresAjv.test.js +50 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/sanitize.test.js +141 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/sanitize2.test.js +18 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/sanitize3.test.js +17 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/sanitize4.test.js +16 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/sanitize5.test.js +16 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/sanitize6.test.js +22 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/sanitize7.test.js +68 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/side-effect.test.js +196 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/standalone-mode.test.js +219 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/string.test.js +84 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/surrogate.test.js +67 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/toJSON.test.js +203 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/typebox.test.js +36 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/typesArray.test.js +550 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/unknownFormats.test.js +27 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/webpack.test.js +50 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/types/index.d.ts +219 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/types/index.tst.ts +259 -0
- package/node_modules/@fastify/fast-json-stringify-compiler/package.json +6 -11
- package/node_modules/@fastify/fast-json-stringify-compiler/types/{index.test-d.ts → index.tst.ts} +34 -32
- package/node_modules/@posthog/core/dist/posthog-core-stateless.d.ts +5 -0
- package/node_modules/@posthog/core/dist/posthog-core-stateless.d.ts.map +1 -1
- package/node_modules/@posthog/core/dist/posthog-core-stateless.js +50 -10
- package/node_modules/@posthog/core/dist/posthog-core-stateless.mjs +47 -10
- package/node_modules/@posthog/core/dist/posthog-core.d.ts +2 -2
- package/node_modules/@posthog/core/dist/posthog-core.d.ts.map +1 -1
- package/node_modules/@posthog/core/dist/posthog-core.js +10 -6
- package/node_modules/@posthog/core/dist/posthog-core.mjs +11 -7
- package/node_modules/@posthog/core/dist/testing/PostHogCoreTestClient.d.ts +1 -0
- package/node_modules/@posthog/core/dist/testing/PostHogCoreTestClient.d.ts.map +1 -1
- package/node_modules/@posthog/core/dist/testing/PostHogCoreTestClient.js +3 -0
- package/node_modules/@posthog/core/dist/testing/PostHogCoreTestClient.mjs +3 -0
- package/node_modules/@posthog/core/dist/utils/promise-queue.d.ts +3 -0
- package/node_modules/@posthog/core/dist/utils/promise-queue.d.ts.map +1 -1
- package/node_modules/@posthog/core/dist/utils/promise-queue.js +15 -3
- package/node_modules/@posthog/core/dist/utils/promise-queue.mjs +15 -3
- package/node_modules/@posthog/core/package.json +1 -1
- package/node_modules/@posthog/core/src/posthog-core-stateless.ts +80 -14
- package/node_modules/@posthog/core/src/posthog-core.ts +18 -7
- package/node_modules/@posthog/core/src/testing/PostHogCoreTestClient.ts +4 -0
- package/node_modules/@posthog/core/src/utils/promise-queue.ts +17 -4
- package/node_modules/@posthog/types/dist/posthog.d.ts +12 -0
- package/node_modules/@posthog/types/dist/posthog.d.ts.map +1 -1
- package/node_modules/@posthog/types/package.json +1 -1
- package/node_modules/@posthog/types/src/posthog.ts +13 -0
- package/node_modules/@protobufjs/utf8/CHANGELOG.md +8 -0
- package/node_modules/@protobufjs/utf8/index.js +29 -18
- package/node_modules/@protobufjs/utf8/package.json +2 -2
- package/node_modules/@protobufjs/utf8/tests/index.js +5 -0
- package/node_modules/@types/node/README.md +1 -1
- package/node_modules/@types/node/buffer.d.ts +64 -25
- package/node_modules/@types/node/crypto.d.ts +18 -5
- package/node_modules/@types/node/diagnostics_channel.d.ts +237 -3
- package/node_modules/@types/node/dns.d.ts +1 -1
- package/node_modules/@types/node/ffi.d.ts +486 -0
- package/node_modules/@types/node/fs/promises.d.ts +3 -0
- package/node_modules/@types/node/fs.d.ts +21 -6
- package/node_modules/@types/node/http.d.ts +25 -0
- package/node_modules/@types/node/index.d.ts +1 -0
- package/node_modules/@types/node/package.json +2 -2
- package/node_modules/@types/node/process.d.ts +14 -1
- package/node_modules/@types/node/quic.d.ts +92 -11
- package/node_modules/@types/node/sqlite.d.ts +55 -0
- package/node_modules/@types/node/stream/iter.d.ts +150 -0
- package/node_modules/@types/node/stream.d.ts +32 -0
- package/node_modules/@types/node/test.d.ts +112 -2
- package/node_modules/@types/node/ts5.6/index.d.ts +1 -0
- package/node_modules/@types/node/ts5.7/index.d.ts +1 -0
- package/node_modules/@types/node/util.d.ts +19 -2
- package/node_modules/@types/node/v8.d.ts +84 -2
- package/node_modules/@types/node/worker_threads.d.ts +8 -7
- package/node_modules/@zuplo/core/package.json +1 -1
- package/node_modules/@zuplo/graphql/out/esm/index.js +11 -11
- package/node_modules/@zuplo/graphql/out/esm/index.js.map +1 -1
- package/node_modules/@zuplo/graphql/package.json +1 -1
- package/node_modules/@zuplo/openapi-tools/package.json +1 -1
- package/node_modules/@zuplo/otel/package.json +1 -1
- package/node_modules/@zuplo/runtime/out/esm/{chunk-54PA7VDV.js → chunk-4QJJMELB.js} +1 -1
- package/node_modules/@zuplo/runtime/out/esm/{chunk-54PA7VDV.js.map → chunk-4QJJMELB.js.map} +1 -1
- package/node_modules/@zuplo/runtime/out/esm/chunk-MJWTZPC2.js +402 -0
- package/node_modules/@zuplo/runtime/out/esm/chunk-MJWTZPC2.js.map +1 -0
- package/node_modules/@zuplo/runtime/out/esm/index.js +1 -1
- package/node_modules/@zuplo/runtime/out/esm/index.js.map +1 -1
- package/node_modules/@zuplo/runtime/out/esm/mcp-gateway/index.js +7 -7
- package/node_modules/@zuplo/runtime/out/esm/mcp-gateway/index.js.map +1 -1
- package/node_modules/@zuplo/runtime/out/esm/mocks/index.js +1 -1
- package/node_modules/@zuplo/runtime/out/types/index.d.ts +263 -19
- package/node_modules/@zuplo/runtime/out/types/mcp-gateway/index.d.ts +33 -7
- package/node_modules/@zuplo/runtime/package.json +1 -1
- package/node_modules/hono/dist/adapter/aws-lambda/handler.js +1 -1
- package/node_modules/hono/dist/adapter/bun/websocket.js +3 -1
- package/node_modules/hono/dist/cjs/adapter/aws-lambda/handler.js +1 -1
- package/node_modules/hono/dist/cjs/adapter/bun/websocket.js +3 -1
- package/node_modules/hono/dist/cjs/middleware/serve-static/index.js +1 -1
- package/node_modules/hono/dist/cjs/utils/body.js +12 -4
- package/node_modules/hono/dist/cjs/utils/buffer.js +2 -1
- package/node_modules/hono/dist/cjs/validator/validator.js +3 -3
- package/node_modules/hono/dist/middleware/serve-static/index.js +1 -1
- package/node_modules/hono/dist/types/middleware/context-storage/index.d.ts +2 -2
- package/node_modules/hono/dist/types/utils/body.d.ts +1 -1
- package/node_modules/hono/dist/utils/body.js +12 -4
- package/node_modules/hono/dist/utils/buffer.js +2 -1
- package/node_modules/hono/dist/validator/validator.js +3 -3
- package/node_modules/hono/package.json +8 -7
- package/node_modules/iconv-lite/encodings/sbcs-data.js +2 -0
- package/node_modules/iconv-lite/encodings/utf32.js +10 -3
- package/node_modules/iconv-lite/package.json +2 -2
- package/node_modules/iconv-lite/types/encodings.d.ts +2 -0
- package/node_modules/protobufjs/dist/light/protobuf.js +2 -2
- package/node_modules/protobufjs/dist/light/protobuf.min.js +2 -2
- package/node_modules/protobufjs/dist/minimal/protobuf.js +2 -2
- package/node_modules/protobufjs/dist/minimal/protobuf.min.js +2 -2
- package/node_modules/protobufjs/dist/protobuf.js +5 -2
- package/node_modules/protobufjs/dist/protobuf.js.map +1 -1
- package/node_modules/protobufjs/dist/protobuf.min.js +3 -3
- package/node_modules/protobufjs/dist/protobuf.min.js.map +1 -1
- package/node_modules/protobufjs/package.json +1 -1
- package/node_modules/protobufjs/src/parse.js +3 -0
- package/node_modules/toad-cache/README.md +10 -9
- package/node_modules/toad-cache/dist/toad-cache.cjs +139 -139
- package/node_modules/toad-cache/dist/toad-cache.mjs +136 -140
- package/node_modules/toad-cache/package.json +8 -8
- package/node_modules/toad-cache/toad-cache.d.cts +20 -14
- package/node_modules/toad-cache/toad-cache.d.ts +18 -14
- package/package.json +6 -6
- package/node_modules/@fastify/fast-json-stringify-compiler/.eslintrc +0 -1
- package/node_modules/@zuplo/runtime/out/esm/chunk-36XLJ4X6.js +0 -389
- package/node_modules/@zuplo/runtime/out/esm/chunk-36XLJ4X6.js.map +0 -1
- package/node_modules/hono/dist/tsconfig.build.tsbuildinfo +0 -1
- /package/node_modules/@zuplo/runtime/out/esm/{chunk-36XLJ4X6.js.LEGAL.txt → chunk-MJWTZPC2.js.LEGAL.txt} +0 -0
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const { test } = require('node:test')
|
|
4
|
+
const build = require('..')
|
|
5
|
+
|
|
6
|
+
test('external $ref schema should be reused, not inlined at every reference', (t) => {
|
|
7
|
+
t.plan(3)
|
|
8
|
+
|
|
9
|
+
const contactSchema = {
|
|
10
|
+
$id: 'contact.json',
|
|
11
|
+
type: 'object',
|
|
12
|
+
properties: {
|
|
13
|
+
firstName: { type: 'string' },
|
|
14
|
+
lastName: { type: 'string' },
|
|
15
|
+
email: { type: 'string' }
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// Schema referencing the same external $ref multiple times
|
|
20
|
+
const parentSchema = {
|
|
21
|
+
type: 'object',
|
|
22
|
+
properties: {
|
|
23
|
+
owner: { $ref: 'contact.json' },
|
|
24
|
+
assignee: { $ref: 'contact.json' },
|
|
25
|
+
reporter: { $ref: 'contact.json' }
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const serializer = build(parentSchema, { schema: { 'contact.json': contactSchema } })
|
|
30
|
+
const code = serializer.toString()
|
|
31
|
+
|
|
32
|
+
// The serialized function should contain extracted anonymous functions
|
|
33
|
+
// rather than inlining the full contact schema at every reference.
|
|
34
|
+
// With the fix, `firstName` appears 0 times in the main serializer body
|
|
35
|
+
// (it is inside the extracted function, which is not included in .toString())
|
|
36
|
+
// or at most 1 time if in a single extracted function.
|
|
37
|
+
const firstNameMatches = code.match(/firstName/g)
|
|
38
|
+
t.assert.ok(firstNameMatches === null || firstNameMatches.length <= 1,
|
|
39
|
+
`firstName should appear at most once (extracted function), got ${firstNameMatches ? firstNameMatches.length : 0}`)
|
|
40
|
+
|
|
41
|
+
// Verify correct serialization
|
|
42
|
+
const data = {
|
|
43
|
+
owner: { firstName: 'John', lastName: 'Doe', email: 'john@example.com' },
|
|
44
|
+
assignee: { firstName: 'Jane', lastName: 'Smith', email: 'jane@example.com' },
|
|
45
|
+
reporter: { firstName: 'Bob', lastName: 'Jones', email: 'bob@example.com' }
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const output = serializer(data)
|
|
49
|
+
t.assert.doesNotThrow(() => JSON.parse(output))
|
|
50
|
+
t.assert.equal(output, JSON.stringify(data))
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
test('external $ref schema reused with anyOf wrapping', (t) => {
|
|
54
|
+
t.plan(2)
|
|
55
|
+
|
|
56
|
+
const contactSchema = {
|
|
57
|
+
$id: 'contact.json',
|
|
58
|
+
type: 'object',
|
|
59
|
+
properties: {
|
|
60
|
+
firstName: { type: 'string' },
|
|
61
|
+
lastName: { type: 'string' },
|
|
62
|
+
email: { type: 'string' }
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// Common pattern: anyOf wrapping $ref for polymorphic fields (populated object OR string ID OR null)
|
|
67
|
+
const parentSchema = {
|
|
68
|
+
type: 'object',
|
|
69
|
+
properties: {
|
|
70
|
+
owner: {
|
|
71
|
+
anyOf: [{ type: ['string', 'null'] }, { $ref: 'contact.json' }]
|
|
72
|
+
},
|
|
73
|
+
assignee: {
|
|
74
|
+
anyOf: [{ type: ['string', 'null'] }, { $ref: 'contact.json' }]
|
|
75
|
+
},
|
|
76
|
+
reporter: {
|
|
77
|
+
anyOf: [{ type: ['string', 'null'] }, { $ref: 'contact.json' }]
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const serializer = build(parentSchema, { schema: { 'contact.json': contactSchema } })
|
|
83
|
+
|
|
84
|
+
// Serialize with populated objects
|
|
85
|
+
const data = {
|
|
86
|
+
owner: { firstName: 'John', lastName: 'Doe', email: 'john@example.com' },
|
|
87
|
+
assignee: { firstName: 'Jane', lastName: 'Smith', email: 'jane@example.com' },
|
|
88
|
+
reporter: { firstName: 'Bob', lastName: 'Jones', email: 'bob@example.com' }
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const output = serializer(data)
|
|
92
|
+
t.assert.doesNotThrow(() => JSON.parse(output))
|
|
93
|
+
t.assert.equal(output, JSON.stringify(data))
|
|
94
|
+
})
|
|
95
|
+
|
|
96
|
+
test('external $ref schema reused in array items', (t) => {
|
|
97
|
+
t.plan(2)
|
|
98
|
+
|
|
99
|
+
const contactSchema = {
|
|
100
|
+
$id: 'contact.json',
|
|
101
|
+
type: 'object',
|
|
102
|
+
properties: {
|
|
103
|
+
firstName: { type: 'string' },
|
|
104
|
+
lastName: { type: 'string' }
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const parentSchema = {
|
|
109
|
+
type: 'object',
|
|
110
|
+
properties: {
|
|
111
|
+
contacts: {
|
|
112
|
+
type: 'array',
|
|
113
|
+
items: { $ref: 'contact.json' }
|
|
114
|
+
},
|
|
115
|
+
primary: { $ref: 'contact.json' },
|
|
116
|
+
secondary: { $ref: 'contact.json' }
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
const serializer = build(parentSchema, { schema: { 'contact.json': contactSchema } })
|
|
121
|
+
|
|
122
|
+
const data = {
|
|
123
|
+
contacts: [
|
|
124
|
+
{ firstName: 'Alice', lastName: 'Wonder' },
|
|
125
|
+
{ firstName: 'Bob', lastName: 'Builder' }
|
|
126
|
+
],
|
|
127
|
+
primary: { firstName: 'Charlie', lastName: 'Charm' },
|
|
128
|
+
secondary: { firstName: 'Diana', lastName: 'Prince' }
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
const output = serializer(data)
|
|
132
|
+
t.assert.doesNotThrow(() => JSON.parse(output))
|
|
133
|
+
t.assert.equal(output, JSON.stringify(data))
|
|
134
|
+
})
|
|
135
|
+
|
|
136
|
+
test('external array $ref schema should be reused, not inlined at every reference', (t) => {
|
|
137
|
+
t.plan(2)
|
|
138
|
+
|
|
139
|
+
const tagsSchema = {
|
|
140
|
+
$id: 'tags.json',
|
|
141
|
+
type: 'array',
|
|
142
|
+
items: { type: 'string' }
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
const parentSchema = {
|
|
146
|
+
type: 'object',
|
|
147
|
+
properties: {
|
|
148
|
+
a: { $ref: 'tags.json' },
|
|
149
|
+
b: { $ref: 'tags.json' },
|
|
150
|
+
c: { $ref: 'tags.json' }
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
const serializer = build(parentSchema, { schema: { 'tags.json': tagsSchema } })
|
|
155
|
+
|
|
156
|
+
const data = {
|
|
157
|
+
a: ['x', 'y'],
|
|
158
|
+
b: ['z'],
|
|
159
|
+
c: []
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
const output = serializer(data)
|
|
163
|
+
t.assert.doesNotThrow(() => JSON.parse(output))
|
|
164
|
+
t.assert.equal(output, JSON.stringify(data))
|
|
165
|
+
})
|
|
166
|
+
|
|
167
|
+
test('inline anonymous schemas should still be inlined (not extracted)', (t) => {
|
|
168
|
+
t.plan(1)
|
|
169
|
+
|
|
170
|
+
// Inline schemas (no external $ref) should continue to work normally
|
|
171
|
+
const schema = {
|
|
172
|
+
type: 'object',
|
|
173
|
+
properties: {
|
|
174
|
+
a: { type: 'object', properties: { x: { type: 'string' } } },
|
|
175
|
+
b: { type: 'object', properties: { x: { type: 'string' } } }
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
const serializer = build(schema)
|
|
180
|
+
const output = serializer({ a: { x: 'hello' }, b: { x: 'world' } })
|
|
181
|
+
|
|
182
|
+
t.assert.equal(output, '{"a":{"x":"hello"},"b":{"x":"world"}}')
|
|
183
|
+
})
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const { test } = require('node:test')
|
|
4
|
+
const build = require('..')
|
|
5
|
+
|
|
6
|
+
test('additionalProperties: false', (t) => {
|
|
7
|
+
t.plan(1)
|
|
8
|
+
const stringify = build({
|
|
9
|
+
title: 'additionalProperties',
|
|
10
|
+
type: 'object',
|
|
11
|
+
properties: {
|
|
12
|
+
foo: {
|
|
13
|
+
type: 'string'
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
additionalProperties: false
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
const obj = { foo: 'a', bar: 'b', baz: 'c' }
|
|
20
|
+
t.assert.equal(stringify(obj), '{"foo":"a"}')
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
test('additionalProperties: {}', (t) => {
|
|
24
|
+
t.plan(1)
|
|
25
|
+
const stringify = build({
|
|
26
|
+
title: 'additionalProperties',
|
|
27
|
+
type: 'object',
|
|
28
|
+
properties: {
|
|
29
|
+
foo: {
|
|
30
|
+
type: 'string'
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
additionalProperties: {}
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
const obj = { foo: 'a', bar: 'b', baz: 'c' }
|
|
37
|
+
t.assert.equal(stringify(obj), '{"foo":"a","bar":"b","baz":"c"}')
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
test('additionalProperties: {type: string}', (t) => {
|
|
41
|
+
t.plan(1)
|
|
42
|
+
const stringify = build({
|
|
43
|
+
title: 'additionalProperties',
|
|
44
|
+
type: 'object',
|
|
45
|
+
properties: {
|
|
46
|
+
foo: {
|
|
47
|
+
type: 'string'
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
additionalProperties: {
|
|
51
|
+
type: 'string'
|
|
52
|
+
}
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
const obj = { foo: 'a', bar: 'b', baz: 'c' }
|
|
56
|
+
t.assert.equal(stringify(obj), '{"foo":"a","bar":"b","baz":"c"}')
|
|
57
|
+
})
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# JSON-Schema-Test-Suite
|
|
2
|
+
|
|
3
|
+
You can find all test cases [here](https://github.com/json-schema-org/JSON-Schema-Test-Suite).
|
|
4
|
+
It contains a set of JSON objects that implementors of JSON Schema validation libraries can use to test their validators.
|
|
5
|
+
|
|
6
|
+
# How to add another test case?
|
|
7
|
+
|
|
8
|
+
1. Navigate to [JSON-Schema-Test-Suite](https://github.com/json-schema-org/JSON-Schema-Test-Suite/tree/main/tests)
|
|
9
|
+
2. Choose a draft `draft4`, `draft6` or `draft7`
|
|
10
|
+
3. Copy & paste the `test-case.json` to the project and add a test like in the `draft4.test.js`
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"description": "required validation",
|
|
4
|
+
"schema": {
|
|
5
|
+
"properties": {
|
|
6
|
+
"foo": {},
|
|
7
|
+
"bar": {}
|
|
8
|
+
},
|
|
9
|
+
"required": ["foo"]
|
|
10
|
+
},
|
|
11
|
+
"tests": [
|
|
12
|
+
{
|
|
13
|
+
"description": "present required property is valid",
|
|
14
|
+
"data": {"foo": 1},
|
|
15
|
+
"valid": true
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
"description": "non-present required property is invalid",
|
|
19
|
+
"data": {"bar": 1},
|
|
20
|
+
"valid": false
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
"description": "ignores arrays",
|
|
24
|
+
"data": [],
|
|
25
|
+
"valid": true
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
"description": "ignores strings",
|
|
29
|
+
"data": "",
|
|
30
|
+
"valid": true
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
"description": "ignores other non-objects",
|
|
34
|
+
"data": 12,
|
|
35
|
+
"valid": true
|
|
36
|
+
}
|
|
37
|
+
]
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
"description": "required default validation",
|
|
41
|
+
"schema": {
|
|
42
|
+
"properties": {
|
|
43
|
+
"foo": {}
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
"tests": [
|
|
47
|
+
{
|
|
48
|
+
"description": "not required by default",
|
|
49
|
+
"data": {},
|
|
50
|
+
"valid": true
|
|
51
|
+
}
|
|
52
|
+
]
|
|
53
|
+
}
|
|
54
|
+
]
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const { test } = require('node:test')
|
|
4
|
+
const { counTests, runTests } = require('./util')
|
|
5
|
+
|
|
6
|
+
const requiredTestSuite = require('./draft4/required.json')
|
|
7
|
+
|
|
8
|
+
test('required', async (t) => {
|
|
9
|
+
const skippedTests = ['ignores arrays', 'ignores strings', 'ignores other non-objects']
|
|
10
|
+
t.plan(counTests(requiredTestSuite, skippedTests))
|
|
11
|
+
await runTests(t, requiredTestSuite, skippedTests)
|
|
12
|
+
})
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"description": "required validation",
|
|
4
|
+
"schema": {
|
|
5
|
+
"properties": {
|
|
6
|
+
"foo": {},
|
|
7
|
+
"bar": {}
|
|
8
|
+
},
|
|
9
|
+
"required": ["foo"]
|
|
10
|
+
},
|
|
11
|
+
"tests": [
|
|
12
|
+
{
|
|
13
|
+
"description": "present required property is valid",
|
|
14
|
+
"data": {"foo": 1},
|
|
15
|
+
"valid": true
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
"description": "non-present required property is invalid",
|
|
19
|
+
"data": {"bar": 1},
|
|
20
|
+
"valid": false
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
"description": "ignores arrays",
|
|
24
|
+
"data": [],
|
|
25
|
+
"valid": true
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
"description": "ignores strings",
|
|
29
|
+
"data": "",
|
|
30
|
+
"valid": true
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
"description": "ignores other non-objects",
|
|
34
|
+
"data": 12,
|
|
35
|
+
"valid": true
|
|
36
|
+
}
|
|
37
|
+
]
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
"description": "required default validation",
|
|
41
|
+
"schema": {
|
|
42
|
+
"properties": {
|
|
43
|
+
"foo": {}
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
"tests": [
|
|
47
|
+
{
|
|
48
|
+
"description": "not required by default",
|
|
49
|
+
"data": {},
|
|
50
|
+
"valid": true
|
|
51
|
+
}
|
|
52
|
+
]
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
"description": "required with empty array",
|
|
56
|
+
"schema": {
|
|
57
|
+
"properties": {
|
|
58
|
+
"foo": {}
|
|
59
|
+
},
|
|
60
|
+
"required": []
|
|
61
|
+
},
|
|
62
|
+
"tests": [
|
|
63
|
+
{
|
|
64
|
+
"description": "property not required",
|
|
65
|
+
"data": {},
|
|
66
|
+
"valid": true
|
|
67
|
+
}
|
|
68
|
+
]
|
|
69
|
+
}
|
|
70
|
+
]
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const { test } = require('node:test')
|
|
4
|
+
const { counTests, runTests } = require('./util')
|
|
5
|
+
|
|
6
|
+
const requiredTestSuite = require('./draft6/required.json')
|
|
7
|
+
|
|
8
|
+
test('required', async (t) => {
|
|
9
|
+
const skippedTests = ['ignores arrays', 'ignores strings', 'ignores other non-objects']
|
|
10
|
+
t.plan(counTests(requiredTestSuite, skippedTests))
|
|
11
|
+
await runTests(t, requiredTestSuite, skippedTests)
|
|
12
|
+
})
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"description": "required validation",
|
|
4
|
+
"schema": {
|
|
5
|
+
"properties": {
|
|
6
|
+
"foo": {},
|
|
7
|
+
"bar": {}
|
|
8
|
+
},
|
|
9
|
+
"required": ["foo"]
|
|
10
|
+
},
|
|
11
|
+
"tests": [
|
|
12
|
+
{
|
|
13
|
+
"description": "present required property is valid",
|
|
14
|
+
"data": {"foo": 1},
|
|
15
|
+
"valid": true
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
"description": "non-present required property is invalid",
|
|
19
|
+
"data": {"bar": 1},
|
|
20
|
+
"valid": false
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
"description": "ignores arrays",
|
|
24
|
+
"data": [],
|
|
25
|
+
"valid": true
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
"description": "ignores strings",
|
|
29
|
+
"data": "",
|
|
30
|
+
"valid": true
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
"description": "ignores other non-objects",
|
|
34
|
+
"data": 12,
|
|
35
|
+
"valid": true
|
|
36
|
+
}
|
|
37
|
+
]
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
"description": "required default validation",
|
|
41
|
+
"schema": {
|
|
42
|
+
"properties": {
|
|
43
|
+
"foo": {}
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
"tests": [
|
|
47
|
+
{
|
|
48
|
+
"description": "not required by default",
|
|
49
|
+
"data": {},
|
|
50
|
+
"valid": true
|
|
51
|
+
}
|
|
52
|
+
]
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
"description": "required with empty array",
|
|
56
|
+
"schema": {
|
|
57
|
+
"properties": {
|
|
58
|
+
"foo": {}
|
|
59
|
+
},
|
|
60
|
+
"required": []
|
|
61
|
+
},
|
|
62
|
+
"tests": [
|
|
63
|
+
{
|
|
64
|
+
"description": "property not required",
|
|
65
|
+
"data": {},
|
|
66
|
+
"valid": true
|
|
67
|
+
}
|
|
68
|
+
]
|
|
69
|
+
}
|
|
70
|
+
]
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const { test } = require('node:test')
|
|
4
|
+
const { counTests, runTests } = require('./util')
|
|
5
|
+
|
|
6
|
+
const requiredTestSuite = require('./draft7/required.json')
|
|
7
|
+
|
|
8
|
+
test('required', async (t) => {
|
|
9
|
+
const skippedTests = ['ignores arrays', 'ignores strings', 'ignores other non-objects']
|
|
10
|
+
t.plan(counTests(requiredTestSuite, skippedTests))
|
|
11
|
+
await runTests(t, requiredTestSuite, skippedTests)
|
|
12
|
+
})
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const build = require('../..')
|
|
4
|
+
|
|
5
|
+
async function runTests (t, testsuite, skippedTests) {
|
|
6
|
+
for (const scenario of testsuite) {
|
|
7
|
+
const stringify = build(scenario.schema)
|
|
8
|
+
for (const test of scenario.tests) {
|
|
9
|
+
if (skippedTests.indexOf(test.description) !== -1) {
|
|
10
|
+
console.log(`skip ${test.description}`)
|
|
11
|
+
continue
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
await t.test(test.description, (t) => {
|
|
15
|
+
t.plan(1)
|
|
16
|
+
try {
|
|
17
|
+
const output = stringify(test.data)
|
|
18
|
+
t.assert.equal(output, JSON.stringify(test.data), 'compare payloads')
|
|
19
|
+
} catch (err) {
|
|
20
|
+
t.assert.ok(test.valid === false, 'payload should be valid: ' + err.message)
|
|
21
|
+
}
|
|
22
|
+
})
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function counTests (ts, skippedTests) {
|
|
28
|
+
return ts.reduce((a, b) => a + b.tests.length, 0) - skippedTests.length
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
module.exports = { runTests, counTests }
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const { test } = require('node:test')
|
|
4
|
+
const build = require('..')
|
|
5
|
+
|
|
6
|
+
test('missing values', (t) => {
|
|
7
|
+
t.plan(3)
|
|
8
|
+
|
|
9
|
+
const stringify = build({
|
|
10
|
+
title: 'object with missing values',
|
|
11
|
+
type: 'object',
|
|
12
|
+
properties: {
|
|
13
|
+
str: {
|
|
14
|
+
type: 'string'
|
|
15
|
+
},
|
|
16
|
+
num: {
|
|
17
|
+
type: 'number'
|
|
18
|
+
},
|
|
19
|
+
val: {
|
|
20
|
+
type: 'string'
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
t.assert.equal('{"val":"value"}', stringify({ val: 'value' }))
|
|
26
|
+
t.assert.equal('{"str":"string","val":"value"}', stringify({ str: 'string', val: 'value' }))
|
|
27
|
+
t.assert.equal('{"str":"string","num":42,"val":"value"}', stringify({ str: 'string', num: 42, val: 'value' }))
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
test('handle null when value should be string', (t) => {
|
|
31
|
+
t.plan(1)
|
|
32
|
+
|
|
33
|
+
const stringify = build({
|
|
34
|
+
type: 'object',
|
|
35
|
+
properties: {
|
|
36
|
+
str: {
|
|
37
|
+
type: 'string'
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
t.assert.equal('{"str":""}', stringify({ str: null }))
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
test('handle null when value should be integer', (t) => {
|
|
46
|
+
t.plan(1)
|
|
47
|
+
|
|
48
|
+
const stringify = build({
|
|
49
|
+
type: 'object',
|
|
50
|
+
properties: {
|
|
51
|
+
int: {
|
|
52
|
+
type: 'integer'
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
t.assert.equal('{"int":0}', stringify({ int: null }))
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
test('handle null when value should be number', (t) => {
|
|
61
|
+
t.plan(1)
|
|
62
|
+
|
|
63
|
+
const stringify = build({
|
|
64
|
+
type: 'object',
|
|
65
|
+
properties: {
|
|
66
|
+
num: {
|
|
67
|
+
type: 'number'
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
t.assert.equal('{"num":0}', stringify({ num: null }))
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
test('handle null when value should be boolean', (t) => {
|
|
76
|
+
t.plan(1)
|
|
77
|
+
|
|
78
|
+
const stringify = build({
|
|
79
|
+
type: 'object',
|
|
80
|
+
properties: {
|
|
81
|
+
bool: {
|
|
82
|
+
type: 'boolean'
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
t.assert.equal('{"bool":false}', stringify({ bool: null }))
|
|
88
|
+
})
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const { test } = require('node:test')
|
|
4
|
+
const build = require('..')
|
|
5
|
+
|
|
6
|
+
test('should throw a TypeError with the path to the key of the invalid value', (t) => {
|
|
7
|
+
t.plan(1)
|
|
8
|
+
const schema = {
|
|
9
|
+
type: 'object',
|
|
10
|
+
properties: {
|
|
11
|
+
num: {
|
|
12
|
+
type: ['number']
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const stringify = build(schema)
|
|
18
|
+
t.assert.throws(() => stringify({ num: { bla: 123 } }), new TypeError('The value of \'#/properties/num\' does not match schema definition.'))
|
|
19
|
+
})
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const { test } = require('node:test')
|
|
4
|
+
const build = require('..')
|
|
5
|
+
|
|
6
|
+
test('nested objects with same properties', (t) => {
|
|
7
|
+
t.plan(1)
|
|
8
|
+
|
|
9
|
+
const schema = {
|
|
10
|
+
title: 'nested objects with same properties',
|
|
11
|
+
type: 'object',
|
|
12
|
+
properties: {
|
|
13
|
+
stringProperty: {
|
|
14
|
+
type: 'string'
|
|
15
|
+
},
|
|
16
|
+
objectProperty: {
|
|
17
|
+
type: 'object',
|
|
18
|
+
additionalProperties: true
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
const stringify = build(schema)
|
|
23
|
+
|
|
24
|
+
const value = stringify({
|
|
25
|
+
stringProperty: 'string1',
|
|
26
|
+
objectProperty: {
|
|
27
|
+
stringProperty: 'string2',
|
|
28
|
+
numberProperty: 42
|
|
29
|
+
}
|
|
30
|
+
})
|
|
31
|
+
t.assert.equal(value, '{"stringProperty":"string1","objectProperty":{"stringProperty":"string2","numberProperty":42}}')
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
test('names collision', (t) => {
|
|
35
|
+
t.plan(1)
|
|
36
|
+
|
|
37
|
+
const schema = {
|
|
38
|
+
title: 'nested objects with same properties',
|
|
39
|
+
type: 'object',
|
|
40
|
+
properties: {
|
|
41
|
+
test: {
|
|
42
|
+
type: 'object',
|
|
43
|
+
properties: {
|
|
44
|
+
a: { type: 'string' }
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
tes: {
|
|
48
|
+
type: 'object',
|
|
49
|
+
properties: {
|
|
50
|
+
b: { type: 'string' },
|
|
51
|
+
t: { type: 'object' }
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
const stringify = build(schema)
|
|
57
|
+
const data = {
|
|
58
|
+
test: { a: 'a' },
|
|
59
|
+
tes: { b: 'b', t: {} }
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
t.assert.equal(stringify(data), JSON.stringify(data))
|
|
63
|
+
})
|