@tahminator/sapling 2.0.5-beta.18ab8bae → 2.0.5-beta.252df3a1
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/index.cjs +41 -24
- package/dist/index.mjs +41 -24
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -551,15 +551,20 @@ var OpenAPIGenerator = class {
|
|
|
551
551
|
const openApiPath = prefix + route.path;
|
|
552
552
|
if (!paths[openApiPath]) paths[openApiPath] = {};
|
|
553
553
|
const responses = {};
|
|
554
|
-
if (schemas?.responseBody)
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
554
|
+
if (schemas?.responseBody) {
|
|
555
|
+
const responseSchema = this.toJsonSchema(schemas.responseBody, "output");
|
|
556
|
+
responses["200"] = {
|
|
557
|
+
description: responseSchema.description ?? "Successful response",
|
|
558
|
+
content: { "application/json": { schema: responseSchema } }
|
|
559
|
+
};
|
|
560
|
+
} else responses["200"] = { description: "Successful response" };
|
|
561
|
+
if (routeSchema?.responses) for (const resp of routeSchema.responses) {
|
|
562
|
+
const responseSchema = this.toJsonSchema(resp.schema, "output");
|
|
563
|
+
responses[String(resp.statusCode)] = {
|
|
564
|
+
description: responseSchema.description ?? `Response ${resp.statusCode}`,
|
|
565
|
+
content: { "application/json": { schema: responseSchema } }
|
|
566
|
+
};
|
|
567
|
+
}
|
|
563
568
|
const operation = {
|
|
564
569
|
responses,
|
|
565
570
|
description: routeSchema?.description,
|
|
@@ -567,31 +572,41 @@ var OpenAPIGenerator = class {
|
|
|
567
572
|
};
|
|
568
573
|
const parameters = [];
|
|
569
574
|
if (schemas?.requestParam) {
|
|
570
|
-
const paramSchema = this.toJsonSchema(schemas.requestParam);
|
|
571
|
-
if (paramSchema.type === "object" && paramSchema.properties) for (const [name, schema] of Object.entries(paramSchema.properties))
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
575
|
+
const paramSchema = this.toJsonSchema(schemas.requestParam, "input");
|
|
576
|
+
if (paramSchema.type === "object" && paramSchema.properties) for (const [name, schema] of Object.entries(paramSchema.properties)) {
|
|
577
|
+
const parameterSchema = schema;
|
|
578
|
+
parameters.push({
|
|
579
|
+
name,
|
|
580
|
+
in: "path",
|
|
581
|
+
required: true,
|
|
582
|
+
description: parameterSchema.description,
|
|
583
|
+
schema: parameterSchema
|
|
584
|
+
});
|
|
585
|
+
}
|
|
577
586
|
}
|
|
578
587
|
if (schemas?.requestQuery) {
|
|
579
|
-
const querySchema = this.toJsonSchema(schemas.requestQuery);
|
|
588
|
+
const querySchema = this.toJsonSchema(schemas.requestQuery, "input");
|
|
580
589
|
if (querySchema.type === "object" && querySchema.properties) for (const [name, schema] of Object.entries(querySchema.properties)) {
|
|
581
590
|
const isRequired = Array.isArray(querySchema.required) && querySchema.required.includes(name);
|
|
591
|
+
const parameterSchema = schema;
|
|
582
592
|
parameters.push({
|
|
583
593
|
name,
|
|
584
594
|
in: "query",
|
|
585
595
|
required: isRequired,
|
|
586
|
-
|
|
596
|
+
description: parameterSchema.description,
|
|
597
|
+
schema: parameterSchema
|
|
587
598
|
});
|
|
588
599
|
}
|
|
589
600
|
}
|
|
590
601
|
if (parameters.length > 0) operation.parameters = parameters;
|
|
591
|
-
if (schemas?.requestBody)
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
602
|
+
if (schemas?.requestBody) {
|
|
603
|
+
const requestSchema = this.toJsonSchema(schemas.requestBody, "input");
|
|
604
|
+
operation.requestBody = {
|
|
605
|
+
required: true,
|
|
606
|
+
description: requestSchema.description,
|
|
607
|
+
content: { "application/json": { schema: requestSchema } }
|
|
608
|
+
};
|
|
609
|
+
}
|
|
595
610
|
const method = route.method.toLowerCase();
|
|
596
611
|
paths[openApiPath][method] = operation;
|
|
597
612
|
}
|
|
@@ -607,9 +622,11 @@ var OpenAPIGenerator = class {
|
|
|
607
622
|
paths
|
|
608
623
|
};
|
|
609
624
|
}
|
|
610
|
-
toJsonSchema(schema) {
|
|
625
|
+
toJsonSchema(schema, direction = "output") {
|
|
611
626
|
try {
|
|
612
|
-
|
|
627
|
+
const jsonSchema = schema["~standard"].jsonSchema;
|
|
628
|
+
if (direction === "input" && jsonSchema.input) return jsonSchema.input({ target: "openapi-3.0" });
|
|
629
|
+
return jsonSchema.output({ target: "openapi-3.0" });
|
|
613
630
|
} catch (e) {
|
|
614
631
|
if (e instanceof Error && e.message.includes("Transforms cannot be represented in JSON Schema")) throw new Error(`${e.message}.\nIt appears that you are using z.transform() - it is highly recommended that you use z.codec instead - https://zod.dev/codecs`);
|
|
615
632
|
throw e;
|
package/dist/index.mjs
CHANGED
|
@@ -526,15 +526,20 @@ var OpenAPIGenerator = class {
|
|
|
526
526
|
const openApiPath = prefix + route.path;
|
|
527
527
|
if (!paths[openApiPath]) paths[openApiPath] = {};
|
|
528
528
|
const responses = {};
|
|
529
|
-
if (schemas?.responseBody)
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
529
|
+
if (schemas?.responseBody) {
|
|
530
|
+
const responseSchema = this.toJsonSchema(schemas.responseBody, "output");
|
|
531
|
+
responses["200"] = {
|
|
532
|
+
description: responseSchema.description ?? "Successful response",
|
|
533
|
+
content: { "application/json": { schema: responseSchema } }
|
|
534
|
+
};
|
|
535
|
+
} else responses["200"] = { description: "Successful response" };
|
|
536
|
+
if (routeSchema?.responses) for (const resp of routeSchema.responses) {
|
|
537
|
+
const responseSchema = this.toJsonSchema(resp.schema, "output");
|
|
538
|
+
responses[String(resp.statusCode)] = {
|
|
539
|
+
description: responseSchema.description ?? `Response ${resp.statusCode}`,
|
|
540
|
+
content: { "application/json": { schema: responseSchema } }
|
|
541
|
+
};
|
|
542
|
+
}
|
|
538
543
|
const operation = {
|
|
539
544
|
responses,
|
|
540
545
|
description: routeSchema?.description,
|
|
@@ -542,31 +547,41 @@ var OpenAPIGenerator = class {
|
|
|
542
547
|
};
|
|
543
548
|
const parameters = [];
|
|
544
549
|
if (schemas?.requestParam) {
|
|
545
|
-
const paramSchema = this.toJsonSchema(schemas.requestParam);
|
|
546
|
-
if (paramSchema.type === "object" && paramSchema.properties) for (const [name, schema] of Object.entries(paramSchema.properties))
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
550
|
+
const paramSchema = this.toJsonSchema(schemas.requestParam, "input");
|
|
551
|
+
if (paramSchema.type === "object" && paramSchema.properties) for (const [name, schema] of Object.entries(paramSchema.properties)) {
|
|
552
|
+
const parameterSchema = schema;
|
|
553
|
+
parameters.push({
|
|
554
|
+
name,
|
|
555
|
+
in: "path",
|
|
556
|
+
required: true,
|
|
557
|
+
description: parameterSchema.description,
|
|
558
|
+
schema: parameterSchema
|
|
559
|
+
});
|
|
560
|
+
}
|
|
552
561
|
}
|
|
553
562
|
if (schemas?.requestQuery) {
|
|
554
|
-
const querySchema = this.toJsonSchema(schemas.requestQuery);
|
|
563
|
+
const querySchema = this.toJsonSchema(schemas.requestQuery, "input");
|
|
555
564
|
if (querySchema.type === "object" && querySchema.properties) for (const [name, schema] of Object.entries(querySchema.properties)) {
|
|
556
565
|
const isRequired = Array.isArray(querySchema.required) && querySchema.required.includes(name);
|
|
566
|
+
const parameterSchema = schema;
|
|
557
567
|
parameters.push({
|
|
558
568
|
name,
|
|
559
569
|
in: "query",
|
|
560
570
|
required: isRequired,
|
|
561
|
-
|
|
571
|
+
description: parameterSchema.description,
|
|
572
|
+
schema: parameterSchema
|
|
562
573
|
});
|
|
563
574
|
}
|
|
564
575
|
}
|
|
565
576
|
if (parameters.length > 0) operation.parameters = parameters;
|
|
566
|
-
if (schemas?.requestBody)
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
577
|
+
if (schemas?.requestBody) {
|
|
578
|
+
const requestSchema = this.toJsonSchema(schemas.requestBody, "input");
|
|
579
|
+
operation.requestBody = {
|
|
580
|
+
required: true,
|
|
581
|
+
description: requestSchema.description,
|
|
582
|
+
content: { "application/json": { schema: requestSchema } }
|
|
583
|
+
};
|
|
584
|
+
}
|
|
570
585
|
const method = route.method.toLowerCase();
|
|
571
586
|
paths[openApiPath][method] = operation;
|
|
572
587
|
}
|
|
@@ -582,9 +597,11 @@ var OpenAPIGenerator = class {
|
|
|
582
597
|
paths
|
|
583
598
|
};
|
|
584
599
|
}
|
|
585
|
-
toJsonSchema(schema) {
|
|
600
|
+
toJsonSchema(schema, direction = "output") {
|
|
586
601
|
try {
|
|
587
|
-
|
|
602
|
+
const jsonSchema = schema["~standard"].jsonSchema;
|
|
603
|
+
if (direction === "input" && jsonSchema.input) return jsonSchema.input({ target: "openapi-3.0" });
|
|
604
|
+
return jsonSchema.output({ target: "openapi-3.0" });
|
|
588
605
|
} catch (e) {
|
|
589
606
|
if (e instanceof Error && e.message.includes("Transforms cannot be represented in JSON Schema")) throw new Error(`${e.message}.\nIt appears that you are using z.transform() - it is highly recommended that you use z.codec instead - https://zod.dev/codecs`);
|
|
590
607
|
throw e;
|