osury 1.0.1 → 1.2.0
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/dist/osury.mjs +4041 -0
- package/package.json +6 -20
- package/bin/osury.mjs +0 -547
- package/src/BackendReScript.res.mjs +0 -157
- package/src/Codegen.res.mjs +0 -160
- package/src/CodegenHelpers.res.mjs +0 -233
- package/src/CodegenShims.res.mjs +0 -44
- package/src/CodegenTransforms.res.mjs +0 -794
- package/src/CodegenTypes.res.mjs +0 -187
- package/src/DomainBackend.res.mjs +0 -41
- package/src/DomainConfig.res.mjs +0 -206
- package/src/DomainGen.res.mjs +0 -53
- package/src/DomainIR.res.mjs +0 -2
- package/src/Errors.res.mjs +0 -106
- package/src/IR.res.mjs +0 -2
- package/src/IRGen.res.mjs +0 -367
- package/src/OpenAPIParser.res.mjs +0 -724
- package/src/Schema.gen.tsx +0 -28
- package/src/Schema.res.mjs +0 -877
package/src/Schema.res.mjs
DELETED
|
@@ -1,877 +0,0 @@
|
|
|
1
|
-
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
|
-
|
|
3
|
-
import * as Errors from "./Errors.res.mjs";
|
|
4
|
-
import * as Core__Array from "@rescript/core/src/Core__Array.res.mjs";
|
|
5
|
-
import * as Core__Option from "@rescript/core/src/Core__Option.res.mjs";
|
|
6
|
-
import * as Primitive_option from "@rescript/runtime/lib/es6/Primitive_option.js";
|
|
7
|
-
|
|
8
|
-
function isNullType(json) {
|
|
9
|
-
if (typeof json !== "object" || json === null || Array.isArray(json)) {
|
|
10
|
-
return false;
|
|
11
|
-
}
|
|
12
|
-
let match = json["type"];
|
|
13
|
-
return match === "null";
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
function hasDefault(json) {
|
|
17
|
-
if (typeof json === "object" && json !== null && !Array.isArray(json)) {
|
|
18
|
-
return Core__Option.isSome(json["default"]);
|
|
19
|
-
} else {
|
|
20
|
-
return false;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
function extractRefName(refPath) {
|
|
25
|
-
let parts = refPath.split("/");
|
|
26
|
-
return Core__Option.getOr(parts[parts.length - 1 | 0], refPath);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function parseEnumValues(arr) {
|
|
30
|
-
let values = Core__Array.filterMap(arr, item => {
|
|
31
|
-
if (typeof item === "string") {
|
|
32
|
-
return item;
|
|
33
|
-
}
|
|
34
|
-
});
|
|
35
|
-
if (values.length === arr.length) {
|
|
36
|
-
return values;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
function extractTagFromConst(dict) {
|
|
41
|
-
let match = dict["_tag"];
|
|
42
|
-
if (match === undefined) {
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
if (typeof match !== "object" || match === null || Array.isArray(match)) {
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
48
|
-
let match$1 = match["const"];
|
|
49
|
-
if (typeof match$1 === "string") {
|
|
50
|
-
return match$1;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
function extractTagFromProperty(dict, propertyName) {
|
|
55
|
-
let match = dict[propertyName];
|
|
56
|
-
if (match === undefined) {
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
if (typeof match !== "object" || match === null || Array.isArray(match)) {
|
|
60
|
-
return;
|
|
61
|
-
}
|
|
62
|
-
let match$1 = match["const"];
|
|
63
|
-
if (typeof match$1 === "string") {
|
|
64
|
-
return match$1;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
function extractDiscriminatorPropertyName(dict) {
|
|
69
|
-
let match = dict["discriminator"];
|
|
70
|
-
if (match === undefined) {
|
|
71
|
-
return;
|
|
72
|
-
}
|
|
73
|
-
if (typeof match !== "object" || match === null || Array.isArray(match)) {
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
|
-
let match$1 = match["propertyName"];
|
|
77
|
-
if (typeof match$1 === "string") {
|
|
78
|
-
return match$1;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
function parseSchema(json) {
|
|
83
|
-
if (typeof json === "object" && json !== null && !Array.isArray(json)) {
|
|
84
|
-
return parseObject(json);
|
|
85
|
-
}
|
|
86
|
-
return {
|
|
87
|
-
TAG: "Error",
|
|
88
|
-
_0: [Errors.makeError({
|
|
89
|
-
TAG: "InvalidJson",
|
|
90
|
-
_0: "expected object"
|
|
91
|
-
}, undefined, undefined, undefined)]
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
function parsePrimitiveType(dict) {
|
|
96
|
-
let match = dict["type"];
|
|
97
|
-
if (match !== undefined) {
|
|
98
|
-
if (Array.isArray(match)) {
|
|
99
|
-
let typeStrings = Core__Array.filterMap(match, t => {
|
|
100
|
-
if (typeof t === "string") {
|
|
101
|
-
return t;
|
|
102
|
-
}
|
|
103
|
-
});
|
|
104
|
-
let hasNull = typeStrings.includes("null");
|
|
105
|
-
let nonNullTypes = typeStrings.filter(t => t !== "null");
|
|
106
|
-
if (!hasNull) {
|
|
107
|
-
return {
|
|
108
|
-
TAG: "Error",
|
|
109
|
-
_0: [Errors.makeError({
|
|
110
|
-
TAG: "UnsupportedFeature",
|
|
111
|
-
_0: "type array without null"
|
|
112
|
-
}, undefined, undefined, undefined)]
|
|
113
|
-
};
|
|
114
|
-
}
|
|
115
|
-
if (nonNullTypes.length !== 1) {
|
|
116
|
-
return {
|
|
117
|
-
TAG: "Error",
|
|
118
|
-
_0: [Errors.makeError({
|
|
119
|
-
TAG: "InvalidJson",
|
|
120
|
-
_0: "type array must have exactly one non-null type"
|
|
121
|
-
}, undefined, undefined, undefined)]
|
|
122
|
-
};
|
|
123
|
-
}
|
|
124
|
-
let nonNullType = nonNullTypes[0];
|
|
125
|
-
let newDict = Object.fromEntries(Object.entries(dict).map(param => {
|
|
126
|
-
let k = param[0];
|
|
127
|
-
if (k === "type") {
|
|
128
|
-
return [
|
|
129
|
-
k,
|
|
130
|
-
nonNullType
|
|
131
|
-
];
|
|
132
|
-
} else {
|
|
133
|
-
return [
|
|
134
|
-
k,
|
|
135
|
-
param[1]
|
|
136
|
-
];
|
|
137
|
-
}
|
|
138
|
-
}));
|
|
139
|
-
let inner = parsePrimitiveType(newDict);
|
|
140
|
-
if (inner.TAG === "Ok") {
|
|
141
|
-
return {
|
|
142
|
-
TAG: "Ok",
|
|
143
|
-
_0: {
|
|
144
|
-
_tag: "Nullable",
|
|
145
|
-
_0: inner._0
|
|
146
|
-
}
|
|
147
|
-
};
|
|
148
|
-
} else {
|
|
149
|
-
return {
|
|
150
|
-
TAG: "Error",
|
|
151
|
-
_0: inner._0
|
|
152
|
-
};
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
switch (typeof match) {
|
|
156
|
-
case "string" :
|
|
157
|
-
switch (match) {
|
|
158
|
-
case "array" :
|
|
159
|
-
return parseArrayType(dict);
|
|
160
|
-
case "boolean" :
|
|
161
|
-
return {
|
|
162
|
-
TAG: "Ok",
|
|
163
|
-
_0: "Boolean"
|
|
164
|
-
};
|
|
165
|
-
case "integer" :
|
|
166
|
-
return {
|
|
167
|
-
TAG: "Ok",
|
|
168
|
-
_0: "Integer"
|
|
169
|
-
};
|
|
170
|
-
case "null" :
|
|
171
|
-
return {
|
|
172
|
-
TAG: "Ok",
|
|
173
|
-
_0: "Null"
|
|
174
|
-
};
|
|
175
|
-
case "number" :
|
|
176
|
-
return {
|
|
177
|
-
TAG: "Ok",
|
|
178
|
-
_0: "Number"
|
|
179
|
-
};
|
|
180
|
-
case "object" :
|
|
181
|
-
return parseObjectType(dict);
|
|
182
|
-
case "string" :
|
|
183
|
-
let match$1 = dict["const"];
|
|
184
|
-
let exit = 0;
|
|
185
|
-
if (match$1 !== undefined) {
|
|
186
|
-
if (typeof match$1 === "string") {
|
|
187
|
-
return {
|
|
188
|
-
TAG: "Ok",
|
|
189
|
-
_0: {
|
|
190
|
-
_tag: "Enum",
|
|
191
|
-
_0: [match$1]
|
|
192
|
-
}
|
|
193
|
-
};
|
|
194
|
-
}
|
|
195
|
-
exit = 2;
|
|
196
|
-
} else {
|
|
197
|
-
exit = 2;
|
|
198
|
-
}
|
|
199
|
-
if (exit === 2) {
|
|
200
|
-
let match$2 = dict["enum"];
|
|
201
|
-
if (match$2 === undefined) {
|
|
202
|
-
return {
|
|
203
|
-
TAG: "Ok",
|
|
204
|
-
_0: "String"
|
|
205
|
-
};
|
|
206
|
-
}
|
|
207
|
-
let exit$1 = 0;
|
|
208
|
-
if (Array.isArray(match$2)) {
|
|
209
|
-
let values = parseEnumValues(match$2);
|
|
210
|
-
if (values !== undefined) {
|
|
211
|
-
return {
|
|
212
|
-
TAG: "Ok",
|
|
213
|
-
_0: {
|
|
214
|
-
_tag: "Enum",
|
|
215
|
-
_0: values
|
|
216
|
-
}
|
|
217
|
-
};
|
|
218
|
-
} else {
|
|
219
|
-
return {
|
|
220
|
-
TAG: "Error",
|
|
221
|
-
_0: [Errors.makeError({
|
|
222
|
-
TAG: "InvalidJson",
|
|
223
|
-
_0: "enum values must be strings"
|
|
224
|
-
}, undefined, undefined, undefined)]
|
|
225
|
-
};
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
exit$1 = 3;
|
|
229
|
-
if (exit$1 === 3) {
|
|
230
|
-
return {
|
|
231
|
-
TAG: "Error",
|
|
232
|
-
_0: [Errors.makeError({
|
|
233
|
-
TAG: "InvalidJson",
|
|
234
|
-
_0: "enum must be an array"
|
|
235
|
-
}, undefined, undefined, undefined)]
|
|
236
|
-
};
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
break;
|
|
240
|
-
default:
|
|
241
|
-
return {
|
|
242
|
-
TAG: "Error",
|
|
243
|
-
_0: [Errors.unknownType(match, undefined, undefined, undefined)]
|
|
244
|
-
};
|
|
245
|
-
}
|
|
246
|
-
break;
|
|
247
|
-
}
|
|
248
|
-
return {
|
|
249
|
-
TAG: "Error",
|
|
250
|
-
_0: [Errors.makeError({
|
|
251
|
-
TAG: "InvalidJson",
|
|
252
|
-
_0: "type must be a string or array"
|
|
253
|
-
}, undefined, undefined, undefined)]
|
|
254
|
-
};
|
|
255
|
-
}
|
|
256
|
-
let match$3 = dict["properties"];
|
|
257
|
-
if (match$3 !== undefined) {
|
|
258
|
-
return parseObjectType(dict);
|
|
259
|
-
} else {
|
|
260
|
-
return {
|
|
261
|
-
TAG: "Ok",
|
|
262
|
-
_0: "Unknown"
|
|
263
|
-
};
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
function parseArrayType(dict) {
|
|
268
|
-
let itemSchema = dict["items"];
|
|
269
|
-
if (itemSchema === undefined) {
|
|
270
|
-
return {
|
|
271
|
-
TAG: "Error",
|
|
272
|
-
_0: [Errors.missingField("items", undefined, "array type requires items schema", undefined)]
|
|
273
|
-
};
|
|
274
|
-
}
|
|
275
|
-
let itemType = parseSchema(itemSchema);
|
|
276
|
-
if (itemType.TAG === "Ok") {
|
|
277
|
-
return {
|
|
278
|
-
TAG: "Ok",
|
|
279
|
-
_0: {
|
|
280
|
-
_tag: "Array",
|
|
281
|
-
_0: itemType._0
|
|
282
|
-
}
|
|
283
|
-
};
|
|
284
|
-
} else {
|
|
285
|
-
return {
|
|
286
|
-
TAG: "Error",
|
|
287
|
-
_0: itemType._0
|
|
288
|
-
};
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
function parseAnyOf(items) {
|
|
293
|
-
let hasNull = items.some(isNullType);
|
|
294
|
-
let nonNullItems = items.filter(item => !isNullType(item));
|
|
295
|
-
if (hasNull && nonNullItems.length === 1) {
|
|
296
|
-
let match = nonNullItems[0];
|
|
297
|
-
if (match === undefined) {
|
|
298
|
-
return {
|
|
299
|
-
TAG: "Error",
|
|
300
|
-
_0: [Errors.makeError({
|
|
301
|
-
TAG: "InvalidJson",
|
|
302
|
-
_0: "anyOf with only null types"
|
|
303
|
-
}, undefined, undefined, undefined)]
|
|
304
|
-
};
|
|
305
|
-
}
|
|
306
|
-
if (typeof match === "object" && match !== null && !Array.isArray(match)) {
|
|
307
|
-
let innerType = parseObject(match);
|
|
308
|
-
if (innerType.TAG === "Ok") {
|
|
309
|
-
return {
|
|
310
|
-
TAG: "Ok",
|
|
311
|
-
_0: {
|
|
312
|
-
_tag: "Nullable",
|
|
313
|
-
_0: innerType._0
|
|
314
|
-
}
|
|
315
|
-
};
|
|
316
|
-
} else {
|
|
317
|
-
return {
|
|
318
|
-
TAG: "Error",
|
|
319
|
-
_0: innerType._0
|
|
320
|
-
};
|
|
321
|
-
}
|
|
322
|
-
}
|
|
323
|
-
return {
|
|
324
|
-
TAG: "Error",
|
|
325
|
-
_0: [Errors.makeError({
|
|
326
|
-
TAG: "InvalidJson",
|
|
327
|
-
_0: "anyOf item must be object"
|
|
328
|
-
}, undefined, undefined, undefined)]
|
|
329
|
-
};
|
|
330
|
-
}
|
|
331
|
-
if (!hasNull && nonNullItems.length >= 2) {
|
|
332
|
-
let results = nonNullItems.map(parseSchema);
|
|
333
|
-
let errors = Core__Array.filterMap(results, r => {
|
|
334
|
-
if (r.TAG === "Ok") {
|
|
335
|
-
return;
|
|
336
|
-
} else {
|
|
337
|
-
return r._0;
|
|
338
|
-
}
|
|
339
|
-
}).flat();
|
|
340
|
-
if (errors.length > 0) {
|
|
341
|
-
return {
|
|
342
|
-
TAG: "Error",
|
|
343
|
-
_0: errors
|
|
344
|
-
};
|
|
345
|
-
}
|
|
346
|
-
let types = Core__Array.filterMap(results, r => {
|
|
347
|
-
if (r.TAG === "Ok") {
|
|
348
|
-
return r._0;
|
|
349
|
-
}
|
|
350
|
-
});
|
|
351
|
-
return {
|
|
352
|
-
TAG: "Ok",
|
|
353
|
-
_0: {
|
|
354
|
-
_tag: "Union",
|
|
355
|
-
_0: types
|
|
356
|
-
}
|
|
357
|
-
};
|
|
358
|
-
}
|
|
359
|
-
if (!(hasNull && nonNullItems.length >= 2)) {
|
|
360
|
-
return {
|
|
361
|
-
TAG: "Error",
|
|
362
|
-
_0: [Errors.makeError({
|
|
363
|
-
TAG: "InvalidJson",
|
|
364
|
-
_0: "anyOf must have at least 2 items"
|
|
365
|
-
}, undefined, undefined, undefined)]
|
|
366
|
-
};
|
|
367
|
-
}
|
|
368
|
-
let results$1 = nonNullItems.map(parseSchema);
|
|
369
|
-
let errors$1 = Core__Array.filterMap(results$1, r => {
|
|
370
|
-
if (r.TAG === "Ok") {
|
|
371
|
-
return;
|
|
372
|
-
} else {
|
|
373
|
-
return r._0;
|
|
374
|
-
}
|
|
375
|
-
}).flat();
|
|
376
|
-
if (errors$1.length > 0) {
|
|
377
|
-
return {
|
|
378
|
-
TAG: "Error",
|
|
379
|
-
_0: errors$1
|
|
380
|
-
};
|
|
381
|
-
}
|
|
382
|
-
let types$1 = Core__Array.filterMap(results$1, r => {
|
|
383
|
-
if (r.TAG === "Ok") {
|
|
384
|
-
return r._0;
|
|
385
|
-
}
|
|
386
|
-
});
|
|
387
|
-
return {
|
|
388
|
-
TAG: "Ok",
|
|
389
|
-
_0: {
|
|
390
|
-
_tag: "Nullable",
|
|
391
|
-
_0: {
|
|
392
|
-
_tag: "Union",
|
|
393
|
-
_0: types$1
|
|
394
|
-
}
|
|
395
|
-
}
|
|
396
|
-
};
|
|
397
|
-
}
|
|
398
|
-
|
|
399
|
-
function parseObjectType(dict) {
|
|
400
|
-
let valueSchema = dict["additionalProperties"];
|
|
401
|
-
let exit = 0;
|
|
402
|
-
if (valueSchema !== undefined) {
|
|
403
|
-
switch (typeof valueSchema) {
|
|
404
|
-
case "boolean" :
|
|
405
|
-
if (valueSchema) {
|
|
406
|
-
return {
|
|
407
|
-
TAG: "Ok",
|
|
408
|
-
_0: {
|
|
409
|
-
_tag: "Dict",
|
|
410
|
-
_0: "String"
|
|
411
|
-
}
|
|
412
|
-
};
|
|
413
|
-
}
|
|
414
|
-
exit = 1;
|
|
415
|
-
break;
|
|
416
|
-
case "object" :
|
|
417
|
-
let valueType = parseSchema(valueSchema);
|
|
418
|
-
if (valueType.TAG === "Ok") {
|
|
419
|
-
return {
|
|
420
|
-
TAG: "Ok",
|
|
421
|
-
_0: {
|
|
422
|
-
_tag: "Dict",
|
|
423
|
-
_0: valueType._0
|
|
424
|
-
}
|
|
425
|
-
};
|
|
426
|
-
} else {
|
|
427
|
-
return {
|
|
428
|
-
TAG: "Error",
|
|
429
|
-
_0: valueType._0
|
|
430
|
-
};
|
|
431
|
-
}
|
|
432
|
-
default:
|
|
433
|
-
exit = 1;
|
|
434
|
-
}
|
|
435
|
-
} else {
|
|
436
|
-
exit = 1;
|
|
437
|
-
}
|
|
438
|
-
if (exit === 1) {
|
|
439
|
-
let match = dict["required"];
|
|
440
|
-
let requiredFields = match !== undefined ? (
|
|
441
|
-
Array.isArray(match) ? Core__Array.filterMap(match, item => {
|
|
442
|
-
if (typeof item === "string") {
|
|
443
|
-
return item;
|
|
444
|
-
}
|
|
445
|
-
}) : []
|
|
446
|
-
) : [];
|
|
447
|
-
let match$1 = dict["properties"];
|
|
448
|
-
if (match$1 === undefined) {
|
|
449
|
-
return {
|
|
450
|
-
TAG: "Ok",
|
|
451
|
-
_0: {
|
|
452
|
-
_tag: "Object",
|
|
453
|
-
_0: []
|
|
454
|
-
}
|
|
455
|
-
};
|
|
456
|
-
}
|
|
457
|
-
let exit$1 = 0;
|
|
458
|
-
if (typeof match$1 === "object" && match$1 !== null && !Array.isArray(match$1)) {
|
|
459
|
-
let entries = Object.entries(match$1).filter(param => param[0] !== "_tag");
|
|
460
|
-
let results = entries.map(param => {
|
|
461
|
-
let propSchema = param[1];
|
|
462
|
-
let name = param[0];
|
|
463
|
-
let propType = parseSchema(propSchema);
|
|
464
|
-
if (propType.TAG === "Ok") {
|
|
465
|
-
return {
|
|
466
|
-
TAG: "Ok",
|
|
467
|
-
_0: {
|
|
468
|
-
name: name,
|
|
469
|
-
type: propType._0,
|
|
470
|
-
required: requiredFields.includes(name) || hasDefault(propSchema)
|
|
471
|
-
}
|
|
472
|
-
};
|
|
473
|
-
} else {
|
|
474
|
-
return {
|
|
475
|
-
TAG: "Error",
|
|
476
|
-
_0: propType._0
|
|
477
|
-
};
|
|
478
|
-
}
|
|
479
|
-
});
|
|
480
|
-
let errors = Core__Array.filterMap(results, r => {
|
|
481
|
-
if (r.TAG === "Ok") {
|
|
482
|
-
return;
|
|
483
|
-
} else {
|
|
484
|
-
return r._0;
|
|
485
|
-
}
|
|
486
|
-
}).flat();
|
|
487
|
-
if (errors.length > 0) {
|
|
488
|
-
return {
|
|
489
|
-
TAG: "Error",
|
|
490
|
-
_0: errors
|
|
491
|
-
};
|
|
492
|
-
}
|
|
493
|
-
let fields = Core__Array.filterMap(results, r => {
|
|
494
|
-
if (r.TAG === "Ok") {
|
|
495
|
-
return r._0;
|
|
496
|
-
}
|
|
497
|
-
});
|
|
498
|
-
return {
|
|
499
|
-
TAG: "Ok",
|
|
500
|
-
_0: {
|
|
501
|
-
_tag: "Object",
|
|
502
|
-
_0: fields
|
|
503
|
-
}
|
|
504
|
-
};
|
|
505
|
-
}
|
|
506
|
-
exit$1 = 2;
|
|
507
|
-
if (exit$1 === 2) {
|
|
508
|
-
return {
|
|
509
|
-
TAG: "Error",
|
|
510
|
-
_0: [Errors.makeError({
|
|
511
|
-
TAG: "InvalidJson",
|
|
512
|
-
_0: "properties must be an object"
|
|
513
|
-
}, undefined, undefined, undefined)]
|
|
514
|
-
};
|
|
515
|
-
}
|
|
516
|
-
}
|
|
517
|
-
}
|
|
518
|
-
|
|
519
|
-
function parseAllOf(items) {
|
|
520
|
-
let results = items.map(parseSchema);
|
|
521
|
-
let errors = Core__Array.filterMap(results, r => {
|
|
522
|
-
if (r.TAG === "Ok") {
|
|
523
|
-
return;
|
|
524
|
-
} else {
|
|
525
|
-
return r._0;
|
|
526
|
-
}
|
|
527
|
-
}).flat();
|
|
528
|
-
if (errors.length > 0) {
|
|
529
|
-
return {
|
|
530
|
-
TAG: "Error",
|
|
531
|
-
_0: errors
|
|
532
|
-
};
|
|
533
|
-
}
|
|
534
|
-
let allFields = Core__Array.filterMap(results, r => {
|
|
535
|
-
if (r.TAG !== "Ok") {
|
|
536
|
-
return;
|
|
537
|
-
}
|
|
538
|
-
let fields = r._0;
|
|
539
|
-
if (typeof fields !== "object" || fields._tag !== "Object") {
|
|
540
|
-
return;
|
|
541
|
-
} else {
|
|
542
|
-
return fields._0;
|
|
543
|
-
}
|
|
544
|
-
}).flat();
|
|
545
|
-
return {
|
|
546
|
-
TAG: "Ok",
|
|
547
|
-
_0: {
|
|
548
|
-
_tag: "Object",
|
|
549
|
-
_0: allFields
|
|
550
|
-
}
|
|
551
|
-
};
|
|
552
|
-
}
|
|
553
|
-
|
|
554
|
-
function parseOneOf(items, discriminatorPropertyNameOpt) {
|
|
555
|
-
let discriminatorPropertyName = discriminatorPropertyNameOpt !== undefined ? Primitive_option.valFromOption(discriminatorPropertyNameOpt) : undefined;
|
|
556
|
-
let propName = Core__Option.getOr(discriminatorPropertyName, "_tag");
|
|
557
|
-
let caseResults = items.map(item => {
|
|
558
|
-
if (typeof item === "object" && item !== null && !Array.isArray(item)) {
|
|
559
|
-
let match = item["$ref"];
|
|
560
|
-
let exit = 0;
|
|
561
|
-
if (match !== undefined) {
|
|
562
|
-
if (typeof match === "string") {
|
|
563
|
-
let name = extractRefName(match);
|
|
564
|
-
return {
|
|
565
|
-
TAG: "Ok",
|
|
566
|
-
_0: {
|
|
567
|
-
_tag: name,
|
|
568
|
-
payload: {
|
|
569
|
-
_tag: "Ref",
|
|
570
|
-
_0: name
|
|
571
|
-
}
|
|
572
|
-
}
|
|
573
|
-
};
|
|
574
|
-
}
|
|
575
|
-
exit = 2;
|
|
576
|
-
} else {
|
|
577
|
-
exit = 2;
|
|
578
|
-
}
|
|
579
|
-
if (exit === 2) {
|
|
580
|
-
let match$1 = item["properties"];
|
|
581
|
-
let exit$1 = 0;
|
|
582
|
-
if (match$1 !== undefined) {
|
|
583
|
-
if (typeof match$1 === "object" && match$1 !== null && !Array.isArray(match$1)) {
|
|
584
|
-
let tag = extractTagFromProperty(match$1, propName);
|
|
585
|
-
if (tag === undefined) {
|
|
586
|
-
return {
|
|
587
|
-
TAG: "Error",
|
|
588
|
-
_0: [Errors.makeError({
|
|
589
|
-
TAG: "MissingRequiredField",
|
|
590
|
-
_0: propName + " with const"
|
|
591
|
-
}, undefined, undefined, undefined)]
|
|
592
|
-
};
|
|
593
|
-
}
|
|
594
|
-
let match$2 = item["required"];
|
|
595
|
-
let requiredFields = match$2 !== undefined ? (
|
|
596
|
-
Array.isArray(match$2) ? Core__Array.filterMap(match$2, i => {
|
|
597
|
-
if (typeof i === "string") {
|
|
598
|
-
return i;
|
|
599
|
-
}
|
|
600
|
-
}) : []
|
|
601
|
-
) : [];
|
|
602
|
-
let entries = Object.entries(match$1).filter(param => param[0] !== propName);
|
|
603
|
-
let fieldResults = entries.map(param => {
|
|
604
|
-
let name = param[0];
|
|
605
|
-
let propType = parseSchema(param[1]);
|
|
606
|
-
if (propType.TAG === "Ok") {
|
|
607
|
-
return {
|
|
608
|
-
TAG: "Ok",
|
|
609
|
-
_0: {
|
|
610
|
-
name: name,
|
|
611
|
-
type: propType._0,
|
|
612
|
-
required: requiredFields.includes(name)
|
|
613
|
-
}
|
|
614
|
-
};
|
|
615
|
-
} else {
|
|
616
|
-
return {
|
|
617
|
-
TAG: "Error",
|
|
618
|
-
_0: propType._0
|
|
619
|
-
};
|
|
620
|
-
}
|
|
621
|
-
});
|
|
622
|
-
let errors = Core__Array.filterMap(fieldResults, r => {
|
|
623
|
-
if (r.TAG === "Ok") {
|
|
624
|
-
return;
|
|
625
|
-
} else {
|
|
626
|
-
return r._0;
|
|
627
|
-
}
|
|
628
|
-
}).flat();
|
|
629
|
-
if (errors.length > 0) {
|
|
630
|
-
return {
|
|
631
|
-
TAG: "Error",
|
|
632
|
-
_0: errors
|
|
633
|
-
};
|
|
634
|
-
}
|
|
635
|
-
let fields = Core__Array.filterMap(fieldResults, r => {
|
|
636
|
-
if (r.TAG === "Ok") {
|
|
637
|
-
return r._0;
|
|
638
|
-
}
|
|
639
|
-
});
|
|
640
|
-
return {
|
|
641
|
-
TAG: "Ok",
|
|
642
|
-
_0: {
|
|
643
|
-
_tag: tag,
|
|
644
|
-
payload: {
|
|
645
|
-
_tag: "Object",
|
|
646
|
-
_0: fields
|
|
647
|
-
}
|
|
648
|
-
}
|
|
649
|
-
};
|
|
650
|
-
}
|
|
651
|
-
exit$1 = 3;
|
|
652
|
-
} else {
|
|
653
|
-
exit$1 = 3;
|
|
654
|
-
}
|
|
655
|
-
if (exit$1 === 3) {
|
|
656
|
-
return {
|
|
657
|
-
TAG: "Error",
|
|
658
|
-
_0: [Errors.makeError({
|
|
659
|
-
TAG: "InvalidJson",
|
|
660
|
-
_0: "oneOf item must have properties"
|
|
661
|
-
}, undefined, undefined, undefined)]
|
|
662
|
-
};
|
|
663
|
-
}
|
|
664
|
-
}
|
|
665
|
-
}
|
|
666
|
-
return {
|
|
667
|
-
TAG: "Error",
|
|
668
|
-
_0: [Errors.makeError({
|
|
669
|
-
TAG: "InvalidJson",
|
|
670
|
-
_0: "oneOf item must be object"
|
|
671
|
-
}, undefined, undefined, undefined)]
|
|
672
|
-
};
|
|
673
|
-
});
|
|
674
|
-
let errors = Core__Array.filterMap(caseResults, r => {
|
|
675
|
-
if (r.TAG === "Ok") {
|
|
676
|
-
return;
|
|
677
|
-
} else {
|
|
678
|
-
return r._0;
|
|
679
|
-
}
|
|
680
|
-
}).flat();
|
|
681
|
-
if (errors.length > 0) {
|
|
682
|
-
return {
|
|
683
|
-
TAG: "Error",
|
|
684
|
-
_0: errors
|
|
685
|
-
};
|
|
686
|
-
}
|
|
687
|
-
let cases = Core__Array.filterMap(caseResults, r => {
|
|
688
|
-
if (r.TAG === "Ok") {
|
|
689
|
-
return r._0;
|
|
690
|
-
}
|
|
691
|
-
});
|
|
692
|
-
return {
|
|
693
|
-
TAG: "Ok",
|
|
694
|
-
_0: {
|
|
695
|
-
_tag: "PolyVariant",
|
|
696
|
-
_0: cases
|
|
697
|
-
}
|
|
698
|
-
};
|
|
699
|
-
}
|
|
700
|
-
|
|
701
|
-
function applyNullable(dict, result) {
|
|
702
|
-
let match = dict["nullable"];
|
|
703
|
-
if (match === undefined) {
|
|
704
|
-
return result;
|
|
705
|
-
}
|
|
706
|
-
if (typeof match !== "boolean") {
|
|
707
|
-
return result;
|
|
708
|
-
}
|
|
709
|
-
if (!match) {
|
|
710
|
-
return result;
|
|
711
|
-
}
|
|
712
|
-
if (result.TAG !== "Ok") {
|
|
713
|
-
return result;
|
|
714
|
-
}
|
|
715
|
-
let t = result._0;
|
|
716
|
-
if (typeof t !== "object" || t._tag !== "Nullable") {
|
|
717
|
-
return {
|
|
718
|
-
TAG: "Ok",
|
|
719
|
-
_0: {
|
|
720
|
-
_tag: "Nullable",
|
|
721
|
-
_0: t
|
|
722
|
-
}
|
|
723
|
-
};
|
|
724
|
-
} else {
|
|
725
|
-
return {
|
|
726
|
-
TAG: "Ok",
|
|
727
|
-
_0: t
|
|
728
|
-
};
|
|
729
|
-
}
|
|
730
|
-
}
|
|
731
|
-
|
|
732
|
-
function parseObject(dict) {
|
|
733
|
-
let match = dict["$ref"];
|
|
734
|
-
if (match !== undefined) {
|
|
735
|
-
if (typeof match === "string") {
|
|
736
|
-
return applyNullable(dict, {
|
|
737
|
-
TAG: "Ok",
|
|
738
|
-
_0: {
|
|
739
|
-
_tag: "Ref",
|
|
740
|
-
_0: extractRefName(match)
|
|
741
|
-
}
|
|
742
|
-
});
|
|
743
|
-
}
|
|
744
|
-
return {
|
|
745
|
-
TAG: "Error",
|
|
746
|
-
_0: [Errors.makeError({
|
|
747
|
-
TAG: "InvalidJson",
|
|
748
|
-
_0: "$ref must be a string"
|
|
749
|
-
}, undefined, undefined, undefined)]
|
|
750
|
-
};
|
|
751
|
-
}
|
|
752
|
-
let match$1 = dict["oneOf"];
|
|
753
|
-
if (match$1 !== undefined) {
|
|
754
|
-
if (Array.isArray(match$1)) {
|
|
755
|
-
let hasNull = match$1.some(isNullType);
|
|
756
|
-
let nonNullItems = match$1.filter(item => !isNullType(item));
|
|
757
|
-
if (hasNull && nonNullItems.length === 1) {
|
|
758
|
-
let match$2 = nonNullItems[0];
|
|
759
|
-
if (match$2 === undefined) {
|
|
760
|
-
return {
|
|
761
|
-
TAG: "Error",
|
|
762
|
-
_0: [Errors.makeError({
|
|
763
|
-
TAG: "InvalidJson",
|
|
764
|
-
_0: "oneOf with only null types"
|
|
765
|
-
}, undefined, undefined, undefined)]
|
|
766
|
-
};
|
|
767
|
-
}
|
|
768
|
-
let exit = 0;
|
|
769
|
-
if (typeof match$2 === "object" && match$2 !== null && !Array.isArray(match$2)) {
|
|
770
|
-
let innerType = parseObject(match$2);
|
|
771
|
-
if (innerType.TAG === "Ok") {
|
|
772
|
-
return {
|
|
773
|
-
TAG: "Ok",
|
|
774
|
-
_0: {
|
|
775
|
-
_tag: "Nullable",
|
|
776
|
-
_0: innerType._0
|
|
777
|
-
}
|
|
778
|
-
};
|
|
779
|
-
} else {
|
|
780
|
-
return {
|
|
781
|
-
TAG: "Error",
|
|
782
|
-
_0: innerType._0
|
|
783
|
-
};
|
|
784
|
-
}
|
|
785
|
-
}
|
|
786
|
-
exit = 2;
|
|
787
|
-
if (exit === 2) {
|
|
788
|
-
return {
|
|
789
|
-
TAG: "Error",
|
|
790
|
-
_0: [Errors.makeError({
|
|
791
|
-
TAG: "InvalidJson",
|
|
792
|
-
_0: "oneOf item must be object"
|
|
793
|
-
}, undefined, undefined, undefined)]
|
|
794
|
-
};
|
|
795
|
-
}
|
|
796
|
-
} else {
|
|
797
|
-
if (hasNull && nonNullItems.length >= 2) {
|
|
798
|
-
let discriminatorPropName = extractDiscriminatorPropertyName(dict);
|
|
799
|
-
let inner = parseOneOf(nonNullItems, Primitive_option.some(discriminatorPropName));
|
|
800
|
-
if (inner.TAG === "Ok") {
|
|
801
|
-
return {
|
|
802
|
-
TAG: "Ok",
|
|
803
|
-
_0: {
|
|
804
|
-
_tag: "Nullable",
|
|
805
|
-
_0: inner._0
|
|
806
|
-
}
|
|
807
|
-
};
|
|
808
|
-
} else {
|
|
809
|
-
return {
|
|
810
|
-
TAG: "Error",
|
|
811
|
-
_0: inner._0
|
|
812
|
-
};
|
|
813
|
-
}
|
|
814
|
-
}
|
|
815
|
-
let discriminatorPropName$1 = extractDiscriminatorPropertyName(dict);
|
|
816
|
-
return parseOneOf(match$1, Primitive_option.some(discriminatorPropName$1));
|
|
817
|
-
}
|
|
818
|
-
}
|
|
819
|
-
return {
|
|
820
|
-
TAG: "Error",
|
|
821
|
-
_0: [Errors.makeError({
|
|
822
|
-
TAG: "InvalidJson",
|
|
823
|
-
_0: "oneOf must be an array"
|
|
824
|
-
}, undefined, undefined, undefined)]
|
|
825
|
-
};
|
|
826
|
-
}
|
|
827
|
-
let match$3 = dict["allOf"];
|
|
828
|
-
if (match$3 !== undefined) {
|
|
829
|
-
if (Array.isArray(match$3)) {
|
|
830
|
-
return parseAllOf(match$3);
|
|
831
|
-
}
|
|
832
|
-
return {
|
|
833
|
-
TAG: "Error",
|
|
834
|
-
_0: [Errors.makeError({
|
|
835
|
-
TAG: "InvalidJson",
|
|
836
|
-
_0: "allOf must be an array"
|
|
837
|
-
}, undefined, undefined, undefined)]
|
|
838
|
-
};
|
|
839
|
-
}
|
|
840
|
-
let match$4 = dict["anyOf"];
|
|
841
|
-
if (match$4 === undefined) {
|
|
842
|
-
return applyNullable(dict, parsePrimitiveType(dict));
|
|
843
|
-
}
|
|
844
|
-
if (Array.isArray(match$4)) {
|
|
845
|
-
return parseAnyOf(match$4);
|
|
846
|
-
}
|
|
847
|
-
return {
|
|
848
|
-
TAG: "Error",
|
|
849
|
-
_0: [Errors.makeError({
|
|
850
|
-
TAG: "InvalidJson",
|
|
851
|
-
_0: "anyOf must be an array"
|
|
852
|
-
}, undefined, undefined, undefined)]
|
|
853
|
-
};
|
|
854
|
-
}
|
|
855
|
-
|
|
856
|
-
let parse = parseSchema;
|
|
857
|
-
|
|
858
|
-
export {
|
|
859
|
-
isNullType,
|
|
860
|
-
hasDefault,
|
|
861
|
-
extractRefName,
|
|
862
|
-
parseEnumValues,
|
|
863
|
-
extractTagFromConst,
|
|
864
|
-
extractTagFromProperty,
|
|
865
|
-
extractDiscriminatorPropertyName,
|
|
866
|
-
parseSchema,
|
|
867
|
-
parsePrimitiveType,
|
|
868
|
-
parseArrayType,
|
|
869
|
-
parseAnyOf,
|
|
870
|
-
parseObjectType,
|
|
871
|
-
parseAllOf,
|
|
872
|
-
parseOneOf,
|
|
873
|
-
applyNullable,
|
|
874
|
-
parseObject,
|
|
875
|
-
parse,
|
|
876
|
-
}
|
|
877
|
-
/* No side effect */
|