@zuplo/cli 6.71.23 → 6.71.26

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.
Files changed (128) hide show
  1. package/node_modules/@fastify/fast-json-stringify-compiler/.github/dependabot.yml +42 -2
  2. package/node_modules/@fastify/fast-json-stringify-compiler/.github/workflows/ci.yml +6 -1
  3. package/node_modules/@fastify/fast-json-stringify-compiler/.github/workflows/lock-threads.yml +19 -0
  4. package/node_modules/@fastify/fast-json-stringify-compiler/LICENSE +1 -1
  5. package/node_modules/@fastify/fast-json-stringify-compiler/README.md +1 -1
  6. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/.gitattributes +2 -0
  7. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/.github/dependabot.yml +13 -0
  8. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/.github/workflows/ci.yml +33 -0
  9. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/.github/workflows/lock-threads.yml +19 -0
  10. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/LICENSE +22 -0
  11. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/README.md +742 -0
  12. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/benchmark/bench-cmp-branch.js +116 -0
  13. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/benchmark/bench-cmp-lib.js +339 -0
  14. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/benchmark/bench-thread.js +33 -0
  15. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/benchmark/bench.js +391 -0
  16. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/build/build-schema-validator.js +26 -0
  17. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/eslint.config.js +9 -0
  18. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/examples/example.js +81 -0
  19. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/examples/server.js +42 -0
  20. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/index.js +1308 -0
  21. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/lib/location.js +24 -0
  22. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/lib/merge-schemas.js +9 -0
  23. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/lib/schema-validator.js +1134 -0
  24. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/lib/serializer.js +141 -0
  25. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/lib/standalone.js +34 -0
  26. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/lib/validator.js +96 -0
  27. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/package.json +89 -0
  28. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/additionalProperties.test.js +332 -0
  29. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/allof.test.js +751 -0
  30. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/any.test.js +231 -0
  31. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/anyof.test.js +812 -0
  32. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/array.test.js +688 -0
  33. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/asNumber.test.js +13 -0
  34. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/basic.test.js +400 -0
  35. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/bigint.test.js +76 -0
  36. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/clean-cache.test.js +47 -0
  37. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/const.test.js +314 -0
  38. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/date.test.js +639 -0
  39. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/debug-mode.test.js +130 -0
  40. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/defaults.test.js +376 -0
  41. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/enum.test.js +37 -0
  42. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/fix-604.test.js +25 -0
  43. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/fixtures/.keep +0 -0
  44. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/if-then-else.test.js +540 -0
  45. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/inferType.test.js +92 -0
  46. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/infinity.test.js +55 -0
  47. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/integer.test.js +194 -0
  48. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/invalidSchema.test.js +38 -0
  49. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/issue-479.test.js +57 -0
  50. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/issue-793.test.js +107 -0
  51. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/issue-794.test.js +177 -0
  52. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/issue-836.test.js +183 -0
  53. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/json-add-comma.test.js +57 -0
  54. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/json-schema-test-suite/README.md +10 -0
  55. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/json-schema-test-suite/draft4/required.json +54 -0
  56. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/json-schema-test-suite/draft4.test.js +12 -0
  57. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/json-schema-test-suite/draft6/required.json +70 -0
  58. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/json-schema-test-suite/draft6.test.js +12 -0
  59. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/json-schema-test-suite/draft7/required.json +70 -0
  60. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/json-schema-test-suite/draft7.test.js +12 -0
  61. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/json-schema-test-suite/util.js +31 -0
  62. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/missing-values.test.js +88 -0
  63. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/multi-type-serializer.test.js +19 -0
  64. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/nestedObjects.test.js +63 -0
  65. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/nullable.test.js +543 -0
  66. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/oneof.test.js +510 -0
  67. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/patternProperties.test.js +168 -0
  68. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/recursion.test.js +245 -0
  69. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/ref.json +12 -0
  70. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/ref.test.js +2077 -0
  71. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/regex.test.js +32 -0
  72. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/required.test.js +204 -0
  73. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/requiresAjv.test.js +50 -0
  74. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/sanitize.test.js +141 -0
  75. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/sanitize2.test.js +18 -0
  76. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/sanitize3.test.js +17 -0
  77. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/sanitize4.test.js +16 -0
  78. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/sanitize5.test.js +16 -0
  79. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/sanitize6.test.js +22 -0
  80. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/sanitize7.test.js +68 -0
  81. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/side-effect.test.js +196 -0
  82. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/standalone-mode.test.js +219 -0
  83. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/string.test.js +84 -0
  84. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/surrogate.test.js +67 -0
  85. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/toJSON.test.js +203 -0
  86. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/typebox.test.js +36 -0
  87. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/typesArray.test.js +550 -0
  88. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/unknownFormats.test.js +27 -0
  89. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/test/webpack.test.js +50 -0
  90. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/types/index.d.ts +219 -0
  91. package/node_modules/@fastify/fast-json-stringify-compiler/node_modules/fast-json-stringify/types/index.tst.ts +259 -0
  92. package/node_modules/@fastify/fast-json-stringify-compiler/package.json +6 -11
  93. package/node_modules/@fastify/fast-json-stringify-compiler/types/{index.test-d.ts → index.tst.ts} +34 -32
  94. package/node_modules/@protobufjs/utf8/CHANGELOG.md +8 -0
  95. package/node_modules/@protobufjs/utf8/index.js +29 -18
  96. package/node_modules/@protobufjs/utf8/package.json +2 -2
  97. package/node_modules/@protobufjs/utf8/tests/index.js +5 -0
  98. package/node_modules/@zuplo/core/package.json +1 -1
  99. package/node_modules/@zuplo/graphql/package.json +1 -1
  100. package/node_modules/@zuplo/openapi-tools/package.json +1 -1
  101. package/node_modules/@zuplo/otel/package.json +1 -1
  102. package/node_modules/@zuplo/runtime/out/esm/{chunk-5CYWMN74.js → chunk-D3O7C43P.js} +98 -97
  103. package/node_modules/@zuplo/runtime/out/esm/chunk-D3O7C43P.js.map +1 -0
  104. package/node_modules/@zuplo/runtime/out/esm/index.js +1 -1
  105. package/node_modules/@zuplo/runtime/out/esm/index.js.map +1 -1
  106. package/node_modules/@zuplo/runtime/out/esm/mcp-gateway/index.js +1 -1
  107. package/node_modules/@zuplo/runtime/out/types/index.d.ts +172 -0
  108. package/node_modules/@zuplo/runtime/package.json +1 -1
  109. package/node_modules/hono/dist/adapter/aws-lambda/handler.js +1 -1
  110. package/node_modules/hono/dist/adapter/bun/websocket.js +3 -1
  111. package/node_modules/hono/dist/cjs/adapter/aws-lambda/handler.js +1 -1
  112. package/node_modules/hono/dist/cjs/adapter/bun/websocket.js +3 -1
  113. package/node_modules/hono/dist/cjs/middleware/serve-static/index.js +1 -1
  114. package/node_modules/hono/dist/cjs/utils/body.js +12 -4
  115. package/node_modules/hono/dist/cjs/utils/buffer.js +2 -1
  116. package/node_modules/hono/dist/cjs/validator/validator.js +3 -3
  117. package/node_modules/hono/dist/middleware/serve-static/index.js +1 -1
  118. package/node_modules/hono/dist/types/middleware/context-storage/index.d.ts +2 -2
  119. package/node_modules/hono/dist/types/utils/body.d.ts +1 -1
  120. package/node_modules/hono/dist/utils/body.js +12 -4
  121. package/node_modules/hono/dist/utils/buffer.js +2 -1
  122. package/node_modules/hono/dist/validator/validator.js +3 -3
  123. package/node_modules/hono/package.json +8 -7
  124. package/package.json +6 -6
  125. package/node_modules/@fastify/fast-json-stringify-compiler/.eslintrc +0 -1
  126. package/node_modules/@zuplo/runtime/out/esm/chunk-5CYWMN74.js.map +0 -1
  127. package/node_modules/hono/dist/tsconfig.build.tsbuildinfo +0 -1
  128. /package/node_modules/@zuplo/runtime/out/esm/{chunk-5CYWMN74.js.LEGAL.txt → chunk-D3O7C43P.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
+ })