typespec-http-zod 0.14.0 → 0.15.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.d.ts CHANGED
@@ -206,6 +206,22 @@ export interface EmittedRoute {
206
206
  * what arrived, parsing and re-serialising would verify a different string than the sender signed.
207
207
  */
208
208
  readonly rawBodyProperty: string | undefined;
209
+ /**
210
+ * The input property a PARSED body arrives under, where it must not be spread into the parameters.
211
+ *
212
+ * **A body with an indexer cannot be flattened.** `@body body: Record<string>` merged with the
213
+ * query and header parameters gives an intersection whose index signature every sibling must
214
+ * satisfy, so an optional `@query q?: string` fails with
215
+ * `TS2345: 'q' is incompatible with index signature` and the generated server does not compile.
216
+ *
217
+ * **And flattening it was wrong before it failed to compile.** The document states the parameters
218
+ * and the body as separate things; merged, a body key named `q` silently overwrites the query
219
+ * parameter of that name. Naming the property keeps them apart, which is what the document says.
220
+ *
221
+ * `undefined` for an ordinary model body, which is spread as before. Same shape as
222
+ * {@link rawBodyProperty}, whose case is the same statement about a different body.
223
+ */
224
+ readonly bodyProperty: string | undefined;
209
225
  /** Declared failures, each with the schema for its OWN body, in OpenAPI's precedence order. */
210
226
  readonly errorArms: readonly {
211
227
  readonly status: StatusKey;
package/dist/src/api.js CHANGED
@@ -958,6 +958,14 @@ export function collectRoutes(program, registry, service) {
958
958
  const rawBodyProperty = requestType?.kind === "Scalar" && requestType.name === "bytes"
959
959
  ? (bodyParameter?.property?.name ?? "body")
960
960
  : undefined;
961
+ /**
962
+ * A body with an indexer is named rather than spread - see `bodyProperty`. Read from the
963
+ * resolved model's own indexer rather than from the emitted schema text, which would be a
964
+ * decision made by pattern-matching generated output.
965
+ */
966
+ const bodyProperty = requestType?.kind === "Model" && requestType.indexer !== undefined
967
+ ? (bodyParameter?.property?.name ?? "body")
968
+ : undefined;
961
969
  routes.push({
962
970
  operationId: operationIdOf(program, operation.operation),
963
971
  verb: operation.verb.toUpperCase(),
@@ -1035,6 +1043,7 @@ export function collectRoutes(program, registry, service) {
1035
1043
  ? "z.unknown()"
1036
1044
  : registry.expressionFor(responseType)),
1037
1045
  rawBodyProperty,
1046
+ bodyProperty,
1038
1047
  // Responses are read at Visibility.Read, exactly as the success body above is. Resolving
1039
1048
  // them under the ambient request visibility declared six components under the wrong
1040
1049
  // suffix - measured: type/model/visibility gained six divergences.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "typespec-http-zod",
3
- "version": "0.14.0",
3
+ "version": "0.15.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",