osury 0.26.0 → 0.28.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/package.json +1 -1
- package/src/CodegenTransforms.res.mjs +33 -1
- package/src/IRGen.res.mjs +30 -27
- package/src/OpenAPIParser.res.mjs +168 -16
package/package.json
CHANGED
|
@@ -348,7 +348,39 @@ function topologicalSort(schemas) {
|
|
|
348
348
|
function buildSkipSchemaSet(schemas) {
|
|
349
349
|
let skipSet = {};
|
|
350
350
|
schemas.forEach(s => {
|
|
351
|
-
|
|
351
|
+
let types = s.schema;
|
|
352
|
+
let hasInlineProblem;
|
|
353
|
+
let exit = 0;
|
|
354
|
+
if (typeof types !== "object") {
|
|
355
|
+
exit = 1;
|
|
356
|
+
} else {
|
|
357
|
+
switch (types._tag) {
|
|
358
|
+
case "PolyVariant" :
|
|
359
|
+
hasInlineProblem = types._0.some(c => {
|
|
360
|
+
if (CodegenHelpers.hasUnion(c.payload)) {
|
|
361
|
+
return true;
|
|
362
|
+
} else {
|
|
363
|
+
return CodegenHelpers.hasUnknown(c.payload);
|
|
364
|
+
}
|
|
365
|
+
});
|
|
366
|
+
break;
|
|
367
|
+
case "Union" :
|
|
368
|
+
hasInlineProblem = types._0.some(t => {
|
|
369
|
+
if (CodegenHelpers.hasUnion(t)) {
|
|
370
|
+
return true;
|
|
371
|
+
} else {
|
|
372
|
+
return CodegenHelpers.hasUnknown(t);
|
|
373
|
+
}
|
|
374
|
+
});
|
|
375
|
+
break;
|
|
376
|
+
default:
|
|
377
|
+
exit = 1;
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
if (exit === 1) {
|
|
381
|
+
hasInlineProblem = CodegenHelpers.hasUnion(s.schema) || CodegenHelpers.hasUnknown(s.schema);
|
|
382
|
+
}
|
|
383
|
+
if (hasInlineProblem) {
|
|
352
384
|
skipSet[s.name] = true;
|
|
353
385
|
return;
|
|
354
386
|
}
|
package/src/IRGen.res.mjs
CHANGED
|
@@ -166,16 +166,17 @@ function convertToIrTypeDef(namedSchema, schemasDict, tagsDict, skipSchemaSet) {
|
|
|
166
166
|
payload: payload
|
|
167
167
|
};
|
|
168
168
|
});
|
|
169
|
+
let baseAnnotations = [
|
|
170
|
+
"GenType",
|
|
171
|
+
{
|
|
172
|
+
TAG: "Tag",
|
|
173
|
+
_0: tagName
|
|
174
|
+
}
|
|
175
|
+
];
|
|
176
|
+
let annotations = shouldSkipSchema ? baseAnnotations : baseAnnotations.concat(["Schema"]);
|
|
169
177
|
return {
|
|
170
178
|
name: typeName,
|
|
171
|
-
annotations:
|
|
172
|
-
"GenType",
|
|
173
|
-
{
|
|
174
|
-
TAG: "Tag",
|
|
175
|
-
_0: tagName
|
|
176
|
-
},
|
|
177
|
-
"Schema"
|
|
178
|
-
],
|
|
179
|
+
annotations: annotations,
|
|
179
180
|
kind: {
|
|
180
181
|
TAG: "VariantDef",
|
|
181
182
|
_0: irCases
|
|
@@ -192,17 +193,18 @@ function convertToIrTypeDef(namedSchema, schemasDict, tagsDict, skipSchemaSet) {
|
|
|
192
193
|
payload: payload
|
|
193
194
|
};
|
|
194
195
|
});
|
|
196
|
+
let baseAnnotations$1 = [
|
|
197
|
+
"GenType",
|
|
198
|
+
{
|
|
199
|
+
TAG: "Tag",
|
|
200
|
+
_0: tagName
|
|
201
|
+
},
|
|
202
|
+
"Unboxed"
|
|
203
|
+
];
|
|
204
|
+
let annotations$1 = shouldSkipSchema ? baseAnnotations$1 : baseAnnotations$1.concat(["Schema"]);
|
|
195
205
|
return {
|
|
196
206
|
name: typeName,
|
|
197
|
-
annotations:
|
|
198
|
-
"GenType",
|
|
199
|
-
{
|
|
200
|
-
TAG: "Tag",
|
|
201
|
-
_0: tagName
|
|
202
|
-
},
|
|
203
|
-
"Unboxed",
|
|
204
|
-
"Schema"
|
|
205
|
-
],
|
|
207
|
+
annotations: annotations$1,
|
|
206
208
|
kind: {
|
|
207
209
|
TAG: "VariantDef",
|
|
208
210
|
_0: irCases$1
|
|
@@ -244,16 +246,17 @@ function convertToIrTypeDef(namedSchema, schemasDict, tagsDict, skipSchemaSet) {
|
|
|
244
246
|
payload: payload$1
|
|
245
247
|
};
|
|
246
248
|
});
|
|
249
|
+
let baseAnnotations$2 = [
|
|
250
|
+
"GenType",
|
|
251
|
+
{
|
|
252
|
+
TAG: "Tag",
|
|
253
|
+
_0: tagName
|
|
254
|
+
}
|
|
255
|
+
];
|
|
256
|
+
let annotations$2 = shouldSkipSchema ? baseAnnotations$2 : baseAnnotations$2.concat(["Schema"]);
|
|
247
257
|
return {
|
|
248
258
|
name: typeName,
|
|
249
|
-
annotations:
|
|
250
|
-
"GenType",
|
|
251
|
-
{
|
|
252
|
-
TAG: "Tag",
|
|
253
|
-
_0: tagName
|
|
254
|
-
},
|
|
255
|
-
"Schema"
|
|
256
|
-
],
|
|
259
|
+
annotations: annotations$2,
|
|
257
260
|
kind: {
|
|
258
261
|
TAG: "VariantDef",
|
|
259
262
|
_0: irCases$2
|
|
@@ -278,13 +281,13 @@ function convertToIrTypeDef(namedSchema, schemasDict, tagsDict, skipSchemaSet) {
|
|
|
278
281
|
_0: convertType(namedSchema.schema)
|
|
279
282
|
});
|
|
280
283
|
}
|
|
281
|
-
let annotations = shouldSkipSchema ? ["GenType"] : [
|
|
284
|
+
let annotations$3 = shouldSkipSchema ? ["GenType"] : [
|
|
282
285
|
"GenType",
|
|
283
286
|
"Schema"
|
|
284
287
|
];
|
|
285
288
|
return {
|
|
286
289
|
name: typeName,
|
|
287
|
-
annotations: annotations,
|
|
290
|
+
annotations: annotations$3,
|
|
288
291
|
kind: kind
|
|
289
292
|
};
|
|
290
293
|
}
|
|
@@ -375,6 +375,147 @@ function parseComponentSchemas(componentsJson) {
|
|
|
375
375
|
};
|
|
376
376
|
}
|
|
377
377
|
|
|
378
|
+
function buildParamsObjectJson(params) {
|
|
379
|
+
let properties = {};
|
|
380
|
+
let required = [];
|
|
381
|
+
params.forEach(param => {
|
|
382
|
+
if (typeof param !== "object" || param === null || Array.isArray(param)) {
|
|
383
|
+
return;
|
|
384
|
+
}
|
|
385
|
+
let match = param["in"];
|
|
386
|
+
let location = typeof match === "string" ? match : undefined;
|
|
387
|
+
let isQueryOrPath;
|
|
388
|
+
if (location !== undefined) {
|
|
389
|
+
switch (location) {
|
|
390
|
+
case "path" :
|
|
391
|
+
case "query" :
|
|
392
|
+
isQueryOrPath = true;
|
|
393
|
+
break;
|
|
394
|
+
default:
|
|
395
|
+
isQueryOrPath = false;
|
|
396
|
+
}
|
|
397
|
+
} else {
|
|
398
|
+
isQueryOrPath = false;
|
|
399
|
+
}
|
|
400
|
+
if (!isQueryOrPath) {
|
|
401
|
+
return;
|
|
402
|
+
}
|
|
403
|
+
let match$1 = param["name"];
|
|
404
|
+
let match$2 = param["schema"];
|
|
405
|
+
if (match$1 === undefined) {
|
|
406
|
+
return;
|
|
407
|
+
}
|
|
408
|
+
if (typeof match$1 !== "string") {
|
|
409
|
+
return;
|
|
410
|
+
}
|
|
411
|
+
if (match$2 === undefined) {
|
|
412
|
+
return;
|
|
413
|
+
}
|
|
414
|
+
properties[match$1] = match$2;
|
|
415
|
+
let match$3 = param["required"];
|
|
416
|
+
let isRequired = match$3 === true;
|
|
417
|
+
let pathRequired = location === "path";
|
|
418
|
+
if (isRequired || pathRequired) {
|
|
419
|
+
required.push(match$1);
|
|
420
|
+
return;
|
|
421
|
+
}
|
|
422
|
+
});
|
|
423
|
+
if (Object.entries(properties).length === 0) {
|
|
424
|
+
return;
|
|
425
|
+
}
|
|
426
|
+
let obj = {};
|
|
427
|
+
obj["type"] = "object";
|
|
428
|
+
obj["properties"] = properties;
|
|
429
|
+
obj["required"] = required;
|
|
430
|
+
return obj;
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
function parsePathParameters(pathsJson) {
|
|
434
|
+
if (typeof pathsJson !== "object" || pathsJson === null || Array.isArray(pathsJson)) {
|
|
435
|
+
return {
|
|
436
|
+
TAG: "Ok",
|
|
437
|
+
_0: []
|
|
438
|
+
};
|
|
439
|
+
}
|
|
440
|
+
let results = Object.entries(pathsJson).flatMap(param => {
|
|
441
|
+
let methodsJson = param[1];
|
|
442
|
+
let path = param[0];
|
|
443
|
+
if (typeof methodsJson === "object" && methodsJson !== null && !Array.isArray(methodsJson)) {
|
|
444
|
+
return Core__Array.filterMap(Object.entries(methodsJson), param => {
|
|
445
|
+
let opJson = param[1];
|
|
446
|
+
let method = param[0];
|
|
447
|
+
let httpMethods = [
|
|
448
|
+
"get",
|
|
449
|
+
"post",
|
|
450
|
+
"put",
|
|
451
|
+
"patch",
|
|
452
|
+
"delete"
|
|
453
|
+
];
|
|
454
|
+
if (!httpMethods.includes(method)) {
|
|
455
|
+
return;
|
|
456
|
+
}
|
|
457
|
+
if (typeof opJson !== "object" || opJson === null || Array.isArray(opJson)) {
|
|
458
|
+
return;
|
|
459
|
+
}
|
|
460
|
+
let match = opJson["parameters"];
|
|
461
|
+
if (match === undefined) {
|
|
462
|
+
return;
|
|
463
|
+
}
|
|
464
|
+
if (!Array.isArray(match)) {
|
|
465
|
+
return;
|
|
466
|
+
}
|
|
467
|
+
let objJson = buildParamsObjectJson(match);
|
|
468
|
+
if (objJson === undefined) {
|
|
469
|
+
return;
|
|
470
|
+
}
|
|
471
|
+
let name = ucFirst(method) + pathToName(path) + "Params";
|
|
472
|
+
let schemaType = Schema.parse(objJson);
|
|
473
|
+
if (schemaType.TAG === "Ok") {
|
|
474
|
+
return {
|
|
475
|
+
TAG: "Ok",
|
|
476
|
+
_0: {
|
|
477
|
+
name: name,
|
|
478
|
+
schema: schemaType._0,
|
|
479
|
+
discriminatorTag: undefined,
|
|
480
|
+
discriminatorPropertyName: undefined,
|
|
481
|
+
fieldDiscriminators: undefined
|
|
482
|
+
}
|
|
483
|
+
};
|
|
484
|
+
} else {
|
|
485
|
+
return {
|
|
486
|
+
TAG: "Error",
|
|
487
|
+
_0: schemaType._0
|
|
488
|
+
};
|
|
489
|
+
}
|
|
490
|
+
});
|
|
491
|
+
} else {
|
|
492
|
+
return [];
|
|
493
|
+
}
|
|
494
|
+
});
|
|
495
|
+
let errors = Core__Array.filterMap(results, r => {
|
|
496
|
+
if (r.TAG === "Ok") {
|
|
497
|
+
return;
|
|
498
|
+
} else {
|
|
499
|
+
return r._0;
|
|
500
|
+
}
|
|
501
|
+
}).flat();
|
|
502
|
+
if (errors.length > 0) {
|
|
503
|
+
return {
|
|
504
|
+
TAG: "Error",
|
|
505
|
+
_0: errors
|
|
506
|
+
};
|
|
507
|
+
}
|
|
508
|
+
let schemas = Core__Array.filterMap(results, r => {
|
|
509
|
+
if (r.TAG === "Ok") {
|
|
510
|
+
return r._0;
|
|
511
|
+
}
|
|
512
|
+
});
|
|
513
|
+
return {
|
|
514
|
+
TAG: "Ok",
|
|
515
|
+
_0: schemas
|
|
516
|
+
};
|
|
517
|
+
}
|
|
518
|
+
|
|
378
519
|
function parseDocument(json) {
|
|
379
520
|
if (typeof json === "object" && json !== null && !Array.isArray(json)) {
|
|
380
521
|
let componentsJson = json["components"];
|
|
@@ -387,29 +528,38 @@ function parseDocument(json) {
|
|
|
387
528
|
TAG: "Ok",
|
|
388
529
|
_0: []
|
|
389
530
|
});
|
|
390
|
-
|
|
391
|
-
|
|
531
|
+
let pathsJson$1 = json["paths"];
|
|
532
|
+
let paramSchemas = pathsJson$1 !== undefined ? parsePathParameters(pathsJson$1) : ({
|
|
533
|
+
TAG: "Ok",
|
|
534
|
+
_0: []
|
|
535
|
+
});
|
|
536
|
+
let exit = 0;
|
|
537
|
+
if (componentSchemas.TAG === "Ok" && pathSchemas.TAG === "Ok") {
|
|
538
|
+
if (paramSchemas.TAG === "Ok") {
|
|
392
539
|
return {
|
|
393
540
|
TAG: "Ok",
|
|
394
|
-
_0: componentSchemas._0.concat(pathSchemas._0)
|
|
395
|
-
};
|
|
396
|
-
} else {
|
|
397
|
-
return {
|
|
398
|
-
TAG: "Error",
|
|
399
|
-
_0: pathSchemas._0
|
|
541
|
+
_0: componentSchemas._0.concat(pathSchemas._0).concat(paramSchemas._0)
|
|
400
542
|
};
|
|
401
543
|
}
|
|
402
|
-
|
|
403
|
-
let e = componentSchemas._0;
|
|
404
|
-
if (pathSchemas.TAG === "Ok") {
|
|
405
|
-
return {
|
|
406
|
-
TAG: "Error",
|
|
407
|
-
_0: e
|
|
408
|
-
};
|
|
544
|
+
exit = 2;
|
|
409
545
|
} else {
|
|
546
|
+
exit = 2;
|
|
547
|
+
}
|
|
548
|
+
if (exit === 2) {
|
|
549
|
+
let errs = Core__Array.filterMap([
|
|
550
|
+
componentSchemas,
|
|
551
|
+
pathSchemas,
|
|
552
|
+
paramSchemas
|
|
553
|
+
], r => {
|
|
554
|
+
if (r.TAG === "Ok") {
|
|
555
|
+
return;
|
|
556
|
+
} else {
|
|
557
|
+
return r._0;
|
|
558
|
+
}
|
|
559
|
+
}).flat();
|
|
410
560
|
return {
|
|
411
561
|
TAG: "Error",
|
|
412
|
-
_0:
|
|
562
|
+
_0: errs
|
|
413
563
|
};
|
|
414
564
|
}
|
|
415
565
|
}
|
|
@@ -431,6 +581,8 @@ export {
|
|
|
431
581
|
extractDiscriminatorPropertyName,
|
|
432
582
|
extractDiscriminatorTag,
|
|
433
583
|
parseComponentSchemas,
|
|
584
|
+
buildParamsObjectJson,
|
|
585
|
+
parsePathParameters,
|
|
434
586
|
parseDocument,
|
|
435
587
|
}
|
|
436
588
|
/* No side effect */
|