@haddowg/json-api-codegen 1.6.0 → 1.7.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/cli.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { r as CodegenConfig } from "./index-CU-kUx70.mjs";
1
+ import { r as CodegenConfig } from "./index-CeSU_OuC.mjs";
2
2
 
3
3
  //#region src/cli.d.ts
4
4
  declare const USAGE = "Usage: json-api-codegen --input <url|file> --output <file> [--server <name>] [--schemas <url|file>] [--check]";
package/dist/cli.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { n as generate, r as schemasOutputPath, t as check } from "./src-C2INS1Wd.mjs";
2
+ import { n as generate, r as schemasOutputPath, t as check } from "./src-DhZyiWge.mjs";
3
3
  import { realpathSync } from "node:fs";
4
4
  import { fileURLToPath } from "node:url";
5
5
  //#region src/cli.ts
@@ -49,6 +49,8 @@ interface ParameterObject {
49
49
  }
50
50
  interface OperationObject {
51
51
  operationId?: string;
52
+ summary?: string;
53
+ description?: string;
52
54
  parameters?: readonly ParameterObject[];
53
55
  requestBody?: RequestBodyObject;
54
56
  responses?: Record<string, ResponseObject>;
@@ -151,6 +153,21 @@ declare class DescriptorBuilder {
151
153
  * `output` is `document` (a 2xx returns a JSON:API document) or `none` (only `204`).
152
154
  */
153
155
  private actions;
156
+ /**
157
+ * The non-JSON:API media types an action answers with under its 2xx responses, each once, in
158
+ * the document's order, with how the client reads its body.
159
+ */
160
+ private rawOutput;
161
+ /**
162
+ * How the client reads or sends a non-JSON:API body: `binary` for `format: binary` (or no schema
163
+ * on a type that isn't text or JSON), `text` for any other string schema (or no schema on a
164
+ * `text/*` type), `json` for any other schema (or no schema on a JSON type).
165
+ */
166
+ private rawMediaKind;
167
+ /** How the client sends one of an action's several request media types. */
168
+ private inputMediaKind;
169
+ /** A schema with a component `$ref` followed, else the schema as is. */
170
+ private resolveSchema;
154
171
  /**
155
172
  * The wire type (and cardinality) of a document component's primary `data` — a `$ref` to a
156
173
  * resource, an inline object carrying `properties.type.const` (a create-request body), or an
@@ -260,7 +277,7 @@ declare function buildAtomic(doc: OpenApiDocument): AtomicDescriptor | null;
260
277
  /** Below this the document predates the structures this codegen reads. */
261
278
  declare const MINIMUM_CONTRACT = 1;
262
279
  /** Above this the document carries structures this codegen does not read. */
263
- declare const MAXIMUM_CONTRACT = 9;
280
+ declare const MAXIMUM_CONTRACT = 11;
264
281
  /**
265
282
  * Check the document's `info.x-generator.contract` against the range this codegen reads. A
266
283
  * document older than the range throws; a newer one returns a warning, because its new
@@ -295,6 +312,10 @@ declare class Emitter {
295
312
  * already-named attribute type. Populated as interfaces are emitted.
296
313
  */
297
314
  private readonly emittedInterfaces;
315
+ /** Enum component name -> the alias name it's emitted under. */
316
+ private readonly enumNames;
317
+ /** Type names already spoken for: the module's own, the per-type interfaces and enum aliases. */
318
+ private readonly takenNames;
298
319
  /** Component names mid-expansion in {@link tsType} — a cycle guard for self/mutually-referential `$ref`s. */
299
320
  private readonly expanding;
300
321
  /**
@@ -303,10 +324,21 @@ declare class Emitter {
303
324
  * type-map only references aliases that exist (a `none` input/output contributes neither).
304
325
  */
305
326
  private readonly actionAliasNames;
327
+ /** Raw body components already emitted as a named alias, by component name. */
328
+ private readonly rawBodyAliases;
329
+ /** JSDoc for entries of the `resourceMap` literal, keyed by their path joined with `/`. */
330
+ private readonly literalDocs;
306
331
  /** Provenance of the source document, stamped into the generated header for drift tracking. */
307
332
  private readonly provenance;
308
333
  private readonly doc;
309
334
  constructor(source: OpenApiDocument, descriptor: ApiDescriptor, atomic: AtomicDescriptor | null);
335
+ /** The operation an action is invoked over: its declared method, else `POST`. */
336
+ private actionOperation;
337
+ /**
338
+ * The alias an enum component is emitted under: its own name when that's a usable type name,
339
+ * else one derived from it (with a warning), kept clear of every other name in the module.
340
+ */
341
+ private enumName;
310
342
  /** Map each declared wire type back to the `Base` of its resource schema. */
311
343
  private indexBases;
312
344
  emit(): string;
@@ -330,6 +362,26 @@ declare class Emitter {
330
362
  * no alias. Deterministic order: types, then action names (the descriptor is sorted).
331
363
  */
332
364
  private actionTypeAliases;
365
+ /**
366
+ * The alias a JSON-like raw body is typed by. A `$ref` to a component is emitted once under the
367
+ * component's own name when that name is free; anything else gets `fallback`. The alias source
368
+ * is pushed onto `out` the first time.
369
+ */
370
+ private rawBodyAlias;
371
+ /**
372
+ * The typed fields of a multipart or URL-encoded request body whose object schema lists
373
+ * `properties`, which the client encodes into a `FormData` or `URLSearchParams`. `undefined`
374
+ * when the schema lists none, so the body stays a raw `FormData` or `URLSearchParams`.
375
+ */
376
+ private formFieldsType;
377
+ /**
378
+ * One form field's type: `Blob | File` for a binary part of a multipart body, an array of
379
+ * its item type for an array, else the scalar's own type. A field with no usable type takes
380
+ * any scalar a form can carry.
381
+ */
382
+ private formFieldType;
383
+ /** `export type Name = …` for a raw body schema, with its description as JSDoc. */
384
+ private rawBodyDeclaration;
333
385
  /**
334
386
  * Emit the `ActionTypes` interface wiring the emitted per-action aliases onto the typed
335
387
  * action surface — `type -> actionName -> { input?; output? }`, the client's fourth type
@@ -502,7 +554,7 @@ declare function hashJson(value: unknown): string;
502
554
  declare function deriveProvenance(doc: OpenApiDocument): Provenance;
503
555
  /**
504
556
  * Render the provenance record as the JSDoc header lines stamped into a generated artifact
505
- * (each already prefixed with ` * `). Deterministic: no timestamp, so re-generating from the
557
+ * (each already prefixed with ` * `), with the document's text kept to one comment line. Deterministic: no timestamp, so re-generating from the
506
558
  * same spec yields byte-identical output.
507
559
  */
508
560
  declare function provenanceLines(provenance: Provenance): string[];
@@ -565,4 +617,4 @@ declare function generate(config: CodegenConfig): Promise<string>;
565
617
  declare function check(config: CodegenConfig): Promise<CheckResult>;
566
618
  //#endregion
567
619
  export { InfoObject as A, MAXIMUM_CONTRACT as C, buildAtomic as D, DescriptorBuilder as E, PathItemObject as F, RequestBodyObject as I, ResponseObject as L, OpenApiDocument as M, OperationObject as N, buildDescriptor as O, ParameterObject as P, SchemaObject as R, emit as S, checkContract as T, emitErrorCodes as _, generate as a, VerbCollision as b, deriveProvenance as c, emitSchemas as d, SchemaBundle as f, ErrorCatalogue as g, DocumentedErrorCode as h, check as i, MediaTypeObject as j, HttpMethod as k, hashJson as l, readSchemas as m, CheckResult as n, schemasOutputPath as o, readDocument as p, CodegenConfig as r, Provenance as s, ArtifactDrift as t, provenanceLines as u, readErrorCatalogue as v, MINIMUM_CONTRACT as w, detectVerbCollisions as x, Emitter as y, SchemaOrBool as z };
568
- //# sourceMappingURL=index-CU-kUx70.d.mts.map
620
+ //# sourceMappingURL=index-CeSU_OuC.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index-CeSU_OuC.d.mts","names":[],"sources":["../src/openapi.ts","../src/build-descriptor.ts","../src/contract.ts","../src/emit.ts","../src/error-codes.ts","../src/reader.ts","../src/emit-schemas.ts","../src/provenance.ts","../src/index.ts"],"mappings":";;;;;;AAQA;;;;UAAiB,YAAA;EACf,IAAA;EACA,IAAA;EACA,KAAA;EACA,MAAA;EACA,WAAA;EACA,IAAA;EACA,UAAA,GAAa,MAAA,SAAe,YAAA;EAC5B,KAAA,GAAQ,YAAA;EACR,QAAA;EACA,KAAA,YAAiB,YAAA;EACjB,KAAA,YAAiB,YAAA;EACjB,KAAA,YAAiB,YAAA;EACjB,iBAAA;EACA,qBAAA;EAAA,CACC,GAAA;AAAA;;KAIS,YAAA,GAAe,YAAY;AAAA,UAEtB,eAAA;EACf,MAAA,GAAS,YAAY;AAAA;AAAA,UAGN,iBAAA;EACf,OAAA,GAAU,MAAM,SAAS,eAAA;EACzB,QAAA;AAAA;AAAA,UAGe,cAAA;EACf,OAAA,GAAU,MAAM,SAAS,eAAA;AAAA;AAAA,UAGV,eAAA;EACf,IAAA;EACA,EAAA;EACA,IAAA;EACA,MAAA,GAAS,YAAY;EACrB,KAAA;EACA,OAAA;EAnB8B;EAqB9B,WAAA;AAAA;AAAA,UAGe,eAAA;EACf,WAAA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BodyObject, L as ResponseObject, M as OpenApiDocument, N as OperationObject, O as buildDescriptor, P as ParameterObject, R as SchemaObject, S as emit, T as checkContract, _ as emitErrorCodes, a as generate, b as VerbCollision, c as deriveProvenance, d as emitSchemas, f as SchemaBundle, g as ErrorCatalogue, h as DocumentedErrorCode, i as check, j as MediaTypeObject, k as HttpMethod, l as hashJson, m as readSchemas, n as CheckResult, o as schemasOutputPath, p as readDocument, r as CodegenConfig, s as Provenance, t as ArtifactDrift, u as provenanceLines, v as readErrorCatalogue, w as MINIMUM_CONTRACT, x as detectVerbCollisions, y as Emitter, z as SchemaOrBool } from "./index-CU-kUx70.mjs";
1
+ import { A as InfoObject, C as MAXIMUM_CONTRACT, D as buildAtomic, E as DescriptorBuilder, F as PathItemObject, I as RequestBodyObject, L as ResponseObject, M as OpenApiDocument, N as OperationObject, O as buildDescriptor, P as ParameterObject, R as SchemaObject, S as emit, T as checkContract, _ as emitErrorCodes, a as generate, b as VerbCollision, c as deriveProvenance, d as emitSchemas, f as SchemaBundle, g as ErrorCatalogue, h as DocumentedErrorCode, i as check, j as MediaTypeObject, k as HttpMethod, l as hashJson, m as readSchemas, n as CheckResult, o as schemasOutputPath, p as readDocument, r as CodegenConfig, s as Provenance, t as ArtifactDrift, u as provenanceLines, v as readErrorCatalogue, w as MINIMUM_CONTRACT, x as detectVerbCollisions, y as Emitter, z as SchemaOrBool } from "./index-CeSU_OuC.mjs";
2
2
  export { ArtifactDrift, CheckResult, CodegenConfig, DescriptorBuilder, type DocumentedErrorCode, Emitter, type ErrorCatalogue, type HttpMethod, type InfoObject, MAXIMUM_CONTRACT, MINIMUM_CONTRACT, type MediaTypeObject, type OpenApiDocument, type OperationObject, type ParameterObject, type PathItemObject, type Provenance, type RequestBodyObject, type ResponseObject, type SchemaBundle, type SchemaObject, type SchemaOrBool, type VerbCollision, buildAtomic, buildDescriptor, check, checkContract, deriveProvenance, detectVerbCollisions, emit, emitErrorCodes, emitSchemas, generate, hashJson, provenanceLines, readDocument, readErrorCatalogue, readSchemas, schemasOutputPath };
package/dist/index.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import { _ as checkContract, a as readSchemas, b as buildDescriptor, c as detectVerbCollisions, d as hashJson, f as provenanceLines, g as MINIMUM_CONTRACT, h as MAXIMUM_CONTRACT, i as readDocument, l as emit, m as readErrorCatalogue, n as generate, o as emitSchemas, p as emitErrorCodes, r as schemasOutputPath, s as Emitter, t as check, u as deriveProvenance, v as DescriptorBuilder, y as buildAtomic } from "./src-C2INS1Wd.mjs";
1
+ import { _ as checkContract, a as readSchemas, b as buildDescriptor, c as detectVerbCollisions, d as hashJson, f as provenanceLines, g as MINIMUM_CONTRACT, h as MAXIMUM_CONTRACT, i as readDocument, l as emit, m as readErrorCatalogue, n as generate, o as emitSchemas, p as emitErrorCodes, r as schemasOutputPath, s as Emitter, t as check, u as deriveProvenance, v as DescriptorBuilder, y as buildAtomic } from "./src-DhZyiWge.mjs";
2
2
  export { DescriptorBuilder, Emitter, MAXIMUM_CONTRACT, MINIMUM_CONTRACT, buildAtomic, buildDescriptor, check, checkContract, deriveProvenance, detectVerbCollisions, emit, emitErrorCodes, emitSchemas, generate, hashJson, provenanceLines, readDocument, readErrorCatalogue, readSchemas, schemasOutputPath };