@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.
- 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/@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/@zuplo/core/package.json +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-5CYWMN74.js → chunk-D3O7C43P.js} +98 -97
- package/node_modules/@zuplo/runtime/out/esm/chunk-D3O7C43P.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 +1 -1
- package/node_modules/@zuplo/runtime/out/types/index.d.ts +172 -0
- 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/package.json +6 -6
- package/node_modules/@fastify/fast-json-stringify-compiler/.eslintrc +0 -1
- package/node_modules/@zuplo/runtime/out/esm/chunk-5CYWMN74.js.map +0 -1
- package/node_modules/hono/dist/tsconfig.build.tsbuildinfo +0 -1
- /package/node_modules/@zuplo/runtime/out/esm/{chunk-5CYWMN74.js.LEGAL.txt → chunk-D3O7C43P.js.LEGAL.txt} +0 -0
|
@@ -0,0 +1,510 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const { test } = require('node:test')
|
|
4
|
+
const build = require('..')
|
|
5
|
+
|
|
6
|
+
test('object with multiple types field', (t) => {
|
|
7
|
+
t.plan(2)
|
|
8
|
+
|
|
9
|
+
const schema = {
|
|
10
|
+
title: 'object with multiple types field',
|
|
11
|
+
type: 'object',
|
|
12
|
+
properties: {
|
|
13
|
+
str: {
|
|
14
|
+
oneOf: [{
|
|
15
|
+
type: 'string'
|
|
16
|
+
}, {
|
|
17
|
+
type: 'boolean'
|
|
18
|
+
}]
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
const stringify = build(schema)
|
|
23
|
+
|
|
24
|
+
t.assert.equal(stringify({ str: 'string' }), '{"str":"string"}')
|
|
25
|
+
t.assert.equal(stringify({ str: true }), '{"str":true}')
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
test('object with field of type object or null', (t) => {
|
|
29
|
+
t.plan(2)
|
|
30
|
+
|
|
31
|
+
const schema = {
|
|
32
|
+
title: 'object with field of type object or null',
|
|
33
|
+
type: 'object',
|
|
34
|
+
properties: {
|
|
35
|
+
prop: {
|
|
36
|
+
oneOf: [{
|
|
37
|
+
type: 'object',
|
|
38
|
+
properties: {
|
|
39
|
+
str: {
|
|
40
|
+
type: 'string'
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}, {
|
|
44
|
+
type: 'null'
|
|
45
|
+
}]
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
const stringify = build(schema)
|
|
50
|
+
|
|
51
|
+
t.assert.equal(stringify({ prop: null }), '{"prop":null}')
|
|
52
|
+
|
|
53
|
+
t.assert.equal(stringify({
|
|
54
|
+
prop: {
|
|
55
|
+
str: 'string', remove: 'this'
|
|
56
|
+
}
|
|
57
|
+
}), '{"prop":{"str":"string"}}')
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
test('object with field of type object or array', (t) => {
|
|
61
|
+
t.plan(2)
|
|
62
|
+
|
|
63
|
+
const schema = {
|
|
64
|
+
title: 'object with field of type object or array',
|
|
65
|
+
type: 'object',
|
|
66
|
+
properties: {
|
|
67
|
+
prop: {
|
|
68
|
+
oneOf: [{
|
|
69
|
+
type: 'object',
|
|
70
|
+
properties: {},
|
|
71
|
+
additionalProperties: true
|
|
72
|
+
}, {
|
|
73
|
+
type: 'array',
|
|
74
|
+
items: {
|
|
75
|
+
type: 'string'
|
|
76
|
+
}
|
|
77
|
+
}]
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
const stringify = build(schema)
|
|
82
|
+
|
|
83
|
+
t.assert.equal(stringify({
|
|
84
|
+
prop: { str: 'string' }
|
|
85
|
+
}), '{"prop":{"str":"string"}}')
|
|
86
|
+
|
|
87
|
+
t.assert.equal(stringify({
|
|
88
|
+
prop: ['string']
|
|
89
|
+
}), '{"prop":["string"]}')
|
|
90
|
+
})
|
|
91
|
+
|
|
92
|
+
test('object with field of type string and coercion disable ', (t) => {
|
|
93
|
+
t.plan(1)
|
|
94
|
+
|
|
95
|
+
const schema = {
|
|
96
|
+
title: 'object with field of type string',
|
|
97
|
+
type: 'object',
|
|
98
|
+
properties: {
|
|
99
|
+
str: {
|
|
100
|
+
oneOf: [{
|
|
101
|
+
type: 'string'
|
|
102
|
+
}]
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
const stringify = build(schema)
|
|
107
|
+
t.assert.throws(() => stringify({ str: 1 }))
|
|
108
|
+
})
|
|
109
|
+
|
|
110
|
+
test('object with field of type string and coercion enable ', (t) => {
|
|
111
|
+
t.plan(1)
|
|
112
|
+
|
|
113
|
+
const schema = {
|
|
114
|
+
title: 'object with field of type string',
|
|
115
|
+
type: 'object',
|
|
116
|
+
properties: {
|
|
117
|
+
str: {
|
|
118
|
+
oneOf: [{
|
|
119
|
+
type: 'string'
|
|
120
|
+
}]
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
const options = {
|
|
126
|
+
ajv: {
|
|
127
|
+
coerceTypes: true
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
const stringify = build(schema, options)
|
|
131
|
+
|
|
132
|
+
const value = stringify({
|
|
133
|
+
str: 1
|
|
134
|
+
})
|
|
135
|
+
t.assert.equal(value, '{"str":"1"}')
|
|
136
|
+
})
|
|
137
|
+
|
|
138
|
+
test('object with field with type union of multiple objects', (t) => {
|
|
139
|
+
t.plan(2)
|
|
140
|
+
|
|
141
|
+
const schema = {
|
|
142
|
+
title: 'object with oneOf property value containing objects',
|
|
143
|
+
type: 'object',
|
|
144
|
+
properties: {
|
|
145
|
+
oneOfSchema: {
|
|
146
|
+
oneOf: [
|
|
147
|
+
{
|
|
148
|
+
type: 'object',
|
|
149
|
+
properties: {
|
|
150
|
+
baz: { type: 'number' }
|
|
151
|
+
},
|
|
152
|
+
required: ['baz']
|
|
153
|
+
},
|
|
154
|
+
{
|
|
155
|
+
type: 'object',
|
|
156
|
+
properties: {
|
|
157
|
+
bar: { type: 'string' }
|
|
158
|
+
},
|
|
159
|
+
required: ['bar']
|
|
160
|
+
}
|
|
161
|
+
]
|
|
162
|
+
}
|
|
163
|
+
},
|
|
164
|
+
required: ['oneOfSchema']
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
const stringify = build(schema)
|
|
168
|
+
|
|
169
|
+
t.assert.equal(stringify({ oneOfSchema: { baz: 5 } }), '{"oneOfSchema":{"baz":5}}')
|
|
170
|
+
|
|
171
|
+
t.assert.equal(stringify({ oneOfSchema: { bar: 'foo' } }), '{"oneOfSchema":{"bar":"foo"}}')
|
|
172
|
+
})
|
|
173
|
+
|
|
174
|
+
test('null value in schema', (t) => {
|
|
175
|
+
t.plan(0)
|
|
176
|
+
|
|
177
|
+
const schema = {
|
|
178
|
+
title: 'schema with null child',
|
|
179
|
+
type: 'string',
|
|
180
|
+
nullable: true,
|
|
181
|
+
enum: [null]
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
build(schema)
|
|
185
|
+
})
|
|
186
|
+
|
|
187
|
+
test('oneOf and $ref together', (t) => {
|
|
188
|
+
t.plan(2)
|
|
189
|
+
|
|
190
|
+
const schema = {
|
|
191
|
+
type: 'object',
|
|
192
|
+
properties: {
|
|
193
|
+
cs: {
|
|
194
|
+
oneOf: [
|
|
195
|
+
{
|
|
196
|
+
$ref: '#/definitions/Option'
|
|
197
|
+
},
|
|
198
|
+
{
|
|
199
|
+
type: 'boolean'
|
|
200
|
+
}
|
|
201
|
+
]
|
|
202
|
+
}
|
|
203
|
+
},
|
|
204
|
+
definitions: {
|
|
205
|
+
Option: {
|
|
206
|
+
type: 'string'
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
const stringify = build(schema)
|
|
212
|
+
|
|
213
|
+
t.assert.equal(stringify({ cs: 'franco' }), '{"cs":"franco"}')
|
|
214
|
+
|
|
215
|
+
t.assert.equal(stringify({ cs: true }), '{"cs":true}')
|
|
216
|
+
})
|
|
217
|
+
|
|
218
|
+
test('oneOf and $ref: 2 levels are fine', (t) => {
|
|
219
|
+
t.plan(1)
|
|
220
|
+
|
|
221
|
+
const schema = {
|
|
222
|
+
type: 'object',
|
|
223
|
+
properties: {
|
|
224
|
+
cs: {
|
|
225
|
+
oneOf: [
|
|
226
|
+
{
|
|
227
|
+
$ref: '#/definitions/Option'
|
|
228
|
+
},
|
|
229
|
+
{
|
|
230
|
+
type: 'boolean'
|
|
231
|
+
}
|
|
232
|
+
]
|
|
233
|
+
}
|
|
234
|
+
},
|
|
235
|
+
definitions: {
|
|
236
|
+
Option: {
|
|
237
|
+
oneOf: [
|
|
238
|
+
{
|
|
239
|
+
type: 'number'
|
|
240
|
+
},
|
|
241
|
+
{
|
|
242
|
+
type: 'boolean'
|
|
243
|
+
}
|
|
244
|
+
]
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
const stringify = build(schema)
|
|
250
|
+
const value = stringify({
|
|
251
|
+
cs: 3
|
|
252
|
+
})
|
|
253
|
+
t.assert.equal(value, '{"cs":3}')
|
|
254
|
+
})
|
|
255
|
+
|
|
256
|
+
test('oneOf and $ref: multiple levels should throw at build.', (t) => {
|
|
257
|
+
t.plan(3)
|
|
258
|
+
|
|
259
|
+
const schema = {
|
|
260
|
+
type: 'object',
|
|
261
|
+
properties: {
|
|
262
|
+
cs: {
|
|
263
|
+
oneOf: [
|
|
264
|
+
{
|
|
265
|
+
$ref: '#/definitions/Option'
|
|
266
|
+
},
|
|
267
|
+
{
|
|
268
|
+
type: 'boolean'
|
|
269
|
+
}
|
|
270
|
+
]
|
|
271
|
+
}
|
|
272
|
+
},
|
|
273
|
+
definitions: {
|
|
274
|
+
Option: {
|
|
275
|
+
oneOf: [
|
|
276
|
+
{
|
|
277
|
+
$ref: '#/definitions/Option2'
|
|
278
|
+
},
|
|
279
|
+
{
|
|
280
|
+
type: 'string'
|
|
281
|
+
}
|
|
282
|
+
]
|
|
283
|
+
},
|
|
284
|
+
Option2: {
|
|
285
|
+
type: 'number'
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
const stringify = build(schema)
|
|
291
|
+
|
|
292
|
+
t.assert.equal(stringify({ cs: 3 }), '{"cs":3}')
|
|
293
|
+
t.assert.equal(stringify({ cs: true }), '{"cs":true}')
|
|
294
|
+
t.assert.equal(stringify({ cs: 'pippo' }), '{"cs":"pippo"}')
|
|
295
|
+
})
|
|
296
|
+
|
|
297
|
+
test('oneOf and $ref - multiple external $ref', (t) => {
|
|
298
|
+
t.plan(2)
|
|
299
|
+
|
|
300
|
+
const externalSchema = {
|
|
301
|
+
external: {
|
|
302
|
+
definitions: {
|
|
303
|
+
def: {
|
|
304
|
+
type: 'object',
|
|
305
|
+
properties: {
|
|
306
|
+
prop: { oneOf: [{ $ref: 'external2#/definitions/other' }] }
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
},
|
|
311
|
+
external2: {
|
|
312
|
+
definitions: {
|
|
313
|
+
internal: {
|
|
314
|
+
type: 'string'
|
|
315
|
+
},
|
|
316
|
+
other: {
|
|
317
|
+
type: 'object',
|
|
318
|
+
properties: {
|
|
319
|
+
prop2: { $ref: '#/definitions/internal' }
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
const schema = {
|
|
327
|
+
title: 'object with $ref',
|
|
328
|
+
type: 'object',
|
|
329
|
+
properties: {
|
|
330
|
+
obj: {
|
|
331
|
+
$ref: 'external#/definitions/def'
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
const object = {
|
|
337
|
+
obj: {
|
|
338
|
+
prop: {
|
|
339
|
+
prop2: 'test'
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
const stringify = build(schema, { schema: externalSchema })
|
|
345
|
+
const output = stringify(object)
|
|
346
|
+
|
|
347
|
+
t.assert.doesNotThrow(() => JSON.parse(output))
|
|
348
|
+
t.assert.equal(output, '{"obj":{"prop":{"prop2":"test"}}}')
|
|
349
|
+
})
|
|
350
|
+
|
|
351
|
+
test('oneOf with enum with more than 100 entries', (t) => {
|
|
352
|
+
t.plan(1)
|
|
353
|
+
|
|
354
|
+
const schema = {
|
|
355
|
+
title: 'type array that may have one of declared items',
|
|
356
|
+
type: 'array',
|
|
357
|
+
items: {
|
|
358
|
+
oneOf: [
|
|
359
|
+
{
|
|
360
|
+
type: 'string',
|
|
361
|
+
enum: ['EUR', 'USD', ...(new Set([...new Array(200)].map(() => Math.random().toString(36).substr(2, 3)))).values()]
|
|
362
|
+
},
|
|
363
|
+
{ type: 'null' }
|
|
364
|
+
]
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
const stringify = build(schema)
|
|
368
|
+
|
|
369
|
+
const value = stringify(['EUR', 'USD', null])
|
|
370
|
+
t.assert.equal(value, '["EUR","USD",null]')
|
|
371
|
+
})
|
|
372
|
+
|
|
373
|
+
test('oneOf object with field of type string with format or null', (t) => {
|
|
374
|
+
t.plan(1)
|
|
375
|
+
|
|
376
|
+
const toStringify = new Date()
|
|
377
|
+
|
|
378
|
+
const withOneOfSchema = {
|
|
379
|
+
type: 'object',
|
|
380
|
+
properties: {
|
|
381
|
+
prop: {
|
|
382
|
+
oneOf: [{
|
|
383
|
+
type: 'string',
|
|
384
|
+
format: 'date-time'
|
|
385
|
+
}, {
|
|
386
|
+
type: 'null'
|
|
387
|
+
}]
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
const withOneOfStringify = build(withOneOfSchema)
|
|
393
|
+
|
|
394
|
+
t.assert.equal(withOneOfStringify({
|
|
395
|
+
prop: toStringify
|
|
396
|
+
}), `{"prop":"${toStringify.toISOString()}"}`)
|
|
397
|
+
})
|
|
398
|
+
|
|
399
|
+
test('one array item match oneOf types', (t) => {
|
|
400
|
+
t.plan(3)
|
|
401
|
+
|
|
402
|
+
const schema = {
|
|
403
|
+
type: 'object',
|
|
404
|
+
additionalProperties: false,
|
|
405
|
+
required: ['data'],
|
|
406
|
+
properties: {
|
|
407
|
+
data: {
|
|
408
|
+
type: 'array',
|
|
409
|
+
minItems: 1,
|
|
410
|
+
items: {
|
|
411
|
+
oneOf: [
|
|
412
|
+
{
|
|
413
|
+
type: 'string'
|
|
414
|
+
},
|
|
415
|
+
{
|
|
416
|
+
type: 'number'
|
|
417
|
+
}
|
|
418
|
+
]
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
const stringify = build(schema)
|
|
425
|
+
|
|
426
|
+
t.assert.equal(stringify({ data: ['foo'] }), '{"data":["foo"]}')
|
|
427
|
+
t.assert.equal(stringify({ data: [1] }), '{"data":[1]}')
|
|
428
|
+
t.assert.throws(() => stringify({ data: [false, 'foo'] }))
|
|
429
|
+
})
|
|
430
|
+
|
|
431
|
+
test('some array items match oneOf types', (t) => {
|
|
432
|
+
t.plan(2)
|
|
433
|
+
|
|
434
|
+
const schema = {
|
|
435
|
+
type: 'object',
|
|
436
|
+
additionalProperties: false,
|
|
437
|
+
required: ['data'],
|
|
438
|
+
properties: {
|
|
439
|
+
data: {
|
|
440
|
+
type: 'array',
|
|
441
|
+
minItems: 1,
|
|
442
|
+
items: {
|
|
443
|
+
oneOf: [
|
|
444
|
+
{
|
|
445
|
+
type: 'string'
|
|
446
|
+
},
|
|
447
|
+
{
|
|
448
|
+
type: 'number'
|
|
449
|
+
}
|
|
450
|
+
]
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
const stringify = build(schema)
|
|
457
|
+
|
|
458
|
+
t.assert.equal(stringify({ data: ['foo', 5] }), '{"data":["foo",5]}')
|
|
459
|
+
t.assert.throws(() => stringify({ data: [false, 'foo', true, 5] }))
|
|
460
|
+
})
|
|
461
|
+
|
|
462
|
+
test('all array items does not match oneOf types', (t) => {
|
|
463
|
+
t.plan(1)
|
|
464
|
+
|
|
465
|
+
const schema = {
|
|
466
|
+
type: 'object',
|
|
467
|
+
additionalProperties: false,
|
|
468
|
+
required: ['data'],
|
|
469
|
+
properties: {
|
|
470
|
+
data: {
|
|
471
|
+
type: 'array',
|
|
472
|
+
minItems: 1,
|
|
473
|
+
items: {
|
|
474
|
+
oneOf: [
|
|
475
|
+
{
|
|
476
|
+
type: 'string'
|
|
477
|
+
},
|
|
478
|
+
{
|
|
479
|
+
type: 'number'
|
|
480
|
+
}
|
|
481
|
+
]
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
const stringify = build(schema)
|
|
488
|
+
|
|
489
|
+
t.assert.throws(() => stringify({ data: [null, false, true, undefined, [], {}] }))
|
|
490
|
+
})
|
|
491
|
+
|
|
492
|
+
test('invalid oneOf schema', (t) => {
|
|
493
|
+
t.plan(1)
|
|
494
|
+
|
|
495
|
+
const schema = {
|
|
496
|
+
type: 'object',
|
|
497
|
+
properties: {
|
|
498
|
+
prop: {
|
|
499
|
+
oneOf: 'not array' // invalid, oneOf must be array
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
try {
|
|
505
|
+
build(schema)
|
|
506
|
+
t.assert.fail('Should throw')
|
|
507
|
+
} catch (err) {
|
|
508
|
+
t.assert.ok(err.message.includes('schema is invalid'))
|
|
509
|
+
}
|
|
510
|
+
})
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const { test } = require('node:test')
|
|
4
|
+
const build = require('..')
|
|
5
|
+
|
|
6
|
+
test('patternProperties', (t) => {
|
|
7
|
+
t.plan(1)
|
|
8
|
+
const stringify = build({
|
|
9
|
+
title: 'patternProperties',
|
|
10
|
+
type: 'object',
|
|
11
|
+
properties: {
|
|
12
|
+
str: {
|
|
13
|
+
type: 'string'
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
patternProperties: {
|
|
17
|
+
foo: {
|
|
18
|
+
type: 'string'
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
const obj = { str: 'test', foo: 42, ofoo: true, foof: 'string', objfoo: { a: true }, notMe: false }
|
|
24
|
+
t.assert.equal(stringify(obj), '{"str":"test","foo":"42","ofoo":"true","foof":"string","objfoo":"[object Object]"}')
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
test('patternProperties should not change properties', (t) => {
|
|
28
|
+
t.plan(1)
|
|
29
|
+
const stringify = build({
|
|
30
|
+
title: 'patternProperties should not change properties',
|
|
31
|
+
type: 'object',
|
|
32
|
+
properties: {
|
|
33
|
+
foo: {
|
|
34
|
+
type: 'string'
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
patternProperties: {
|
|
38
|
+
foo: {
|
|
39
|
+
type: 'number'
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
const obj = { foo: '42', ofoo: 42 }
|
|
45
|
+
t.assert.equal(stringify(obj), '{"foo":"42","ofoo":42}')
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
test('patternProperties - string coerce', (t) => {
|
|
49
|
+
t.plan(1)
|
|
50
|
+
const stringify = build({
|
|
51
|
+
title: 'check string coerce',
|
|
52
|
+
type: 'object',
|
|
53
|
+
properties: {},
|
|
54
|
+
patternProperties: {
|
|
55
|
+
foo: {
|
|
56
|
+
type: 'string'
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
const obj = { foo: true, ofoo: 42, arrfoo: ['array', 'test'], objfoo: { a: 'world' } }
|
|
62
|
+
t.assert.equal(stringify(obj), '{"foo":"true","ofoo":"42","arrfoo":"array,test","objfoo":"[object Object]"}')
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
test('patternProperties - number coerce', (t) => {
|
|
66
|
+
t.plan(2)
|
|
67
|
+
const stringify = build({
|
|
68
|
+
title: 'check number coerce',
|
|
69
|
+
type: 'object',
|
|
70
|
+
properties: {},
|
|
71
|
+
patternProperties: {
|
|
72
|
+
foo: {
|
|
73
|
+
type: 'number'
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
})
|
|
77
|
+
|
|
78
|
+
const coercibleValues = { foo: true, ofoo: '42' }
|
|
79
|
+
t.assert.equal(stringify(coercibleValues), '{"foo":1,"ofoo":42}')
|
|
80
|
+
|
|
81
|
+
const incoercibleValues = { xfoo: 'string', arrfoo: [1, 2], objfoo: { num: 42 } }
|
|
82
|
+
try {
|
|
83
|
+
stringify(incoercibleValues)
|
|
84
|
+
t.fail('should throw an error')
|
|
85
|
+
} catch (err) {
|
|
86
|
+
t.assert.ok(err)
|
|
87
|
+
}
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
test('patternProperties - boolean coerce', (t) => {
|
|
91
|
+
t.plan(1)
|
|
92
|
+
const stringify = build({
|
|
93
|
+
title: 'check boolean coerce',
|
|
94
|
+
type: 'object',
|
|
95
|
+
properties: {},
|
|
96
|
+
patternProperties: {
|
|
97
|
+
foo: {
|
|
98
|
+
type: 'boolean'
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
})
|
|
102
|
+
|
|
103
|
+
const obj = { foo: 'true', ofoo: 0, arrfoo: [1, 2], objfoo: { a: true } }
|
|
104
|
+
t.assert.equal(stringify(obj), '{"foo":true,"ofoo":false,"arrfoo":true,"objfoo":true}')
|
|
105
|
+
})
|
|
106
|
+
|
|
107
|
+
test('patternProperties - object coerce', (t) => {
|
|
108
|
+
t.plan(1)
|
|
109
|
+
const stringify = build({
|
|
110
|
+
title: 'check object coerce',
|
|
111
|
+
type: 'object',
|
|
112
|
+
properties: {},
|
|
113
|
+
patternProperties: {
|
|
114
|
+
foo: {
|
|
115
|
+
type: 'object',
|
|
116
|
+
properties: {
|
|
117
|
+
answer: {
|
|
118
|
+
type: 'number'
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
})
|
|
124
|
+
|
|
125
|
+
const obj = { objfoo: { answer: 42 } }
|
|
126
|
+
t.assert.equal(stringify(obj), '{"objfoo":{"answer":42}}')
|
|
127
|
+
})
|
|
128
|
+
|
|
129
|
+
test('patternProperties - array coerce', (t) => {
|
|
130
|
+
t.plan(2)
|
|
131
|
+
const stringify = build({
|
|
132
|
+
title: 'check array coerce',
|
|
133
|
+
type: 'object',
|
|
134
|
+
properties: {},
|
|
135
|
+
patternProperties: {
|
|
136
|
+
foo: {
|
|
137
|
+
type: 'array',
|
|
138
|
+
items: {
|
|
139
|
+
type: 'string'
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
})
|
|
144
|
+
|
|
145
|
+
const coercibleValues = { arrfoo: [1, 2] }
|
|
146
|
+
t.assert.equal(stringify(coercibleValues), '{"arrfoo":["1","2"]}')
|
|
147
|
+
|
|
148
|
+
const incoercibleValues = { foo: 'true', ofoo: 0, objfoo: { tyrion: 'lannister' } }
|
|
149
|
+
t.assert.throws(() => stringify(incoercibleValues))
|
|
150
|
+
})
|
|
151
|
+
|
|
152
|
+
test('patternProperties - fail on invalid regex, handled by ajv', (t) => {
|
|
153
|
+
t.plan(1)
|
|
154
|
+
|
|
155
|
+
t.assert.throws(() => build({
|
|
156
|
+
title: 'check array coerce',
|
|
157
|
+
type: 'object',
|
|
158
|
+
properties: {},
|
|
159
|
+
patternProperties: {
|
|
160
|
+
'foo/\\': {
|
|
161
|
+
type: 'array',
|
|
162
|
+
items: {
|
|
163
|
+
type: 'string'
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}), new Error('schema is invalid: data/patternProperties must match format "regex"'))
|
|
168
|
+
})
|