typespec-http-zod 0.7.0 → 0.9.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/src/api.js +20 -1
- package/package.json +1 -1
package/dist/src/api.js
CHANGED
|
@@ -1046,7 +1046,26 @@ function renderSchemas(registry, externals, routeDeclarations, runtimeModule) {
|
|
|
1046
1046
|
const annotation = d.annotated === true ? `: z.ZodType<${d.typeName}>` : "";
|
|
1047
1047
|
return `\n${declared}\nexport const ${d.identifier}${annotation} = ${d.source};\n`;
|
|
1048
1048
|
});
|
|
1049
|
-
|
|
1049
|
+
/**
|
|
1050
|
+
* **Written only when something in the file names it**, like the `ResponseArm` import below and for
|
|
1051
|
+
* the same reason: an unused import fails the lint a generated file has to pass like any other.
|
|
1052
|
+
*
|
|
1053
|
+
* `z` is reached through a declaration's source or a route arm's schema, and a service whose every
|
|
1054
|
+
* operation takes nothing and returns `void` has neither: its arms are
|
|
1055
|
+
* `{ status: 204, schema: undefined }`, which names nothing.
|
|
1056
|
+
* `TS6133: 'z' is declared but its value is never read`, from a compile that reported success. Two
|
|
1057
|
+
* bare `GET`s is where a health check starts, so it is where a new consumer starts.
|
|
1058
|
+
*
|
|
1059
|
+
* **Counting declarations is not sufficient and was the first attempt.** A void-only service HAS
|
|
1060
|
+
* route declarations; they simply do not use Zod. The content decides, and it is TOKENISED on the
|
|
1061
|
+
* language's own identifier rule rather than searched for a substring, so `z` cannot be found
|
|
1062
|
+
* inside `zValidator` or missed beside a bracket. `renderExternalImports` below reads the same
|
|
1063
|
+
* rendered content for the same reason.
|
|
1064
|
+
*/
|
|
1065
|
+
const usesZod = new Set([...declarations, ...routeDeclarations].join("").match(/[A-Za-z_$][\w$]*/g) ?? []).has("z");
|
|
1066
|
+
const parts = [GENERATED_BANNER];
|
|
1067
|
+
if (usesZod)
|
|
1068
|
+
parts.push('\nimport { z } from "zod";\n');
|
|
1050
1069
|
/**
|
|
1051
1070
|
* A TYPE import, so nothing of this package's survives into the emitted JavaScript.
|
|
1052
1071
|
*
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "typespec-http-zod",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"description": "TypeSpec emitter and library: turn an HTTP service definition into Zod validators and framework-free contract types that agree, keyword for keyword, with the OpenAPI document @typespec/openapi3 publishes from the same source.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"codegen",
|