osury 0.25.0 → 0.27.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/IRGen.res.mjs +22 -9
- package/src/OpenAPIParser.res.mjs +168 -16
package/package.json
CHANGED
package/src/IRGen.res.mjs
CHANGED
|
@@ -48,10 +48,15 @@ function convertType(schema) {
|
|
|
48
48
|
_0: convertType(schema._0)
|
|
49
49
|
};
|
|
50
50
|
case "Object" :
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
}
|
|
51
|
+
let fields = schema._0;
|
|
52
|
+
if (fields.length === 0) {
|
|
53
|
+
return "JSON";
|
|
54
|
+
} else {
|
|
55
|
+
return {
|
|
56
|
+
TAG: "InlineRecord",
|
|
57
|
+
_0: fields.map(convertField)
|
|
58
|
+
};
|
|
59
|
+
}
|
|
55
60
|
case "Array" :
|
|
56
61
|
return {
|
|
57
62
|
TAG: "Array",
|
|
@@ -258,13 +263,21 @@ function convertToIrTypeDef(namedSchema, schemasDict, tagsDict, skipSchemaSet) {
|
|
|
258
263
|
}
|
|
259
264
|
let fields = namedSchema.schema;
|
|
260
265
|
let kind;
|
|
261
|
-
|
|
266
|
+
if (typeof fields !== "object" || fields._tag !== "Object") {
|
|
267
|
+
kind = {
|
|
262
268
|
TAG: "AliasDef",
|
|
263
269
|
_0: convertType(namedSchema.schema)
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
270
|
+
};
|
|
271
|
+
} else {
|
|
272
|
+
let fields$1 = fields._0;
|
|
273
|
+
kind = fields$1.length > 0 ? ({
|
|
274
|
+
TAG: "RecordDef",
|
|
275
|
+
_0: fields$1.map(convertField)
|
|
276
|
+
}) : ({
|
|
277
|
+
TAG: "AliasDef",
|
|
278
|
+
_0: convertType(namedSchema.schema)
|
|
279
|
+
});
|
|
280
|
+
}
|
|
268
281
|
let annotations = shouldSkipSchema ? ["GenType"] : [
|
|
269
282
|
"GenType",
|
|
270
283
|
"Schema"
|
|
@@ -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 */
|