@boon4681/giri 0.0.3-alpha-2 → 0.0.3-alpha-3

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/cli.js CHANGED
@@ -1421,7 +1421,12 @@ function inputToJsonSchema(schema) {
1421
1421
  if (!isGiriInputSchema(schema)) {
1422
1422
  return void 0;
1423
1423
  }
1424
- return sanitize(schema.toJsonSchema());
1424
+ try {
1425
+ return sanitize(schema.toJsonSchema());
1426
+ } catch (error) {
1427
+ console.warn(`giri: skipped a request schema that can't be represented as JSON Schema (${error.message}).`);
1428
+ return void 0;
1429
+ }
1425
1430
  }
1426
1431
  function bodyToJsonSchemas(value) {
1427
1432
  if (!isGiriBodySchema(value)) {
@@ -1437,6 +1442,46 @@ function bodyToJsonSchemas(value) {
1437
1442
  return Object.keys(out).length > 0 ? out : void 0;
1438
1443
  }
1439
1444
 
1445
+ // src/generator/schema/route-openapi.ts
1446
+ var import_typebox2 = require("@sinclair/typebox");
1447
+ var import_value2 = require("@sinclair/typebox/value");
1448
+ var StringSchema = import_typebox2.Type.String();
1449
+ var BooleanSchema = import_typebox2.Type.Boolean();
1450
+ var StringArraySchema = import_typebox2.Type.Array(StringSchema);
1451
+ var routeOpenApiSchema = import_typebox2.Type.Object(
1452
+ {
1453
+ hidden: import_typebox2.Type.Optional(BooleanSchema),
1454
+ tags: import_typebox2.Type.Optional(StringArraySchema),
1455
+ summary: import_typebox2.Type.Optional(StringSchema),
1456
+ description: import_typebox2.Type.Optional(StringSchema),
1457
+ deprecated: import_typebox2.Type.Optional(BooleanSchema),
1458
+ operationId: import_typebox2.Type.Optional(StringSchema)
1459
+ },
1460
+ { additionalProperties: true }
1461
+ );
1462
+ function pick(schema, value) {
1463
+ return import_value2.Value.Check(schema, value) ? value : void 0;
1464
+ }
1465
+ function parseRouteOpenApi(value) {
1466
+ if (!value || typeof value !== "object" || Array.isArray(value)) {
1467
+ return void 0;
1468
+ }
1469
+ const o = value;
1470
+ const parsed = {};
1471
+ if ("hidden" in o) {
1472
+ parsed.hidden = Boolean(o.hidden);
1473
+ }
1474
+ const tags = pick(StringArraySchema, o.tags);
1475
+ if (tags) {
1476
+ parsed.tags = tags;
1477
+ }
1478
+ parsed.summary = pick(StringSchema, o.summary);
1479
+ parsed.description = pick(StringSchema, o.description);
1480
+ parsed.operationId = pick(StringSchema, o.operationId);
1481
+ parsed.deprecated = pick(BooleanSchema, o.deprecated);
1482
+ return parsed;
1483
+ }
1484
+
1440
1485
  // src/generator/route-meta.ts
1441
1486
  function loadModule2(file) {
1442
1487
  const resolved = require.resolve(file);
@@ -1749,27 +1794,27 @@ function resolveOpenApi(route, routeModule, loadShared) {
1749
1794
  hidden = false;
1750
1795
  return;
1751
1796
  }
1752
- if (!value || typeof value !== "object") {
1797
+ const parsed = parseRouteOpenApi(value);
1798
+ if (!parsed) {
1753
1799
  return;
1754
1800
  }
1755
- const o = value;
1756
- if ("hidden" in o) {
1757
- hidden = Boolean(o.hidden);
1801
+ if (parsed.hidden !== void 0) {
1802
+ hidden = parsed.hidden;
1758
1803
  }
1759
- if (Array.isArray(o.tags)) {
1760
- tags.push(...o.tags.filter((tag2) => typeof tag2 === "string"));
1804
+ if (parsed.tags) {
1805
+ tags.push(...parsed.tags);
1761
1806
  }
1762
- if (typeof o.summary === "string") {
1763
- meta.summary = o.summary;
1807
+ if (parsed.summary !== void 0) {
1808
+ meta.summary = parsed.summary;
1764
1809
  }
1765
- if (typeof o.description === "string") {
1766
- meta.description = o.description;
1810
+ if (parsed.description !== void 0) {
1811
+ meta.description = parsed.description;
1767
1812
  }
1768
- if (typeof o.deprecated === "boolean") {
1769
- meta.deprecated = o.deprecated;
1813
+ if (parsed.deprecated !== void 0) {
1814
+ meta.deprecated = parsed.deprecated;
1770
1815
  }
1771
- if (isVerb && typeof o.operationId === "string") {
1772
- meta.operationId = o.operationId;
1816
+ if (isVerb && parsed.operationId !== void 0) {
1817
+ meta.operationId = parsed.operationId;
1773
1818
  }
1774
1819
  };
1775
1820
  for (const file of route.sharedFiles) {