typespec-http-zod 0.8.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.
Files changed (2) hide show
  1. package/dist/src/api.js +9 -5
  2. package/package.json +1 -1
package/dist/src/api.js CHANGED
@@ -1050,15 +1050,19 @@ function renderSchemas(registry, externals, routeDeclarations, runtimeModule) {
1050
1050
  * **Written only when something in the file names it**, like the `ResponseArm` import below and for
1051
1051
  * the same reason: an unused import fails the lint a generated file has to pass like any other.
1052
1052
  *
1053
- * `z` is reached through a declaration's source or a route's arms, so a service whose every
1054
- * operation takes nothing and returns `void` declares neither and named it never:
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.
1055
1056
  * `TS6133: 'z' is declared but its value is never read`, from a compile that reported success. Two
1056
1057
  * bare `GET`s is where a health check starts, so it is where a new consumer starts.
1057
1058
  *
1058
- * Decided from the declarations rather than by searching the rendered text, which is the mistake
1059
- * this file has made four times.
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.
1060
1064
  */
1061
- const usesZod = declarations.length > 0 || routeDeclarations.length > 0;
1065
+ const usesZod = new Set([...declarations, ...routeDeclarations].join("").match(/[A-Za-z_$][\w$]*/g) ?? []).has("z");
1062
1066
  const parts = [GENERATED_BANNER];
1063
1067
  if (usesZod)
1064
1068
  parts.push('\nimport { z } from "zod";\n');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "typespec-http-zod",
3
- "version": "0.8.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",