Skip to content

Answers, envelopes and errors

Nothing the generated code runs touches an answer, so the types say what the client returns:

  • Envelope. If the document’s answer is { result, code, message, data } and the client is @mrzr/api-client, which takes the data of such an answer itself, the types and calls speak only of data: allOf: [EnvelopeBase, { data: T }] becomes ApiEnvelope<T> in models.ts. With axios or Angular the answer is delivered whole, so its type is the whole schema (an envelope is an ordinary model there); with fetch you read the Response yourself. A result: false is the client’s to judge — a 200 with result: false is returned as it is. For a custom transport that unwraps on its own, runtime.envelope describes the shape (false for none).
  • Paged lists. A { count, list } payload becomes ApiListData<T> only when the document marks both fields required; otherwise it keeps its own type with optional fields, because ApiListData promises both are there. An API that always sends both can say so with runtime: { list: { assumeRequired: true } }; runtime.list: false turns it off.
  • Errors. A failed status is the client’s own: an AxiosError, an HttpErrorResponse, an ApiError. fetch resolves on any status, so a failed one is a Response with ok: false.
  • Infinite lists are written for a paged read whose answer is { count, list }. When the answer is wrapped (an envelope with a client that does not unwrap it) the hook cannot be typed, so none is written and the run says so.