@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,812 @@
1
+ 'use strict'
2
+
3
+ const { test } = require('node:test')
4
+ const build = require('..')
5
+
6
+ process.env.TZ = 'UTC'
7
+
8
+ test('object with multiple types field', (t) => {
9
+ t.plan(2)
10
+
11
+ const schema = {
12
+ title: 'object with multiple types field',
13
+ type: 'object',
14
+ properties: {
15
+ str: {
16
+ anyOf: [{
17
+ type: 'string'
18
+ }, {
19
+ type: 'boolean'
20
+ }]
21
+ }
22
+ }
23
+ }
24
+ const stringify = build(schema)
25
+
26
+ t.assert.equal(stringify({
27
+ str: 'string'
28
+ }), '{"str":"string"}')
29
+
30
+ t.assert.equal(stringify({
31
+ str: true
32
+ }), '{"str":true}')
33
+ })
34
+
35
+ test('object with field of type object or null', (t) => {
36
+ t.plan(2)
37
+
38
+ const schema = {
39
+ title: 'object with field of type object or null',
40
+ type: 'object',
41
+ properties: {
42
+ prop: {
43
+ anyOf: [{
44
+ type: 'object',
45
+ properties: {
46
+ str: {
47
+ type: 'string'
48
+ }
49
+ }
50
+ }, {
51
+ type: 'null'
52
+ }]
53
+ }
54
+ }
55
+ }
56
+ const stringify = build(schema)
57
+
58
+ t.assert.equal(stringify({
59
+ prop: null
60
+ }), '{"prop":null}')
61
+
62
+ t.assert.equal(stringify({
63
+ prop: {
64
+ str: 'string'
65
+ }
66
+ }), '{"prop":{"str":"string"}}')
67
+ })
68
+
69
+ test('object with field of type object or array', (t) => {
70
+ t.plan(2)
71
+
72
+ const schema = {
73
+ title: 'object with field of type object or array',
74
+ type: 'object',
75
+ properties: {
76
+ prop: {
77
+ anyOf: [{
78
+ type: 'object',
79
+ properties: {},
80
+ additionalProperties: true
81
+ }, {
82
+ type: 'array',
83
+ items: {
84
+ type: 'string'
85
+ }
86
+ }]
87
+ }
88
+ }
89
+ }
90
+ const stringify = build(schema)
91
+
92
+ t.assert.equal(stringify({
93
+ prop: {
94
+ str: 'string'
95
+ }
96
+ }), '{"prop":{"str":"string"}}')
97
+
98
+ t.assert.equal(stringify({
99
+ prop: ['string']
100
+ }), '{"prop":["string"]}')
101
+ })
102
+
103
+ test('object with field of type string and coercion disable ', (t) => {
104
+ t.plan(1)
105
+
106
+ const schema = {
107
+ title: 'object with field of type string',
108
+ type: 'object',
109
+ properties: {
110
+ str: {
111
+ anyOf: [{
112
+ type: 'string'
113
+ }]
114
+ }
115
+ }
116
+ }
117
+ const stringify = build(schema)
118
+ t.assert.throws(() => stringify({ str: 1 }))
119
+ })
120
+
121
+ test('object with field of type string and coercion enable ', (t) => {
122
+ t.plan(1)
123
+
124
+ const schema = {
125
+ title: 'object with field of type string',
126
+ type: 'object',
127
+ properties: {
128
+ str: {
129
+ anyOf: [{
130
+ type: 'string'
131
+ }]
132
+ }
133
+ }
134
+ }
135
+
136
+ const options = {
137
+ ajv: {
138
+ coerceTypes: true
139
+ }
140
+ }
141
+ const stringify = build(schema, options)
142
+
143
+ const value = stringify({
144
+ str: 1
145
+ })
146
+ t.assert.equal(value, '{"str":"1"}')
147
+ })
148
+
149
+ test('object with field with type union of multiple objects', (t) => {
150
+ t.plan(2)
151
+
152
+ const schema = {
153
+ title: 'object with anyOf property value containing objects',
154
+ type: 'object',
155
+ properties: {
156
+ anyOfSchema: {
157
+ anyOf: [
158
+ {
159
+ type: 'object',
160
+ properties: {
161
+ baz: { type: 'number' }
162
+ },
163
+ required: ['baz']
164
+ },
165
+ {
166
+ type: 'object',
167
+ properties: {
168
+ bar: { type: 'string' }
169
+ },
170
+ required: ['bar']
171
+ }
172
+ ]
173
+ }
174
+ },
175
+ required: ['anyOfSchema']
176
+ }
177
+
178
+ const stringify = build(schema)
179
+
180
+ t.assert.equal(stringify({ anyOfSchema: { baz: 5 } }), '{"anyOfSchema":{"baz":5}}')
181
+
182
+ t.assert.equal(stringify({ anyOfSchema: { bar: 'foo' } }), '{"anyOfSchema":{"bar":"foo"}}')
183
+ })
184
+
185
+ test('null value in schema', (t) => {
186
+ t.plan(0)
187
+
188
+ const schema = {
189
+ title: 'schema with null child',
190
+ type: 'string',
191
+ nullable: true,
192
+ enum: [null]
193
+ }
194
+
195
+ build(schema)
196
+ })
197
+
198
+ test('symbol value in schema', (t) => {
199
+ t.plan(4)
200
+
201
+ const ObjectKind = Symbol('LiteralKind')
202
+ const UnionKind = Symbol('UnionKind')
203
+ const LiteralKind = Symbol('LiteralKind')
204
+
205
+ const schema = {
206
+ kind: ObjectKind,
207
+ type: 'object',
208
+ properties: {
209
+ value: {
210
+ kind: UnionKind,
211
+ anyOf: [
212
+ { kind: LiteralKind, type: 'string', enum: ['foo'] },
213
+ { kind: LiteralKind, type: 'string', enum: ['bar'] },
214
+ { kind: LiteralKind, type: 'string', enum: ['baz'] }
215
+ ]
216
+ }
217
+ },
218
+ required: ['value']
219
+ }
220
+
221
+ const stringify = build(schema)
222
+ t.assert.equal(stringify({ value: 'foo' }), '{"value":"foo"}')
223
+ t.assert.equal(stringify({ value: 'bar' }), '{"value":"bar"}')
224
+ t.assert.equal(stringify({ value: 'baz' }), '{"value":"baz"}')
225
+ t.assert.throws(() => stringify({ value: 'qux' }))
226
+ })
227
+
228
+ test('anyOf and $ref together', (t) => {
229
+ t.plan(2)
230
+
231
+ const schema = {
232
+ type: 'object',
233
+ properties: {
234
+ cs: {
235
+ anyOf: [
236
+ {
237
+ $ref: '#/definitions/Option'
238
+ },
239
+ {
240
+ type: 'boolean'
241
+ }
242
+ ]
243
+ }
244
+ },
245
+ definitions: {
246
+ Option: {
247
+ type: 'string'
248
+ }
249
+ }
250
+ }
251
+
252
+ const stringify = build(schema)
253
+
254
+ t.assert.equal(stringify({ cs: 'franco' }), '{"cs":"franco"}')
255
+
256
+ t.assert.equal(stringify({ cs: true }), '{"cs":true}')
257
+ })
258
+
259
+ test('anyOf and $ref: 2 levels are fine', (t) => {
260
+ t.plan(1)
261
+
262
+ const schema = {
263
+ type: 'object',
264
+ properties: {
265
+ cs: {
266
+ anyOf: [
267
+ {
268
+ $ref: '#/definitions/Option'
269
+ },
270
+ {
271
+ type: 'boolean'
272
+ }
273
+ ]
274
+ }
275
+ },
276
+ definitions: {
277
+ Option: {
278
+ anyOf: [
279
+ {
280
+ type: 'number'
281
+ },
282
+ {
283
+ type: 'boolean'
284
+ }
285
+ ]
286
+ }
287
+ }
288
+ }
289
+
290
+ const stringify = build(schema)
291
+ const value = stringify({ cs: 3 })
292
+ t.assert.equal(value, '{"cs":3}')
293
+ })
294
+
295
+ test('anyOf and $ref: multiple levels should throw at build.', (t) => {
296
+ t.plan(3)
297
+
298
+ const schema = {
299
+ type: 'object',
300
+ properties: {
301
+ cs: {
302
+ anyOf: [
303
+ {
304
+ $ref: '#/definitions/Option'
305
+ },
306
+ {
307
+ type: 'boolean'
308
+ }
309
+ ]
310
+ }
311
+ },
312
+ definitions: {
313
+ Option: {
314
+ anyOf: [
315
+ {
316
+ $ref: '#/definitions/Option2'
317
+ },
318
+ {
319
+ type: 'string'
320
+ }
321
+ ]
322
+ },
323
+ Option2: {
324
+ type: 'number'
325
+ }
326
+ }
327
+ }
328
+
329
+ const stringify = build(schema)
330
+
331
+ t.assert.equal(stringify({ cs: 3 }), '{"cs":3}')
332
+ t.assert.equal(stringify({ cs: true }), '{"cs":true}')
333
+ t.assert.equal(stringify({ cs: 'pippo' }), '{"cs":"pippo"}')
334
+ })
335
+
336
+ test('anyOf and $ref - multiple external $ref', (t) => {
337
+ t.plan(2)
338
+
339
+ const externalSchema = {
340
+ external: {
341
+ definitions: {
342
+ def: {
343
+ type: 'object',
344
+ properties: {
345
+ prop: { anyOf: [{ $ref: 'external2#/definitions/other' }] }
346
+ }
347
+ }
348
+ }
349
+ },
350
+ external2: {
351
+ definitions: {
352
+ internal: {
353
+ type: 'string'
354
+ },
355
+ other: {
356
+ type: 'object',
357
+ properties: {
358
+ prop2: { $ref: '#/definitions/internal' }
359
+ }
360
+ }
361
+ }
362
+ }
363
+ }
364
+
365
+ const schema = {
366
+ title: 'object with $ref',
367
+ type: 'object',
368
+ properties: {
369
+ obj: {
370
+ $ref: 'external#/definitions/def'
371
+ }
372
+ }
373
+ }
374
+
375
+ const object = {
376
+ obj: {
377
+ prop: {
378
+ prop2: 'test'
379
+ }
380
+ }
381
+ }
382
+
383
+ const stringify = build(schema, { schema: externalSchema })
384
+ const output = stringify(object)
385
+
386
+ t.assert.doesNotThrow(() => JSON.parse(output))
387
+ t.assert.equal(output, '{"obj":{"prop":{"prop2":"test"}}}')
388
+ })
389
+
390
+ test('anyOf looks for all of the array items', (t) => {
391
+ t.plan(1)
392
+
393
+ const schema = {
394
+ title: 'type array that may have any of declared items',
395
+ type: 'array',
396
+ items: {
397
+ anyOf: [
398
+ {
399
+ type: 'object',
400
+ properties: {
401
+ savedId: {
402
+ type: 'string'
403
+ }
404
+ },
405
+ required: ['savedId']
406
+ },
407
+ {
408
+ type: 'object',
409
+ properties: {
410
+ error: {
411
+ type: 'string'
412
+ }
413
+ },
414
+ required: ['error']
415
+ }
416
+ ]
417
+ }
418
+ }
419
+ const stringify = build(schema)
420
+
421
+ const value = stringify([{ savedId: 'great' }, { error: 'oops' }])
422
+ t.assert.equal(value, '[{"savedId":"great"},{"error":"oops"}]')
423
+ })
424
+
425
+ test('anyOf with enum with more than 100 entries', (t) => {
426
+ t.plan(1)
427
+
428
+ const schema = {
429
+ title: 'type array that may have any of declared items',
430
+ type: 'array',
431
+ items: {
432
+ anyOf: [
433
+ {
434
+ type: 'string',
435
+ enum: ['EUR', 'USD', ...(new Set([...new Array(200)].map(() => Math.random().toString(36).substr(2, 3)))).values()]
436
+ },
437
+ { type: 'null' }
438
+ ]
439
+ }
440
+ }
441
+ const stringify = build(schema)
442
+
443
+ const value = stringify(['EUR', 'USD', null])
444
+ t.assert.equal(value, '["EUR","USD",null]')
445
+ })
446
+
447
+ test('anyOf object with field date-time of type string with format or null', (t) => {
448
+ t.plan(1)
449
+ const toStringify = new Date()
450
+ const withOneOfSchema = {
451
+ type: 'object',
452
+ properties: {
453
+ prop: {
454
+ anyOf: [{
455
+ type: 'string',
456
+ format: 'date-time'
457
+ }, {
458
+ type: 'null'
459
+ }]
460
+ }
461
+ }
462
+ }
463
+
464
+ const withOneOfStringify = build(withOneOfSchema)
465
+
466
+ t.assert.equal(withOneOfStringify({
467
+ prop: toStringify
468
+ }), `{"prop":"${toStringify.toISOString()}"}`)
469
+ })
470
+
471
+ test('anyOf object with nested field date-time of type string with format or null', (t) => {
472
+ t.plan(1)
473
+ const withOneOfSchema = {
474
+ type: 'object',
475
+ properties: {
476
+ prop: {
477
+ anyOf: [{
478
+ type: 'object',
479
+ properties: {
480
+ nestedProp: {
481
+ type: 'string',
482
+ format: 'date-time'
483
+ }
484
+ }
485
+ }]
486
+ }
487
+ }
488
+ }
489
+
490
+ const withOneOfStringify = build(withOneOfSchema)
491
+
492
+ const data = {
493
+ prop: { nestedProp: new Date() }
494
+ }
495
+
496
+ t.assert.equal(withOneOfStringify(data), JSON.stringify(data))
497
+ })
498
+
499
+ test('anyOf object with nested field date of type string with format or null', (t) => {
500
+ t.plan(1)
501
+ const withOneOfSchema = {
502
+ type: 'object',
503
+ properties: {
504
+ prop: {
505
+ anyOf: [{
506
+ type: 'object',
507
+ properties: {
508
+ nestedProp: {
509
+ type: 'string',
510
+ format: 'date'
511
+ }
512
+ }
513
+ }]
514
+ }
515
+ }
516
+ }
517
+
518
+ const withOneOfStringify = build(withOneOfSchema)
519
+
520
+ const data = {
521
+ prop: { nestedProp: new Date(1674263005800) }
522
+ }
523
+
524
+ t.assert.equal(withOneOfStringify(data), '{"prop":{"nestedProp":"2023-01-21"}}')
525
+ })
526
+
527
+ test('anyOf object with nested field time of type string with format or null', (t) => {
528
+ t.plan(1)
529
+ const withOneOfSchema = {
530
+ type: 'object',
531
+ properties: {
532
+ prop: {
533
+ anyOf: [{
534
+ type: 'object',
535
+ properties: {
536
+ nestedProp: {
537
+ type: 'string',
538
+ format: 'time'
539
+ }
540
+ }
541
+ }]
542
+ }
543
+ }
544
+ }
545
+
546
+ const withOneOfStringify = build(withOneOfSchema)
547
+
548
+ const data = {
549
+ prop: { nestedProp: new Date(1674263005800) }
550
+ }
551
+ t.assert.equal(withOneOfStringify(data), '{"prop":{"nestedProp":"01:03:25"}}')
552
+ })
553
+
554
+ test('anyOf object with field date of type string with format or null', (t) => {
555
+ t.plan(1)
556
+ const toStringify = '2011-01-01'
557
+ const withOneOfSchema = {
558
+ type: 'object',
559
+ properties: {
560
+ prop: {
561
+ anyOf: [{
562
+ type: 'string',
563
+ format: 'date'
564
+ }, {
565
+ type: 'null'
566
+ }]
567
+ }
568
+ }
569
+ }
570
+
571
+ const withOneOfStringify = build(withOneOfSchema)
572
+ t.assert.equal(withOneOfStringify({
573
+ prop: toStringify
574
+ }), '{"prop":"2011-01-01"}')
575
+ })
576
+
577
+ test('anyOf object with invalid field date of type string with format or null', (t) => {
578
+ t.plan(1)
579
+ const toStringify = 'foo bar'
580
+ const withOneOfSchema = {
581
+ type: 'object',
582
+ properties: {
583
+ prop: {
584
+ anyOf: [{
585
+ type: 'string',
586
+ format: 'date'
587
+ }, {
588
+ type: 'null'
589
+ }]
590
+ }
591
+ }
592
+ }
593
+
594
+ const withOneOfStringify = build(withOneOfSchema)
595
+ t.assert.throws(() => withOneOfStringify({ prop: toStringify }))
596
+ })
597
+
598
+ test('anyOf with a nested external schema', (t) => {
599
+ t.plan(1)
600
+
601
+ const externalSchemas = {
602
+ schema1: {
603
+ definitions: {
604
+ def1: {
605
+ $id: 'external',
606
+ type: 'string'
607
+ }
608
+ },
609
+ type: 'number'
610
+ }
611
+ }
612
+ const schema = { anyOf: [{ $ref: 'external' }] }
613
+
614
+ const stringify = build(schema, { schema: externalSchemas })
615
+ t.assert.equal(stringify('foo'), '"foo"')
616
+ })
617
+
618
+ test('object with ref and validated properties', (t) => {
619
+ t.plan(1)
620
+
621
+ const externalSchemas = {
622
+ RefSchema: {
623
+ $id: 'RefSchema',
624
+ type: 'string'
625
+ }
626
+ }
627
+
628
+ const schema = {
629
+ $id: 'root',
630
+ type: 'object',
631
+ properties: {
632
+ id: {
633
+ anyOf: [
634
+ { type: 'string' },
635
+ { type: 'number' }
636
+ ]
637
+ },
638
+ reference: { $ref: 'RefSchema' }
639
+ }
640
+ }
641
+
642
+ const stringify = build(schema, { schema: externalSchemas })
643
+ t.assert.equal(stringify({ id: 1, reference: 'hi' }), '{"id":1,"reference":"hi"}')
644
+ })
645
+
646
+ test('anyOf required props', (t) => {
647
+ t.plan(3)
648
+
649
+ const schema = {
650
+ type: 'object',
651
+ properties: {
652
+ prop1: { type: 'string' },
653
+ prop2: { type: 'string' },
654
+ prop3: { type: 'string' }
655
+ },
656
+ required: ['prop1'],
657
+ anyOf: [{ required: ['prop2'] }, { required: ['prop3'] }]
658
+ }
659
+ const stringify = build(schema)
660
+ t.assert.equal(stringify({ prop1: 'test', prop2: 'test2' }), '{"prop1":"test","prop2":"test2"}')
661
+ t.assert.equal(stringify({ prop1: 'test', prop3: 'test3' }), '{"prop1":"test","prop3":"test3"}')
662
+ t.assert.equal(stringify({ prop1: 'test', prop2: 'test2', prop3: 'test3' }), '{"prop1":"test","prop2":"test2","prop3":"test3"}')
663
+ })
664
+
665
+ test('anyOf required props', (t) => {
666
+ t.plan(3)
667
+
668
+ const schema = {
669
+ type: 'object',
670
+ properties: {
671
+ prop1: { type: 'string' }
672
+ },
673
+ anyOf: [
674
+ {
675
+ properties: {
676
+ prop2: { type: 'string' }
677
+ }
678
+ },
679
+ {
680
+ properties: {
681
+ prop3: { type: 'string' }
682
+ }
683
+ }
684
+ ]
685
+ }
686
+ const stringify = build(schema)
687
+ t.assert.equal(stringify({ prop1: 'test1' }), '{"prop1":"test1"}')
688
+ t.assert.equal(stringify({ prop2: 'test2' }), '{"prop2":"test2"}')
689
+ t.assert.equal(stringify({ prop1: 'test1', prop2: 'test2' }), '{"prop1":"test1","prop2":"test2"}')
690
+ })
691
+
692
+ test('recursive nested anyOfs', (t) => {
693
+ t.plan(1)
694
+
695
+ const schema = {
696
+ type: 'object',
697
+ properties: {
698
+ foo: {
699
+ additionalProperties: false,
700
+ anyOf: [{ $ref: '#' }]
701
+ }
702
+ }
703
+ }
704
+
705
+ const data = { foo: {} }
706
+ const stringify = build(schema)
707
+ t.assert.equal(stringify(data), JSON.stringify(data))
708
+ })
709
+
710
+ test('recursive nested anyOfs', (t) => {
711
+ t.plan(1)
712
+
713
+ const schema = {
714
+ type: 'object',
715
+ properties: {
716
+ foo: {
717
+ additionalProperties: false,
718
+ anyOf: [{ anyOf: [{ $ref: '#' }] }]
719
+ }
720
+ }
721
+ }
722
+
723
+ const data = { foo: {} }
724
+ const stringify = build(schema)
725
+ t.assert.equal(stringify(data), JSON.stringify(data))
726
+ })
727
+
728
+ test('external recursive anyOfs', (t) => {
729
+ t.plan(1)
730
+
731
+ const externalSchema = {
732
+ type: 'object',
733
+ properties: {
734
+ foo: {
735
+ properties: {
736
+ bar: { type: 'string' }
737
+ },
738
+ anyOf: [{ $ref: '#' }]
739
+ }
740
+ }
741
+ }
742
+
743
+ const schema = {
744
+ type: 'object',
745
+ properties: {
746
+ a: { $ref: 'externalSchema#/properties/foo' },
747
+ b: { $ref: 'externalSchema#/properties/foo' }
748
+ }
749
+ }
750
+
751
+ const data = {
752
+ a: {
753
+ foo: {},
754
+ bar: '42',
755
+ baz: 42
756
+ },
757
+ b: {
758
+ foo: {},
759
+ bar: '42',
760
+ baz: 42
761
+ }
762
+ }
763
+ const stringify = build(schema, { schema: { externalSchema } })
764
+ t.assert.equal(stringify(data), '{"a":{"bar":"42","foo":{}},"b":{"bar":"42","foo":{}}}')
765
+ })
766
+
767
+ test('should build merged schemas twice', (t) => {
768
+ t.plan(2)
769
+
770
+ const schema = {
771
+ type: 'object',
772
+ properties: {
773
+ enums: {
774
+ type: 'string',
775
+ anyOf: [
776
+ { type: 'string', const: 'FOO' },
777
+ { type: 'string', const: 'BAR' }
778
+ ]
779
+ }
780
+ }
781
+ }
782
+
783
+ {
784
+ const stringify = build(schema)
785
+ t.assert.equal(stringify({ enums: 'FOO' }), '{"enums":"FOO"}')
786
+ }
787
+
788
+ {
789
+ const stringify = build(schema)
790
+ t.assert.equal(stringify({ enums: 'BAR' }), '{"enums":"BAR"}')
791
+ }
792
+ })
793
+
794
+ test('invalid anyOf schema', (t) => {
795
+ t.plan(1)
796
+
797
+ const schema = {
798
+ type: 'object',
799
+ properties: {
800
+ prop: {
801
+ anyOf: 'not array' // invalid, anyOf must be array
802
+ }
803
+ }
804
+ }
805
+
806
+ try {
807
+ build(schema)
808
+ t.assert.fail('Should throw')
809
+ } catch (err) {
810
+ t.assert.ok(err.message.includes('schema is invalid'))
811
+ }
812
+ })