typespec-http-zod 0.7.0 → 0.8.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 +16 -1
  2. package/package.json +1 -1
package/dist/src/api.js CHANGED
@@ -1046,7 +1046,22 @@ 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
- const parts = [GENERATED_BANNER, '\nimport { z } from "zod";\n'];
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's arms, so a service whose every
1054
+ * operation takes nothing and returns `void` declares neither and named it never:
1055
+ * `TS6133: 'z' is declared but its value is never read`, from a compile that reported success. Two
1056
+ * bare `GET`s is where a health check starts, so it is where a new consumer starts.
1057
+ *
1058
+ * Decided from the declarations rather than by searching the rendered text, which is the mistake
1059
+ * this file has made four times.
1060
+ */
1061
+ const usesZod = declarations.length > 0 || routeDeclarations.length > 0;
1062
+ const parts = [GENERATED_BANNER];
1063
+ if (usesZod)
1064
+ parts.push('\nimport { z } from "zod";\n');
1050
1065
  /**
1051
1066
  * A TYPE import, so nothing of this package's survives into the emitted JavaScript.
1052
1067
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "typespec-http-zod",
3
- "version": "0.7.0",
3
+ "version": "0.8.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",