oas-truth 0.0.1 → 0.0.3

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 (3) hide show
  1. package/dist/index.d.ts +46 -47
  2. package/dist/index.js +34 -26
  3. package/package.json +32 -14
package/dist/index.d.ts CHANGED
@@ -1,17 +1,16 @@
1
1
  import SwaggerParser from "@apidevtools/swagger-parser";
2
-
3
2
  //#region src/openapi/index.d.ts
4
- declare function parseOpenAPI(input: string): Promise<{
3
+ export declare function parseOpenAPI(input: string): Promise<{
5
4
  readonly ok: true;
6
5
  readonly value: OpenAPI;
7
6
  readonly error?: never;
8
7
  } | {
8
+ readonly value?: never;
9
9
  readonly ok: false;
10
10
  readonly error: string;
11
- readonly value?: never;
12
11
  }>;
13
12
  type BaseOpenAPI = Awaited<ReturnType<typeof SwaggerParser.bundle>>;
14
- type OpenAPI = BaseOpenAPI & {
13
+ export type OpenAPI = BaseOpenAPI & {
15
14
  readonly openapi?: string;
16
15
  readonly $self?: string;
17
16
  readonly info?: {
@@ -53,7 +52,7 @@ type OpenAPI = BaseOpenAPI & {
53
52
  } & {
54
53
  paths: OpenAPIPaths;
55
54
  };
56
- type Components = {
55
+ export type Components = {
57
56
  readonly schemas?: {
58
57
  readonly [k: string]: Schema;
59
58
  };
@@ -121,12 +120,12 @@ type OAuthFlow = {
121
120
  };
122
121
  };
123
122
  };
124
- type OpenAPIPaths = { readonly [P in keyof NonNullable<BaseOpenAPI['paths']>]: PathItem };
125
- type Type = 'string' | 'number' | 'integer' | 'date' | 'boolean' | 'array' | 'object' | 'null';
126
- type Format = FormatString | FormatNumber;
127
- type FormatString = 'email' | 'uuid' | 'uuidv4' | 'uuidv6' | 'uuidv7' | 'url' | 'uri' | 'httpUrl' | 'hostname' | 'hex' | 'jwt' | 'emoji' | 'base64' | 'base64url' | 'nanoid' | 'cuid' | 'cuid2' | 'ulid' | 'ipv4' | 'ipv6' | 'cidrv4' | 'cidrv6' | 'date' | 'time' | 'date-time' | 'duration' | 'binary' | 'byte' | 'password' | 'mac' | 'hash' | 'e164' | 'guid' | 'toLowerCase' | 'toUpperCase' | 'trim';
128
- type FormatNumber = 'int32' | 'int64' | 'bigint' | 'float' | 'float32' | 'float64' | 'double' | 'password';
129
- type Ref = `#/components/schemas/${string}` | `#/components/responses/${string}` | `#/components/parameters/${string}` | `#/components/examples/${string}` | `#/components/requestBodies/${string}` | `#/components/headers/${string}` | `#/components/securitySchemes/${string}` | `#/components/links/${string}` | `#/components/callbacks/${string}` | `#/components/pathItems/${string}` | `#/components/mediaTypes/${string}`;
123
+ export type OpenAPIPaths = { readonly [P in keyof NonNullable<BaseOpenAPI['paths']>]: PathItem; };
124
+ export type Type = 'string' | 'number' | 'integer' | 'date' | 'boolean' | 'array' | 'object' | 'null';
125
+ export type Format = FormatString | FormatNumber;
126
+ export type FormatString = 'email' | 'uuid' | 'uuidv4' | 'uuidv6' | 'uuidv7' | 'url' | 'uri' | 'httpUrl' | 'hostname' | 'hex' | 'jwt' | 'emoji' | 'base64' | 'base64url' | 'nanoid' | 'cuid' | 'cuid2' | 'ulid' | 'ipv4' | 'ipv6' | 'cidrv4' | 'cidrv6' | 'date' | 'time' | 'date-time' | 'duration' | 'binary' | 'byte' | 'password' | 'mac' | 'hash' | 'e164' | 'guid' | 'toLowerCase' | 'toUpperCase' | 'trim';
127
+ export type FormatNumber = 'int32' | 'int64' | 'bigint' | 'float' | 'float32' | 'float64' | 'double' | 'password';
128
+ export type Ref = `#/components/schemas/${string}` | `#/components/responses/${string}` | `#/components/parameters/${string}` | `#/components/examples/${string}` | `#/components/requestBodies/${string}` | `#/components/headers/${string}` | `#/components/securitySchemes/${string}` | `#/components/links/${string}` | `#/components/callbacks/${string}` | `#/components/pathItems/${string}` | `#/components/mediaTypes/${string}`;
130
129
  type Server = {
131
130
  readonly url: string;
132
131
  readonly description?: string;
@@ -139,7 +138,7 @@ type Server = {
139
138
  };
140
139
  };
141
140
  };
142
- type Header = {
141
+ export type Header = {
143
142
  readonly description?: string;
144
143
  readonly required?: boolean;
145
144
  readonly deprecated?: boolean;
@@ -160,7 +159,7 @@ type Header = {
160
159
  schema?: Schema;
161
160
  content?: Content;
162
161
  };
163
- type Link = {
162
+ export type Link = {
164
163
  readonly operationRef?: string;
165
164
  readonly operationId?: string;
166
165
  readonly parameters?: {
@@ -170,12 +169,12 @@ type Link = {
170
169
  readonly description?: string;
171
170
  readonly server?: Server;
172
171
  };
173
- type Reference = {
172
+ export type Reference = {
174
173
  readonly $ref?: Ref;
175
174
  readonly summary?: string;
176
175
  readonly description?: string;
177
176
  };
178
- type Encoding = {
177
+ export type Encoding = {
179
178
  readonly contentType?: string;
180
179
  readonly headers?: {
181
180
  readonly [k: string]: Header | Reference;
@@ -186,10 +185,10 @@ type Encoding = {
186
185
  readonly prefixEncoding?: Encoding;
187
186
  readonly itemEncoding?: Encoding;
188
187
  };
189
- type Content = {
188
+ export type Content = {
190
189
  readonly [k: string]: Media;
191
190
  };
192
- type PathItem = {
191
+ export type PathItem = {
193
192
  readonly $ref?: Ref;
194
193
  readonly summary?: string;
195
194
  readonly description?: string;
@@ -208,7 +207,7 @@ type PathItem = {
208
207
  readonly servers?: readonly Server[];
209
208
  readonly parameters?: readonly (Parameter | Reference)[];
210
209
  };
211
- type Operation = {
210
+ export type Operation = {
212
211
  readonly tags?: readonly string[];
213
212
  readonly summary?: string;
214
213
  readonly description?: string;
@@ -246,7 +245,7 @@ type Operation = {
246
245
  }[];
247
246
  readonly 'x-pagination'?: boolean;
248
247
  };
249
- type Responses = {
248
+ export type Responses = {
250
249
  readonly $ref?: Ref;
251
250
  readonly summary?: string;
252
251
  readonly description?: string;
@@ -269,7 +268,7 @@ type ExternalDocs = {
269
268
  readonly url: string;
270
269
  readonly description?: string;
271
270
  };
272
- type Schema = {
271
+ export type Schema = {
273
272
  readonly discriminator?: Discriminator;
274
273
  readonly xml?: {
275
274
  readonly nodeType?: string;
@@ -320,7 +319,8 @@ type Schema = {
320
319
  * `false` = no trailing items / length cap). Boolean form is exercised when
321
320
  * paired with `prefixItems` to enforce a strict tuple shape.
322
321
  */
323
- readonly items?: Schema | readonly Schema[] | boolean; /** JSON Schema 2020-12: Tuple validation */
322
+ readonly items?: Schema | readonly Schema[] | boolean;
323
+ /** JSON Schema 2020-12: Tuple validation */
324
324
  readonly prefixItems?: readonly Schema[];
325
325
  readonly enum?: readonly (string | number | boolean | null | readonly (string | number | boolean | null)[])[];
326
326
  readonly nullable?: boolean;
@@ -445,7 +445,7 @@ type Schema = {
445
445
  readonly 'x-transform'?: string;
446
446
  readonly 'x-pipe'?: string;
447
447
  };
448
- type Parameter = {
448
+ export type Parameter = {
449
449
  readonly $ref?: Ref;
450
450
  readonly name: string;
451
451
  readonly in: 'path' | 'query' | 'header' | 'cookie';
@@ -470,14 +470,14 @@ type Parameter = {
470
470
  } | Reference;
471
471
  };
472
472
  };
473
- type RequestBody = {
473
+ export type RequestBody = {
474
474
  readonly description?: string;
475
475
  readonly content?: {
476
476
  readonly [k: string]: Media | Reference;
477
477
  };
478
478
  readonly required?: boolean;
479
479
  };
480
- type Media = {
480
+ export type Media = {
481
481
  readonly schema: Schema;
482
482
  readonly itemSchema?: Schema;
483
483
  readonly example?: unknown;
@@ -497,13 +497,13 @@ type Media = {
497
497
  readonly prefixEncoding?: Encoding;
498
498
  readonly itemEncoding?: Encoding;
499
499
  };
500
- type Callbacks = {
500
+ export type Callbacks = {
501
501
  readonly [k: string]: PathItem;
502
502
  };
503
503
  //#endregion
504
504
  //#region src/adapter/index.d.ts
505
- type ParamIn = 'query' | 'path';
506
- type SchemaLib = 'zod' | 'valibot' | 'arktype' | 'effect' | 'typebox';
505
+ export type ParamIn = 'query' | 'path';
506
+ export type SchemaLib = 'zod' | 'valibot' | 'arktype' | 'effect' | 'typebox';
507
507
  /**
508
508
  * The minimal surface the component generators consume from a validator
509
509
  * adapter. Each library's full adapter (carrying `toNamedExport`,
@@ -517,71 +517,70 @@ type SchemaLib = 'zod' | 'valibot' | 'arktype' | 'effect' | 'typebox';
517
517
  * omitting it leaves the expression untouched (identity), so the shared library
518
518
  * stays framework-agnostic.
519
519
  */
520
- type ComponentAdapter = {
520
+ export type ComponentAdapter = {
521
521
  readonly renderImport: () => string;
522
522
  readonly toExpression: (schema: Schema, paramIn?: ParamIn) => string;
523
523
  readonly renderTypeInfer: (constName: string) => string;
524
524
  readonly wrapSchema?: (expr: string) => string;
525
525
  };
526
- declare function makeAdapter(lib: SchemaLib): ComponentAdapter;
526
+ export declare function makeAdapter(lib: SchemaLib): ComponentAdapter;
527
527
  //#endregion
528
528
  //#region src/helper/ref-resolver.d.ts
529
- declare function valueToCode(value: unknown, codeReplacements?: ReadonlyMap<unknown, string>): string;
529
+ export declare function valueToCode(value: unknown, codeReplacements?: ReadonlyMap<unknown, string>): string;
530
530
  //#endregion
531
531
  //#region src/helper/schema-replacements.d.ts
532
- declare function makeSchemaReplacements(value: unknown, adapter: ComponentAdapter): ReadonlyMap<unknown, string>;
532
+ export declare function makeSchemaReplacements(value: unknown, adapter: ComponentAdapter): ReadonlyMap<unknown, string>;
533
533
  //#endregion
534
534
  //#region src/utils/index.d.ts
535
- declare function toPascalCase(str: string): string;
535
+ export declare function toPascalCase(str: string): string;
536
536
  /**
537
537
  * Extract the component name from a `$ref`, decoding percent-encoding so the
538
538
  * result matches the (decoded) key under `components.schemas`. Pure-ASCII refs
539
539
  * are returned unchanged. Used for component lookup, not variable naming.
540
540
  */
541
- declare function schemaRefToName(ref: string): string;
541
+ export declare function schemaRefToName(ref: string): string;
542
542
  /**
543
543
  * Convert a name to a valid PascalCase TypeScript identifier. Mirrors
544
544
  * schema-to-library's `toIdentifierPascalCase` so reference identifiers match
545
545
  * the component declaration names it emits. Non-ASCII names are encoded
546
546
  * injectively so distinct names never collide.
547
547
  */
548
- declare function toIdentifierPascalCase(name: string): string;
548
+ export declare function toIdentifierPascalCase(name: string): string;
549
549
  /**
550
550
  * Encode a property key for object-literal output: bare identifiers stay
551
551
  * unquoted, everything else is JSON-encoded so hyphenated/reserved/numeric
552
552
  * keys (e.g. `X-Request-ID`) emit as valid TypeScript.
553
553
  */
554
- declare function makeSafeKey(key: string): string;
554
+ export declare function makeSafeKey(key: string): string;
555
555
  /** Narrow an unknown value to a plain object (excludes arrays and null). */
556
- declare function isRecord(v: unknown): v is {
556
+ export declare function isRecord(v: unknown): v is {
557
557
  readonly [k: string]: unknown;
558
558
  };
559
559
  //#endregion
560
560
  //#region src/generator/components/callbacks.d.ts
561
- declare function makeCallbacksCode(components: Components, adapter: ComponentAdapter, readonly: boolean): string;
561
+ export declare function makeCallbacksCode(components: Components, adapter: ComponentAdapter, readonly: boolean): string;
562
562
  //#endregion
563
563
  //#region src/generator/components/examples.d.ts
564
- declare function makeExamplesCode(components: Components, readonly: boolean): string;
564
+ export declare function makeExamplesCode(components: Components, readonly: boolean): string;
565
565
  //#endregion
566
566
  //#region src/generator/components/headers.d.ts
567
- declare function makeHeadersCode(components: Components, adapter: ComponentAdapter, exportTypes?: boolean): string;
567
+ export declare function makeHeadersCode(components: Components, adapter: ComponentAdapter, exportTypes?: boolean): string;
568
568
  //#endregion
569
569
  //#region src/generator/components/links.d.ts
570
- declare function makeLinksCode(components: Components, readonly: boolean): string;
570
+ export declare function makeLinksCode(components: Components, readonly: boolean): string;
571
571
  //#endregion
572
572
  //#region src/generator/components/parameters.d.ts
573
- declare function makeParametersCode(components: Components, adapter: ComponentAdapter, exportTypes?: boolean): string;
573
+ export declare function makeParametersCode(components: Components, adapter: ComponentAdapter, exportTypes?: boolean): string;
574
574
  //#endregion
575
575
  //#region src/generator/components/path-items.d.ts
576
- declare function makePathItemsCode(components: Components, adapter: ComponentAdapter, readonly: boolean): string;
576
+ export declare function makePathItemsCode(components: Components, adapter: ComponentAdapter, readonly: boolean): string;
577
577
  //#endregion
578
578
  //#region src/generator/components/request-bodies.d.ts
579
- declare function makeRequestBodiesCode(components: Components, adapter: ComponentAdapter, readonly: boolean): string;
579
+ export declare function makeRequestBodiesCode(components: Components, adapter: ComponentAdapter, readonly: boolean): string;
580
580
  //#endregion
581
581
  //#region src/generator/components/responses.d.ts
582
- declare function makeResponsesCode(components: Components, adapter: ComponentAdapter, readonly: boolean): string;
582
+ export declare function makeResponsesCode(components: Components, adapter: ComponentAdapter, readonly: boolean): string;
583
583
  //#endregion
584
584
  //#region src/generator/components/security-schemes.d.ts
585
- declare function makeSecuritySchemesCode(components: Components, readonly: boolean): string;
586
- //#endregion
587
- export { Callbacks, ComponentAdapter, Components, Content, Encoding, Format, FormatNumber, FormatString, Header, Link, Media, OpenAPI, OpenAPIPaths, Operation, ParamIn, Parameter, PathItem, Ref, Reference, RequestBody, Responses, Schema, SchemaLib, Type, isRecord, makeAdapter, makeCallbacksCode, makeExamplesCode, makeHeadersCode, makeLinksCode, makeParametersCode, makePathItemsCode, makeRequestBodiesCode, makeResponsesCode, makeSafeKey, makeSchemaReplacements, makeSecuritySchemesCode, parseOpenAPI, schemaRefToName, toIdentifierPascalCase, toPascalCase, valueToCode };
585
+ export declare function makeSecuritySchemesCode(components: Components, readonly: boolean): string;
586
+ //#endregion
package/dist/index.js CHANGED
@@ -12,25 +12,26 @@ async function parseOpenAPI(input) {
12
12
  try {
13
13
  if (typeof input === "string" && input.endsWith(".tsp")) {
14
14
  const program = await compile(NodeHost, path.resolve(input), { noEmit: true });
15
- if (program.diagnostics.length) return {
15
+ if (program.diagnostics.length > 0) return {
16
16
  ok: false,
17
17
  error: `TypeSpec compile failed:\n${program.diagnostics.map((d) => d.message).join("\n")}`
18
18
  };
19
19
  const [record] = await getOpenAPI3(program);
20
20
  const tsp = "document" in record ? record.document : record.versions[0].document;
21
+ const document = JSON.parse(JSON.stringify(tsp));
21
22
  return {
22
23
  ok: true,
23
- value: await SwaggerParser.bundle(JSON.parse(JSON.stringify(tsp)))
24
+ value: await SwaggerParser.bundle(document)
24
25
  };
25
26
  }
26
27
  return {
27
28
  ok: true,
28
29
  value: await SwaggerParser.bundle(input)
29
30
  };
30
- } catch (e) {
31
+ } catch (error) {
31
32
  return {
32
33
  ok: false,
33
- error: e instanceof Error ? e.message : String(e)
34
+ error: error instanceof Error ? error.message : String(error)
34
35
  };
35
36
  }
36
37
  }
@@ -47,21 +48,30 @@ function toJsonSchema(schema) {
47
48
  /** Pull the bare expression out of a `export const X = <expr>` wrapper, then strip cross-schema refs. */
48
49
  function extractExpr(code, stripRefs = (s) => s) {
49
50
  const joined = code.split("\n").filter((line) => !line.startsWith("import ")).join("\n").trim();
50
- const expr = joined.match(/^export const \w+ = (.+)$/s)?.[1];
51
- if (expr !== void 0) return stripRefs(expr.replace(/;?\s*$/, ""));
51
+ const expr = joined.match(/^export const \w+ = (.+)$/su)?.[1];
52
+ if (expr !== void 0) return stripRefs(expr.replace(/;?\s*$/u, ""));
52
53
  return stripRefs(joined);
53
54
  }
55
+ /** One factory per library; the mapped type makes a missing library a compile error. */
56
+ const ADAPTERS = {
57
+ zod: makeZodAdapter,
58
+ valibot: makeValibotAdapter,
59
+ arktype: makeArktypeAdapter,
60
+ typebox: makeTypeboxAdapter,
61
+ effect: makeEffectAdapter
62
+ };
54
63
  function makeAdapter(lib) {
55
- switch (lib) {
56
- case "zod": return makeZodAdapter();
57
- case "valibot": return makeValibotAdapter();
58
- case "arktype": return makeArktypeAdapter();
59
- case "typebox": return makeTypeboxAdapter();
60
- case "effect": return makeEffectAdapter();
61
- }
64
+ return ADAPTERS[lib]();
65
+ }
66
+ /** Inline `z.lazy(() => XSchema)` back to the bare `XSchema` reference. */
67
+ function stripZodLazy(code) {
68
+ return code.replaceAll(/z\.lazy\(\(\)\s*=>\s*(\w+Schema)\)/gu, "$1");
69
+ }
70
+ /** Inline `v.lazy(() => XSchema)` back to the bare `XSchema` reference. */
71
+ function stripValibotLazy(code) {
72
+ return code.replaceAll(/v\.lazy\(\(\)\s*=>\s*(\w+Schema)\)/gu, "$1");
62
73
  }
63
74
  function makeZodAdapter() {
64
- const stripLazy = (code) => code.replace(/z\.lazy\(\(\)\s*=>\s*(\w+Schema)\)/g, "$1");
65
75
  return {
66
76
  toExpression(schema, paramIn) {
67
77
  return extractExpr(schemaToZod(toJsonSchema(schema), {
@@ -69,7 +79,7 @@ function makeZodAdapter() {
69
79
  openapi: true,
70
80
  readonly: false,
71
81
  ...paramIn && { paramIn }
72
- }), stripLazy);
82
+ }), stripZodLazy);
73
83
  },
74
84
  renderImport() {
75
85
  return "import * as z from 'zod'";
@@ -80,7 +90,6 @@ function makeZodAdapter() {
80
90
  };
81
91
  }
82
92
  function makeValibotAdapter() {
83
- const stripLazy = (code) => code.replace(/v\.lazy\(\(\)\s*=>\s*(\w+Schema)\)/g, "$1");
84
93
  return {
85
94
  toExpression(schema, paramIn) {
86
95
  return extractExpr(schemaToValibot(toJsonSchema(schema), {
@@ -88,7 +97,7 @@ function makeValibotAdapter() {
88
97
  openapi: true,
89
98
  readonly: false,
90
99
  ...paramIn && { paramIn }
91
- }), stripLazy);
100
+ }), stripValibotLazy);
92
101
  },
93
102
  renderImport() {
94
103
  return "import * as v from 'valibot'";
@@ -155,7 +164,7 @@ function makeEffectAdapter() {
155
164
  //#endregion
156
165
  //#region src/utils/index.ts
157
166
  function toPascalCase(str) {
158
- return str.replace(/[^a-zA-Z0-9]+(.)/g, (_, c) => c.toUpperCase()).replace(/^(.)/, (_, c) => c.toUpperCase());
167
+ return str.replaceAll(/[^a-zA-Z0-9]+(.)/gu, (_, c) => c.toUpperCase()).replace(/^(.)/u, (_, c) => c.toUpperCase());
159
168
  }
160
169
  /**
161
170
  * Decode percent-encoding, falling back to the raw input on malformed sequences
@@ -175,15 +184,14 @@ function safeDecode(value) {
175
184
  * are returned unchanged. Used for component lookup, not variable naming.
176
185
  */
177
186
  function schemaRefToName(ref) {
178
- const parts = ref.split("/");
179
- return safeDecode(parts[parts.length - 1] ?? "");
187
+ return safeDecode(ref.split("/").at(-1) ?? "");
180
188
  }
181
189
  /**
182
190
  * Encode non-ASCII characters as `u<hex codepoint>` so they survive identifier
183
191
  * normalization instead of collapsing every non-ASCII name to the same value.
184
192
  */
185
193
  function encodeNonAscii(name) {
186
- return Array.from(name).map((ch) => {
194
+ return [...name].map((ch) => {
187
195
  const cp = ch.codePointAt(0) ?? 0;
188
196
  return cp > 127 ? `u${cp.toString(16)}` : ch;
189
197
  }).join("");
@@ -195,10 +203,10 @@ function encodeNonAscii(name) {
195
203
  * injectively so distinct names never collide.
196
204
  */
197
205
  function toIdentifierPascalCase(name) {
198
- const parts = encodeNonAscii(name).split(/[^a-zA-Z0-9]+/).filter(Boolean);
206
+ const parts = encodeNonAscii(name).split(/[^a-zA-Z0-9]+/u).filter(Boolean);
199
207
  if (parts.length === 0) return "Schema";
200
208
  const result = parts.map((part) => part.charAt(0).toUpperCase() + part.slice(1)).join("");
201
- if (/^[0-9]/.test(result)) return `_${result}`.replace(/([0-9])([a-z])/, (_, d, c) => `${d}${c.toUpperCase()}`);
209
+ if (/^[0-9]/u.test(result)) return `_${result}`.replace(/([0-9])([a-z])/u, (_, d, c) => `${d}${c.toUpperCase()}`);
202
210
  return result;
203
211
  }
204
212
  /**
@@ -207,7 +215,7 @@ function toIdentifierPascalCase(name) {
207
215
  * component schema. Shared by ref-resolver and schema-replacements.
208
216
  */
209
217
  function makeSchemaVarName(ref) {
210
- const name = ref.match(/^#\/components\/schemas\/(.+)$/)?.[1];
218
+ const name = ref.match(/^#\/components\/schemas\/(.+)$/u)?.[1];
211
219
  if (name === void 0) return void 0;
212
220
  return `${toIdentifierPascalCase(safeDecode(name))}Schema`;
213
221
  }
@@ -217,7 +225,7 @@ function makeSchemaVarName(ref) {
217
225
  * keys (e.g. `X-Request-ID`) emit as valid TypeScript.
218
226
  */
219
227
  function makeSafeKey(key) {
220
- return /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(key) ? key : JSON.stringify(key);
228
+ return /^[A-Za-z_$][A-Za-z0-9_$]*$/u.test(key) ? key : JSON.stringify(key);
221
229
  }
222
230
  /** Narrow an unknown value to a plain object (excludes arrays and null). */
223
231
  function isRecord(v) {
@@ -252,7 +260,7 @@ function encodeValue(value, codeReplacements, seen) {
252
260
  }
253
261
  seen.add(value);
254
262
  const entries = Object.entries(value).map(([k, v]) => {
255
- return `${/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(k) ? k : JSON.stringify(k)}:${encodeValue(v, codeReplacements, seen)}`;
263
+ return `${/^[a-zA-Z_$][a-zA-Z0-9_$]*$/u.test(k) ? k : JSON.stringify(k)}:${encodeValue(v, codeReplacements, seen)}`;
256
264
  });
257
265
  seen.delete(value);
258
266
  return `{${entries.join(",")}}`;
package/package.json CHANGED
@@ -1,11 +1,26 @@
1
1
  {
2
2
  "name": "oas-truth",
3
- "version": "0.0.1",
4
- "description": "Read OpenAPI / TypeSpec as the single source of truth and get a typed OpenAPI document back.",
3
+ "version": "0.0.3",
4
+ "description": "oas-truth is a parser from OpenAPI and TypeSpec to a typed OpenAPI document",
5
+ "keywords": [
6
+ "openapi",
7
+ "typespec"
8
+ ],
9
+ "homepage": "https://github.com/nakita628/oas-truth",
10
+ "bugs": {
11
+ "url": "https://github.com/nakita628/oas-truth/issues"
12
+ },
13
+ "license": "MIT",
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "git+https://github.com/nakita628/oas-truth.git",
17
+ "directory": "packages/oas-truth"
18
+ },
5
19
  "files": [
6
20
  "dist"
7
21
  ],
8
22
  "type": "module",
23
+ "sideEffects": false,
9
24
  "exports": {
10
25
  ".": {
11
26
  "types": "./dist/index.d.ts",
@@ -13,25 +28,28 @@
13
28
  }
14
29
  },
15
30
  "dependencies": {
16
- "schema-to-library": "^0.3.5"
31
+ "schema-to-library": "^0.4.0"
17
32
  },
18
33
  "devDependencies": {
19
- "@apidevtools/swagger-parser": "^12.1.0",
20
- "@types/node": "^25.9.3",
21
- "@typespec/compiler": "^1.13.0",
22
- "@typespec/http": "^1.13.0",
23
- "@typespec/openapi3": "^1.13.0",
24
- "@typespec/rest": "^0.83.0",
25
- "@typespec/versioning": "^0.83.0",
26
- "tsdown": "^0.22.2",
27
- "typescript": "^6.0.3"
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
+ "typescript": "^7.0.2"
28
43
  },
29
44
  "peerDependencies": {
30
- "@apidevtools/swagger-parser": ">=12.0.0 <13.0.0",
45
+ "@apidevtools/swagger-parser": ">=12.0.0 <14.0.0",
31
46
  "@typespec/compiler": ">=1.11.0 <2.0.0",
32
47
  "@typespec/openapi3": ">=1.11.0 <2.0.0"
33
48
  },
34
49
  "scripts": {
35
- "build": "tsdown"
50
+ "build": "vp pack",
51
+ "check": "vp check",
52
+ "fix": "vp check --fix",
53
+ "test": "vp test"
36
54
  }
37
55
  }