oas-truth 0.4.0 → 0.5.1

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/README.md CHANGED
@@ -48,6 +48,12 @@ varName, fileName, code }` with no import line, and `make<Kind>Code` joins those
48
48
  map (`user` / `User` → `User` / `User2`); `$ref`s resolve through it, so a later collider is
49
49
  `User2Schema`.
50
50
 
51
+ `makeParametersCode` reads every parameter as text: `query`, `path`, `header` and `cookie`
52
+ values are coerced, and the parameter's `style`, `explode` and `allowEmptyValue` decide how the
53
+ text is split (`form` with `explode: false` reads `1,2,3`, `deepObject` gathers `filter[key]`).
54
+ `toExpression(schema, paramIn, { style, explode, allowEmptyValue })` takes the same options, and
55
+ `isParamStyle` narrows a free-form `style` to one it reads. TypeBox ignores the three options.
56
+
51
57
  `wrapSchema(expr, slot)` is slot-aware (`response-content`, `request-content`, `header`,
52
58
  `parameter`, `media-type`). TypeBox imports from `typebox` and reserves `Compile`. Pass
53
59
  `{ ref: true }` to `makeSchemaDeclarations` to register the OpenAPI key — TypeBox writes it
package/dist/index.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- //#region src/openapi/index.d.ts
2
1
  export declare function parseOpenAPI(input: string): Promise<{
3
2
  readonly ok: true;
4
3
  readonly value: OpenAPI;
@@ -498,18 +497,35 @@ export type Media = {
498
497
  export type Callbacks = {
499
498
  readonly [k: string]: PathItem;
500
499
  };
501
- //#endregion
502
- //#region src/adapter/index.d.ts
503
- export type ParamIn = 'query' | 'path';
500
+ /**
501
+ * Where a value arrives as text: an OpenAPI parameter location, or `formData` for a field of
502
+ * a form body. schema-truth coerces the value from text for every one of them.
503
+ */
504
+ export type ParamIn = 'query' | 'path' | 'header' | 'cookie' | 'formData';
505
+ /**
506
+ * A Parameter Object's `style`: how its text is split into an array or an object.
507
+ *
508
+ * @see https://spec.openapis.org/oas/v3.2.0.html#style-values
509
+ */
510
+ export type ParamStyle = 'matrix' | 'label' | 'simple' | 'form' | 'spaceDelimited' | 'pipeDelimited' | 'deepObject';
511
+ /** Narrow a Parameter Object's free-form `style` to one schema-truth reads. */
512
+ export declare function isParamStyle(style: string): style is ParamStyle;
504
513
  export type SchemaLib = 'zod' | 'valibot' | 'arktype' | 'effect' | 'typebox';
505
514
  /**
506
515
  * Which `schema:` slot a host `wrapSchema` hook is looking at. The second
507
516
  * argument is optional so an existing one-argument hook keeps compiling.
508
517
  */
509
518
  export type SchemaSlot = 'response-content' | 'request-content' | 'header' | 'parameter' | 'media-type';
510
- /** Optional third argument to `toExpression` — TypeBox puts `ref` in builder options. */
519
+ /**
520
+ * Optional third argument to `toExpression`. TypeBox puts `ref` in builder options. `style`,
521
+ * `explode` and `allowEmptyValue` are the parameter's own and apply with a `paramIn`; Zod,
522
+ * Valibot, Effect and Arktype read them, TypeBox ignores them.
523
+ */
511
524
  export type ToExpressionOptions = {
512
525
  readonly ref?: string;
526
+ readonly style?: ParamStyle;
527
+ readonly explode?: boolean;
528
+ readonly allowEmptyValue?: boolean;
513
529
  };
514
530
  /**
515
531
  * Flags `renderImport` uses when the schemas builder needs more than the
@@ -566,18 +582,12 @@ export type ComponentAdapter = {
566
582
  readonly reservedTypeNames?: readonly string[];
567
583
  };
568
584
  export declare function makeAdapter(lib: SchemaLib): ComponentAdapter;
569
- //#endregion
570
- //#region src/helper/ref-resolver.d.ts
571
585
  export declare function valueToCode(value: unknown, codeReplacements?: ReadonlyMap<unknown, string>, identifiers?: ReadonlyMap<string, string>): string;
572
- //#endregion
573
- //#region src/helper/schema-replacements.d.ts
574
586
  type SchemaReplacementsOptions = {
575
587
  readonly slot?: SchemaSlot;
576
588
  readonly identifiers?: ReadonlyMap<string, string>;
577
589
  };
578
590
  export declare function makeSchemaReplacements(value: unknown, adapter: ComponentAdapter, options?: SchemaReplacementsOptions): ReadonlyMap<unknown, string>;
579
- //#endregion
580
- //#region src/utils/index.d.ts
581
591
  export declare function toPascalCase(str: string): string;
582
592
  /**
583
593
  * Extract the component name from a `$ref`, decoding percent-encoding so the
@@ -587,7 +597,7 @@ export declare function toPascalCase(str: string): string;
587
597
  export declare function schemaRefToName(ref: string): string;
588
598
  /**
589
599
  * Convert a name to a valid PascalCase TypeScript identifier. Mirrors
590
- * schema-to-library's `toIdentifierPascalCase` so reference identifiers match
600
+ * schema-truth's `toIdentifierPascalCase` so reference identifiers match
591
601
  * the component declaration names it emits. Non-ASCII names are encoded
592
602
  * injectively so distinct names never collide.
593
603
  */
@@ -620,8 +630,6 @@ export declare function makeSafeKey(key: string): string;
620
630
  export declare function isRecord(v: unknown): v is {
621
631
  readonly [k: string]: unknown;
622
632
  };
623
- //#endregion
624
- //#region src/generator/components/declaration.d.ts
625
633
  type ComponentDeclaration = {
626
634
  readonly name: string;
627
635
  readonly varName: string;
@@ -633,44 +641,24 @@ type ComponentCodeOptions = {
633
641
  readonly readonly?: boolean;
634
642
  readonly identifiers?: ReadonlyMap<string, string>;
635
643
  };
636
- //#endregion
637
- //#region src/generator/components/callbacks.d.ts
638
644
  export declare function makeCallbacksDeclarations(components: Components, adapter: ComponentAdapter, options?: ComponentCodeOptions): readonly ComponentDeclaration[];
639
645
  export declare function makeCallbacksCode(components: Components, adapter: ComponentAdapter, readonly: boolean): string;
640
- //#endregion
641
- //#region src/generator/components/examples.d.ts
642
646
  export declare function makeExamplesDeclarations(components: Components, options?: ComponentCodeOptions): readonly ComponentDeclaration[];
643
647
  export declare function makeExamplesCode(components: Components, readonly: boolean): string;
644
- //#endregion
645
- //#region src/generator/components/headers.d.ts
646
648
  export declare function makeHeadersDeclarations(components: Components, adapter: ComponentAdapter, options?: ComponentCodeOptions): readonly ComponentDeclaration[];
647
649
  export declare function makeHeadersCode(components: Components, adapter: ComponentAdapter, exportTypes?: boolean): string;
648
- //#endregion
649
- //#region src/generator/components/links.d.ts
650
650
  export declare function makeLinksDeclarations(components: Components, options?: ComponentCodeOptions): readonly ComponentDeclaration[];
651
651
  export declare function makeLinksCode(components: Components, readonly: boolean): string;
652
- //#endregion
653
- //#region src/generator/components/media-types.d.ts
654
652
  export declare function makeMediaTypesDeclarations(components: Components, adapter: ComponentAdapter, options?: ComponentCodeOptions): readonly ComponentDeclaration[];
655
653
  export declare function makeMediaTypesCode(components: Components, adapter: ComponentAdapter, exportTypes?: boolean): string;
656
- //#endregion
657
- //#region src/generator/components/parameters.d.ts
658
654
  export declare function makeParametersDeclarations(components: Components, adapter: ComponentAdapter, options?: ComponentCodeOptions): readonly ComponentDeclaration[];
659
655
  export declare function makeParametersCode(components: Components, adapter: ComponentAdapter, exportTypes?: boolean): string;
660
- //#endregion
661
- //#region src/generator/components/path-items.d.ts
662
656
  export declare function makePathItemsDeclarations(components: Components, adapter: ComponentAdapter, options?: ComponentCodeOptions): readonly ComponentDeclaration[];
663
657
  export declare function makePathItemsCode(components: Components, adapter: ComponentAdapter, readonly: boolean): string;
664
- //#endregion
665
- //#region src/generator/components/request-bodies.d.ts
666
658
  export declare function makeRequestBodiesDeclarations(components: Components, adapter: ComponentAdapter, options?: ComponentCodeOptions): readonly ComponentDeclaration[];
667
659
  export declare function makeRequestBodiesCode(components: Components, adapter: ComponentAdapter, readonly: boolean): string;
668
- //#endregion
669
- //#region src/generator/components/responses.d.ts
670
660
  export declare function makeResponsesDeclarations(components: Components, adapter: ComponentAdapter, options?: ComponentCodeOptions): readonly ComponentDeclaration[];
671
661
  export declare function makeResponsesCode(components: Components, adapter: ComponentAdapter, readonly: boolean): string;
672
- //#endregion
673
- //#region src/generator/components/schemas.d.ts
674
662
  type SchemasOptions = {
675
663
  readonly exportTypes?: boolean;
676
664
  readonly readonly?: boolean;
@@ -693,7 +681,7 @@ type SchemasOptions = {
693
681
  readonly wrapDeclaration?: (expr: string, name: string) => string;
694
682
  /**
695
683
  * Register the OpenAPI key on each declaration. TypeBox puts it in the
696
- * outermost builder options via schema-to-library; the other libraries use
684
+ * outermost builder options via schema-truth; the other libraries use
697
685
  * `adapter.withRef` (an outer wrap). A bare identifier is left unchanged.
698
686
  */
699
687
  readonly ref?: boolean;
@@ -738,9 +726,6 @@ export declare function makeSchemaDeclarations(schemas: {
738
726
  * order. Returns `''` when schemas are missing or empty.
739
727
  */
740
728
  export declare function makeSchemasCode(components: Components, adapter: ComponentAdapter, options?: SchemasOptions): string;
741
- //#endregion
742
- //#region src/generator/components/security-schemes.d.ts
743
729
  export declare function makeSecuritySchemesDeclarations(components: Components, options?: ComponentCodeOptions): readonly ComponentDeclaration[];
744
730
  export declare function makeSecuritySchemesCode(components: Components, readonly: boolean): string;
745
- //#endregion
746
731
  export type { ComponentCodeOptions, ComponentDeclaration, SchemaDeclaration, SchemasOptions };
package/dist/index.js CHANGED
@@ -2,12 +2,12 @@ import path from "node:path";
2
2
  import SwaggerParser from "@apidevtools/swagger-parser";
3
3
  import { NodeHost, compile } from "@typespec/compiler";
4
4
  import { getOpenAPI3 } from "@typespec/openapi3";
5
- import { schemaToArktype } from "schema-to-library/arktype";
6
- import { schemaToEffect } from "schema-to-library/effect";
7
- import { schemaToTypebox } from "schema-to-library/typebox";
8
- import { schemaToValibot } from "schema-to-library/valibot";
9
- import { schemaToZod } from "schema-to-library/zod";
10
- //#region src/openapi/index.ts
5
+ import { schemaToArktype } from "schema-truth/arktype";
6
+ import { schemaToEffect } from "schema-truth/effect";
7
+ import { schemaToTypebox } from "schema-truth/typebox";
8
+ import { schemaToValibot } from "schema-truth/valibot";
9
+ import { schemaToZod } from "schema-truth/zod";
10
+ // src/openapi/index.ts
11
11
  async function parseOpenAPI(input) {
12
12
  try {
13
13
  if (typeof input === "string" && input.endsWith(".tsp")) {
@@ -34,20 +34,41 @@ async function parseOpenAPI(input) {
34
34
  };
35
35
  }
36
36
  }
37
- //#endregion
38
- //#region src/adapter/index.ts
37
+ // src/adapter/index.ts
38
+ const PARAM_STYLES = [
39
+ "matrix",
40
+ "label",
41
+ "simple",
42
+ "form",
43
+ "spaceDelimited",
44
+ "pipeDelimited",
45
+ "deepObject"
46
+ ];
47
+ /** Narrow a Parameter Object's free-form `style` to one schema-truth reads. */
48
+ function isParamStyle(style) {
49
+ return PARAM_STYLES.includes(style);
50
+ }
39
51
  /** A generated identifier (`TagSchema`) is already a registered name — do not wrap it. */
40
52
  function isBareIdent(expr) {
41
53
  return /^[A-Za-z_$][\w$]*$/u.test(expr);
42
54
  }
43
55
  /**
44
- * Widen the rich `Schema` type to a bare JSON-Schema object for schema-to-library.
56
+ * Widen the rich `Schema` type to a bare JSON-Schema object for schema-truth.
45
57
  * `Schema` is not structurally assignable to its `JSONSchema` (e.g. `x-emailPattern`
46
58
  * literal unions differ), so this `as`-free bridge erases the incompatible members.
47
59
  */
48
60
  function toJsonSchema(schema) {
49
61
  return schema;
50
62
  }
63
+ /** The wire options schema-truth reads, without an `undefined` member. */
64
+ function wireOptions(paramIn, options) {
65
+ return {
66
+ ...paramIn && { paramIn },
67
+ ...options?.style !== void 0 && { style: options.style },
68
+ ...options?.explode !== void 0 && { explode: options.explode },
69
+ ...options?.allowEmptyValue !== void 0 && { allowEmptyValue: options.allowEmptyValue }
70
+ };
71
+ }
51
72
  /** Pull the bare expression out of a `export const X = <expr>` wrapper, then strip cross-schema refs. */
52
73
  function extractExpr(code, stripRefs = (s) => s) {
53
74
  const joined = code.split("\n").filter((line) => !line.startsWith("import ")).join("\n").trim();
@@ -90,12 +111,12 @@ function renderArktypeCyclic(varName, containerExpr, externals) {
90
111
  }
91
112
  function makeZodAdapter() {
92
113
  return {
93
- toExpression(schema, paramIn) {
114
+ toExpression(schema, paramIn, options) {
94
115
  return extractExpr(schemaToZod(toJsonSchema(schema), {
95
116
  exportType: false,
96
117
  openapi: true,
97
118
  readonly: false,
98
- ...paramIn && { paramIn }
119
+ ...wireOptions(paramIn, options)
99
120
  }), stripZodLazy);
100
121
  },
101
122
  renderImport() {
@@ -117,12 +138,12 @@ function makeZodAdapter() {
117
138
  }
118
139
  function makeValibotAdapter() {
119
140
  return {
120
- toExpression(schema, paramIn) {
141
+ toExpression(schema, paramIn, options) {
121
142
  return extractExpr(schemaToValibot(toJsonSchema(schema), {
122
143
  exportType: false,
123
144
  openapi: true,
124
145
  readonly: false,
125
- ...paramIn && { paramIn }
146
+ ...wireOptions(paramIn, options)
126
147
  }), stripValibotLazy);
127
148
  },
128
149
  renderImport() {
@@ -145,12 +166,12 @@ function makeValibotAdapter() {
145
166
  }
146
167
  function makeArktypeAdapter() {
147
168
  return {
148
- toExpression(schema, paramIn) {
169
+ toExpression(schema, paramIn, options) {
149
170
  return extractExpr(schemaToArktype(toJsonSchema(schema), {
150
171
  exportType: false,
151
172
  openapi: true,
152
173
  readonly: false,
153
- ...paramIn && { paramIn }
174
+ ...wireOptions(paramIn, options)
154
175
  }));
155
176
  },
156
177
  renderImport(options) {
@@ -173,7 +194,7 @@ function makeTypeboxAdapter() {
173
194
  exportType: false,
174
195
  openapi: true,
175
196
  readonly: false,
176
- ...paramIn && { paramIn },
197
+ ...wireOptions(paramIn, options),
177
198
  ...options?.ref !== void 0 && { ref: options.ref }
178
199
  }));
179
200
  },
@@ -193,12 +214,12 @@ function makeTypeboxAdapter() {
193
214
  }
194
215
  function makeEffectAdapter() {
195
216
  return {
196
- toExpression(schema, paramIn) {
217
+ toExpression(schema, paramIn, options) {
197
218
  return extractExpr(schemaToEffect(toJsonSchema(schema), {
198
219
  exportType: false,
199
220
  openapi: true,
200
221
  readonly: false,
201
- ...paramIn && { paramIn }
222
+ ...wireOptions(paramIn, options)
202
223
  }), stripEffectSuspend);
203
224
  },
204
225
  renderImport() {
@@ -223,8 +244,7 @@ function makeEffectAdapter() {
223
244
  }
224
245
  };
225
246
  }
226
- //#endregion
227
- //#region src/utils/index.ts
247
+ // src/utils/index.ts
228
248
  function toPascalCase(str) {
229
249
  return str.replaceAll(/[^a-zA-Z0-9]+(.)/gu, (_, c) => c.toUpperCase()).replace(/^(.)/u, (_, c) => c.toUpperCase());
230
250
  }
@@ -260,7 +280,7 @@ function encodeNonAscii(name) {
260
280
  }
261
281
  /**
262
282
  * Convert a name to a valid PascalCase TypeScript identifier. Mirrors
263
- * schema-to-library's `toIdentifierPascalCase` so reference identifiers match
283
+ * schema-truth's `toIdentifierPascalCase` so reference identifiers match
264
284
  * the component declaration names it emits. Non-ASCII names are encoded
265
285
  * injectively so distinct names never collide.
266
286
  */
@@ -315,8 +335,7 @@ function makeSafeKey(key) {
315
335
  function isRecord(v) {
316
336
  return v !== null && typeof v === "object" && !Array.isArray(v);
317
337
  }
318
- //#endregion
319
- //#region src/helper/ref-resolver.ts
338
+ // src/helper/ref-resolver.ts
320
339
  function valueToCode(value, codeReplacements, identifiers) {
321
340
  return encodeValue(value, codeReplacements, identifiers, /* @__PURE__ */ new Set());
322
341
  }
@@ -351,8 +370,7 @@ function encodeValue(value, codeReplacements, identifiers, seen) {
351
370
  }
352
371
  return "null";
353
372
  }
354
- //#endregion
355
- //#region src/helper/schema-replacements.ts
373
+ // src/helper/schema-replacements.ts
356
374
  function isInlineSchema(value) {
357
375
  if (!isRecord(value)) return false;
358
376
  if ("$ref" in value) return false;
@@ -383,8 +401,7 @@ function makeEntries(v, adapter, seen, path, options) {
383
401
  seen.delete(v);
384
402
  return entries;
385
403
  }
386
- //#endregion
387
- //#region src/generator/components/declaration.ts
404
+ // src/generator/components/declaration.ts
388
405
  /**
389
406
  * Join declaration bodies the way `make<Kind>Code` already does: `;` between
390
407
  * entries, no `import ` line. `trailingNewline` matches examples / links /
@@ -396,8 +413,7 @@ function joinDeclarations(declarations, options) {
396
413
  const text = options?.trailingNewline === true ? `${body}\n` : body;
397
414
  return options?.importLine === void 0 ? text : `${options.importLine}\n\n${text}`;
398
415
  }
399
- //#endregion
400
- //#region src/generator/components/callbacks.ts
416
+ // src/generator/components/callbacks.ts
401
417
  function makeCallbacksDeclarations(components, adapter, options) {
402
418
  const { callbacks } = components;
403
419
  if (!callbacks) return [];
@@ -421,8 +437,7 @@ function makeCallbacksDeclarations(components, adapter, options) {
421
437
  function makeCallbacksCode(components, adapter, readonly) {
422
438
  return joinDeclarations(makeCallbacksDeclarations(components, adapter, { readonly }));
423
439
  }
424
- //#endregion
425
- //#region src/generator/components/examples.ts
440
+ // src/generator/components/examples.ts
426
441
  function makeExamplesDeclarations(components, options) {
427
442
  const { examples } = components;
428
443
  if (!examples) return [];
@@ -441,8 +456,7 @@ function makeExamplesDeclarations(components, options) {
441
456
  function makeExamplesCode(components, readonly) {
442
457
  return joinDeclarations(makeExamplesDeclarations(components, { readonly }), { trailingNewline: true });
443
458
  }
444
- //#endregion
445
- //#region src/generator/components/headers.ts
459
+ // src/generator/components/headers.ts
446
460
  function makeHeadersDeclarations(components, adapter, options) {
447
461
  const { headers } = components;
448
462
  if (!headers) return [];
@@ -467,8 +481,7 @@ function makeHeadersCode(components, adapter, exportTypes) {
467
481
  importLine: adapter.renderImport()
468
482
  });
469
483
  }
470
- //#endregion
471
- //#region src/generator/components/links.ts
484
+ // src/generator/components/links.ts
472
485
  function makeLinksDeclarations(components, options) {
473
486
  const { links } = components;
474
487
  if (!links) return [];
@@ -487,8 +500,7 @@ function makeLinksDeclarations(components, options) {
487
500
  function makeLinksCode(components, readonly) {
488
501
  return joinDeclarations(makeLinksDeclarations(components, { readonly }), { trailingNewline: true });
489
502
  }
490
- //#endregion
491
- //#region src/generator/components/media-types.ts
503
+ // src/generator/components/media-types.ts
492
504
  function makeMediaTypesDeclarations(components, adapter, options) {
493
505
  const { mediaTypes } = components;
494
506
  if (!mediaTypes) return [];
@@ -514,17 +526,19 @@ function makeMediaTypesCode(components, adapter, exportTypes) {
514
526
  importLine: adapter.renderImport()
515
527
  });
516
528
  }
517
- //#endregion
518
- //#region src/generator/components/parameters.ts
529
+ // src/generator/components/parameters.ts
519
530
  function makeParametersDeclarations(components, adapter, options) {
520
531
  const { parameters } = components;
521
532
  if (!parameters) return [];
522
533
  return Object.entries(parameters).flatMap(([name, param]) => {
523
534
  if (!param.schema) return [];
524
- const paramIn = param.in === "query" || param.in === "path" ? param.in : void 0;
525
535
  const ident = toIdentifierPascalCase(name);
526
536
  const varName = `${ident}ParamsSchema`;
527
- const raw = adapter.toExpression(param.schema, paramIn);
537
+ const raw = adapter.toExpression(param.schema, param.in, {
538
+ ...param.style !== void 0 && isParamStyle(param.style) && { style: param.style },
539
+ ...param.explode !== void 0 && { explode: param.explode },
540
+ ...param.allowEmptyValue !== void 0 && { allowEmptyValue: param.allowEmptyValue }
541
+ });
528
542
  const expr = adapter.wrapSchema ? adapter.wrapSchema(raw, "parameter") : raw;
529
543
  const typeExport = options?.exportTypes === true ? `\n\n${adapter.renderTypeInfer(varName)}` : "";
530
544
  return [{
@@ -541,8 +555,7 @@ function makeParametersCode(components, adapter, exportTypes) {
541
555
  importLine: adapter.renderImport()
542
556
  });
543
557
  }
544
- //#endregion
545
- //#region src/generator/components/path-items.ts
558
+ // src/generator/components/path-items.ts
546
559
  function makePathItemsDeclarations(components, adapter, options) {
547
560
  const { pathItems } = components;
548
561
  if (!pathItems) return [];
@@ -565,8 +578,7 @@ function makePathItemsDeclarations(components, adapter, options) {
565
578
  function makePathItemsCode(components, adapter, readonly) {
566
579
  return joinDeclarations(makePathItemsDeclarations(components, adapter, { readonly }));
567
580
  }
568
- //#endregion
569
- //#region src/generator/components/request-bodies.ts
581
+ // src/generator/components/request-bodies.ts
570
582
  function makeRequestBodiesDeclarations(components, adapter, options) {
571
583
  const { requestBodies } = components;
572
584
  if (!requestBodies) return [];
@@ -589,8 +601,7 @@ function makeRequestBodiesDeclarations(components, adapter, options) {
589
601
  function makeRequestBodiesCode(components, adapter, readonly) {
590
602
  return joinDeclarations(makeRequestBodiesDeclarations(components, adapter, { readonly }));
591
603
  }
592
- //#endregion
593
- //#region src/generator/components/responses.ts
604
+ // src/generator/components/responses.ts
594
605
  function makeResponsesDeclarations(components, adapter, options) {
595
606
  const { responses } = components;
596
607
  if (!responses) return [];
@@ -614,8 +625,7 @@ function makeResponsesDeclarations(components, adapter, options) {
614
625
  function makeResponsesCode(components, adapter, readonly) {
615
626
  return joinDeclarations(makeResponsesDeclarations(components, adapter, { readonly }));
616
627
  }
617
- //#endregion
618
- //#region src/helper/graph.ts
628
+ // src/helper/graph.ts
619
629
  /** Every `components.schemas` name a schema reaches through `$ref`, at any depth. */
620
630
  function collectSchemaRefs(node) {
621
631
  if (Array.isArray(node)) return node.flatMap(collectSchemaRefs);
@@ -709,8 +719,7 @@ function makeCyclicType(name, typeName, schema, infer, readonly, style = {}) {
709
719
  typeName
710
720
  }, infer, readonly, style)}`;
711
721
  }
712
- //#endregion
713
- //#region src/helper/identifiers.ts
722
+ // src/helper/identifiers.ts
714
723
  /**
715
724
  * Identifier rewriting on generated source without a parser: skip quoted
716
725
  * strings so identifier-shaped text inside descriptions and `Type.Ref('X')`
@@ -770,8 +779,7 @@ function wrapReferences(expr, names, wrap) {
770
779
  }
771
780
  return result;
772
781
  }
773
- //#endregion
774
- //#region src/generator/components/schemas.ts
782
+ // src/generator/components/schemas.ts
775
783
  /** Keys whose value is a subschema (or a list of them) and keys whose value maps names to subschemas. */
776
784
  const SUBSCHEMA_KEYS = /* @__PURE__ */ new Set([
777
785
  "items",
@@ -811,7 +819,7 @@ function mapSchema(schema, fn) {
811
819
  }
812
820
  /**
813
821
  * `readonly` as the declarative `x-readonly` extension on every object and array,
814
- * which schema-to-library turns into each library's readonly form.
822
+ * which schema-truth turns into each library's readonly form.
815
823
  */
816
824
  function markReadonly(schema) {
817
825
  return mapSchema(schema, (node) => {
@@ -825,7 +833,7 @@ function markReadonly(schema) {
825
833
  /**
826
834
  * TypeBox and Arktype cannot express a cycle with standalone `const`s: the group
827
835
  * becomes one `Type.Cyclic(...)` / `scope(...)` container and each member selects
828
- * its entry. schema-to-library builds the container from a `$defs` document.
836
+ * its entry. schema-truth builds the container from a `$defs` document.
829
837
  */
830
838
  function rewriteCollisionRef(node, identifiers) {
831
839
  if (typeof node.$ref !== "string" || !node.$ref.startsWith("#/components/schemas/")) return node;
@@ -935,8 +943,7 @@ function makeSchemasCode(components, adapter, options) {
935
943
  if (declarations.length === 0) return "";
936
944
  return `${schemaImportLine(adapter, options, declarations.some((d) => d.importLine !== schemaImportLine(adapter, options)))}\n\n${declarations.map((d) => d.code).join(";")}\n`;
937
945
  }
938
- //#endregion
939
- //#region src/generator/components/security-schemes.ts
946
+ // src/generator/components/security-schemes.ts
940
947
  function makeSecuritySchemesDeclarations(components, options) {
941
948
  const { securitySchemes } = components;
942
949
  if (!securitySchemes) return [];
@@ -955,5 +962,4 @@ function makeSecuritySchemesDeclarations(components, options) {
955
962
  function makeSecuritySchemesCode(components, readonly) {
956
963
  return joinDeclarations(makeSecuritySchemesDeclarations(components, { readonly }), { trailingNewline: true });
957
964
  }
958
- //#endregion
959
- export { declarationFileName, isRecord, makeAdapter, makeCallbacksCode, makeCallbacksDeclarations, makeExamplesCode, makeExamplesDeclarations, makeHeadersCode, makeHeadersDeclarations, makeLinksCode, makeLinksDeclarations, makeMediaTypesCode, makeMediaTypesDeclarations, makeParametersCode, makeParametersDeclarations, makePathItemsCode, makePathItemsDeclarations, makeRequestBodiesCode, makeRequestBodiesDeclarations, makeResponsesCode, makeResponsesDeclarations, makeSafeKey, makeSchemaDeclarations, makeSchemaIdentifiers, makeSchemaReplacements, makeSchemaVarName, makeSchemasCode, makeSecuritySchemesCode, makeSecuritySchemesDeclarations, parseOpenAPI, schemaImportLine, schemaRefToName, toIdentifierPascalCase, toPascalCase, valueToCode };
965
+ export { declarationFileName, isParamStyle, isRecord, makeAdapter, makeCallbacksCode, makeCallbacksDeclarations, makeExamplesCode, makeExamplesDeclarations, makeHeadersCode, makeHeadersDeclarations, makeLinksCode, makeLinksDeclarations, makeMediaTypesCode, makeMediaTypesDeclarations, makeParametersCode, makeParametersDeclarations, makePathItemsCode, makePathItemsDeclarations, makeRequestBodiesCode, makeRequestBodiesDeclarations, makeResponsesCode, makeResponsesDeclarations, makeSafeKey, makeSchemaDeclarations, makeSchemaIdentifiers, makeSchemaReplacements, makeSchemaVarName, makeSchemasCode, makeSecuritySchemesCode, makeSecuritySchemesDeclarations, parseOpenAPI, schemaImportLine, schemaRefToName, toIdentifierPascalCase, toPascalCase, valueToCode };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oas-truth",
3
- "version": "0.4.0",
3
+ "version": "0.5.1",
4
4
  "description": "oas-truth is a parser from OpenAPI and TypeSpec to a typed OpenAPI document",
5
5
  "keywords": [
6
6
  "openapi",
@@ -28,23 +28,23 @@
28
28
  }
29
29
  },
30
30
  "dependencies": {
31
- "schema-to-library": "^0.5.0"
31
+ "schema-truth": "^0.7.0"
32
32
  },
33
33
  "devDependencies": {
34
- "@apidevtools/swagger-parser": "^13.0.0",
35
- "@types/node": "^26.5.1",
36
- "@typespec/compiler": "1.16.0",
37
- "@typespec/http": "1.16.0",
38
- "@typespec/openapi": "1.16.0",
39
- "@typespec/openapi3": "1.16.0",
40
- "@typespec/rest": "0.86.0",
41
- "@typespec/versioning": "0.86.0",
42
- "arktype": "^2.2.3",
43
- "effect": "4.0.0-rc.112",
44
- "typebox": "^1.3.30",
34
+ "@apidevtools/swagger-parser": "^13.1.0",
35
+ "@types/node": "^26.6.5",
36
+ "@typespec/compiler": "1.17.0",
37
+ "@typespec/http": "1.17.0",
38
+ "@typespec/openapi": "1.17.0",
39
+ "@typespec/openapi3": "1.17.0",
40
+ "@typespec/rest": "0.87.0",
41
+ "@typespec/versioning": "0.87.0",
42
+ "arktype": "^2.2.9",
43
+ "effect": "4.0.6",
44
+ "typebox": "^1.4.3",
45
45
  "typescript": "^7.0.2",
46
46
  "valibot": "^1.5.0",
47
- "zod": "^4.6.2"
47
+ "zod": "^4.6.7"
48
48
  },
49
49
  "peerDependencies": {
50
50
  "@apidevtools/swagger-parser": ">=12.0.0 <14.0.0",