@lssm/lib.contracts-transformers 0.0.0-canary-20251217083314 → 1.41.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.
@@ -1,201 +1,4 @@
1
- import { toCamelCase, toPascalCase, toValidIdentifier } from "../common/utils.js";
2
-
3
- //#region src/openapi/schema-converter.ts
4
- /**
5
- * Map JSON Schema types to ContractSpec ScalarTypeEnum values.
6
- */
7
- const JSON_SCHEMA_TO_SCALAR = {
8
- string: "ScalarTypeEnum.STRING",
9
- integer: "ScalarTypeEnum.INT",
10
- number: "ScalarTypeEnum.FLOAT",
11
- boolean: "ScalarTypeEnum.BOOLEAN",
12
- "string:date": "ScalarTypeEnum.DATE",
13
- "string:date-time": "ScalarTypeEnum.DATE_TIME",
14
- "string:email": "ScalarTypeEnum.EMAIL",
15
- "string:uri": "ScalarTypeEnum.URL",
16
- "string:uuid": "ScalarTypeEnum.ID"
17
- };
18
- /**
19
- * Check if a schema is a reference object.
20
- */
21
- function isReference(schema) {
22
- return "$ref" in schema;
23
- }
24
- /**
25
- * Extract type name from a $ref.
26
- */
27
- function typeNameFromRef(ref) {
28
- const parts = ref.split("/");
29
- return parts[parts.length - 1] ?? "Unknown";
30
- }
31
- /**
32
- * Convert a JSON Schema to a TypeScript type representation.
33
- */
34
- function jsonSchemaToType(schema, name) {
35
- if (isReference(schema)) return {
36
- type: toPascalCase(typeNameFromRef(schema.$ref)),
37
- optional: false,
38
- array: false,
39
- primitive: false
40
- };
41
- const schemaObj = schema;
42
- const type = schemaObj["type"];
43
- const format = schemaObj["format"];
44
- const nullable = schemaObj["nullable"];
45
- if (type === "array") {
46
- const items = schemaObj["items"];
47
- if (items) return {
48
- ...jsonSchemaToType(items, name),
49
- array: true,
50
- optional: nullable ?? false
51
- };
52
- return {
53
- type: "unknown",
54
- optional: nullable ?? false,
55
- array: true,
56
- primitive: false
57
- };
58
- }
59
- if (type === "object" || schemaObj["properties"]) return {
60
- type: name ? toPascalCase(name) : "Record<string, unknown>",
61
- optional: nullable ?? false,
62
- array: false,
63
- primitive: false
64
- };
65
- if (schemaObj["enum"]) return {
66
- type: name ? toPascalCase(name) : "string",
67
- optional: nullable ?? false,
68
- array: false,
69
- primitive: false
70
- };
71
- format && `${type}${format}`;
72
- if (type === "string") return {
73
- type: "string",
74
- optional: nullable ?? false,
75
- array: false,
76
- primitive: true
77
- };
78
- if (type === "integer" || type === "number") return {
79
- type: "number",
80
- optional: nullable ?? false,
81
- array: false,
82
- primitive: true
83
- };
84
- if (type === "boolean") return {
85
- type: "boolean",
86
- optional: nullable ?? false,
87
- array: false,
88
- primitive: true
89
- };
90
- return {
91
- type: "unknown",
92
- optional: nullable ?? false,
93
- array: false,
94
- primitive: false
95
- };
96
- }
97
- /**
98
- * Get the ScalarTypeEnum value for a JSON Schema type.
99
- */
100
- function getScalarType(schema) {
101
- if (isReference(schema)) return;
102
- const schemaObj = schema;
103
- const type = schemaObj["type"];
104
- const format = schemaObj["format"];
105
- if (!type) return void 0;
106
- return JSON_SCHEMA_TO_SCALAR[format ? `${type}:${format}` : type] ?? JSON_SCHEMA_TO_SCALAR[type];
107
- }
108
- /**
109
- * Convert a JSON Schema to a SchemaModel field definition.
110
- */
111
- function jsonSchemaToField(schema, fieldName, required) {
112
- const type = jsonSchemaToType(schema, fieldName);
113
- const scalarType = getScalarType(schema);
114
- let enumValues;
115
- if (!isReference(schema)) {
116
- const enumArr = schema["enum"];
117
- if (enumArr) enumValues = enumArr.map(String);
118
- }
119
- return {
120
- name: toValidIdentifier(toCamelCase(fieldName)),
121
- type: {
122
- ...type,
123
- optional: !required || type.optional,
124
- description: !isReference(schema) ? schema["description"] : void 0
125
- },
126
- scalarType,
127
- enumValues
128
- };
129
- }
130
- /**
131
- * Generate SchemaModel TypeScript code for a JSON Schema object.
132
- */
133
- function generateSchemaModelCode(schema, modelName, indent = 0) {
134
- const spaces = " ".repeat(indent);
135
- const fields = [];
136
- let description;
137
- if (isReference(schema)) return {
138
- name: toPascalCase(typeNameFromRef(schema.$ref)),
139
- fields: [],
140
- code: `// Reference to ${schema.$ref}`
141
- };
142
- const schemaObj = schema;
143
- description = schemaObj["description"];
144
- const properties = schemaObj["properties"];
145
- const required = schemaObj["required"] ?? [];
146
- if (!properties) return {
147
- name: toPascalCase(modelName),
148
- description,
149
- fields: [],
150
- code: `${spaces}// Empty schema for ${modelName}`
151
- };
152
- for (const [propName, propSchema] of Object.entries(properties)) {
153
- const isRequired = required.includes(propName);
154
- fields.push(jsonSchemaToField(propSchema, propName, isRequired));
155
- }
156
- const lines = [];
157
- const safeModelName = toPascalCase(toValidIdentifier(modelName));
158
- lines.push(`${spaces}export const ${safeModelName} = defineSchemaModel({`);
159
- lines.push(`${spaces} name: '${safeModelName}',`);
160
- if (description) lines.push(`${spaces} description: ${JSON.stringify(description)},`);
161
- lines.push(`${spaces} fields: {`);
162
- for (const field of fields) {
163
- const fieldLines = generateFieldCode(field, indent + 2);
164
- lines.push(fieldLines);
165
- }
166
- lines.push(`${spaces} },`);
167
- lines.push(`${spaces}});`);
168
- return {
169
- name: safeModelName,
170
- description,
171
- fields,
172
- code: lines.join("\n")
173
- };
174
- }
175
- /**
176
- * Generate TypeScript code for a single field.
177
- */
178
- function generateFieldCode(field, indent) {
179
- const spaces = " ".repeat(indent);
180
- const lines = [];
181
- lines.push(`${spaces}${field.name}: {`);
182
- if (field.enumValues) lines.push(`${spaces} type: new EnumType([${field.enumValues.map((v) => `'${v}'`).join(", ")}]),`);
183
- else if (field.scalarType) lines.push(`${spaces} type: ${field.scalarType},`);
184
- else lines.push(`${spaces} type: ${field.type.type}, // TODO: Define or import this type`);
185
- if (field.type.optional) lines.push(`${spaces} isOptional: true,`);
186
- if (field.type.array) lines.push(`${spaces} isArray: true,`);
187
- lines.push(`${spaces}},`);
188
- return lines.join("\n");
189
- }
190
- /**
191
- * Generate import statements for a SchemaModel.
192
- */
193
- function generateImports(fields) {
194
- const imports = /* @__PURE__ */ new Set();
195
- imports.add("import { defineSchemaModel, ScalarTypeEnum, EnumType } from '@lssm/lib.schema';");
196
- for (const field of fields) if (!field.type.primitive && !field.enumValues && !field.scalarType) {}
197
- return Array.from(imports).join("\n");
198
- }
199
-
200
- //#endregion
201
- export { generateImports, generateSchemaModelCode, getScalarType, jsonSchemaToField, jsonSchemaToType };
1
+ import{toCamelCase as e,toPascalCase as t,toValidIdentifier as n}from"../common/utils.js";const r={string:`ScalarTypeEnum.STRING`,integer:`ScalarTypeEnum.INT`,number:`ScalarTypeEnum.FLOAT`,boolean:`ScalarTypeEnum.BOOLEAN`,"string:date":`ScalarTypeEnum.DATE`,"string:date-time":`ScalarTypeEnum.DATE_TIME`,"string:email":`ScalarTypeEnum.EMAIL`,"string:uri":`ScalarTypeEnum.URL`,"string:uuid":`ScalarTypeEnum.ID`};function i(e){return`$ref`in e}function a(e){let t=e.split(`/`);return t[t.length-1]??`Unknown`}function o(e,n){if(i(e))return{type:t(a(e.$ref)),optional:!1,array:!1,primitive:!1};let r=e,s=r.type,c=r.format,l=r.nullable;if(s===`array`){let e=r.items;return e?{...o(e,n),array:!0,optional:l??!1}:{type:`unknown`,optional:l??!1,array:!0,primitive:!1}}return s===`object`||r.properties?{type:n?t(n):`Record<string, unknown>`,optional:l??!1,array:!1,primitive:!1}:r.enum?{type:n?t(n):`string`,optional:l??!1,array:!1,primitive:!1}:(c&&`${s}${c}`,s===`string`?{type:`string`,optional:l??!1,array:!1,primitive:!0}:s===`integer`||s===`number`?{type:`number`,optional:l??!1,array:!1,primitive:!0}:s===`boolean`?{type:`boolean`,optional:l??!1,array:!1,primitive:!0}:{type:`unknown`,optional:l??!1,array:!1,primitive:!1})}function s(e){if(i(e))return;let t=e,n=t.type,a=t.format;if(n)return r[a?`${n}:${a}`:n]??r[n]}function c(t,r,a){let c=o(t,r),l=s(t),u;if(!i(t)){let e=t.enum;e&&(u=e.map(String))}return{name:n(e(r)),type:{...c,optional:!a||c.optional,description:i(t)?void 0:t.description},scalarType:l,enumValues:u}}function l(e,r,o=0){let s=` `.repeat(o),l=[],d;if(i(e))return{name:t(a(e.$ref)),fields:[],code:`// Reference to ${e.$ref}`};let f=e;d=f.description;let p=f.properties,m=f.required??[];if(!p)return{name:t(r),description:d,fields:[],code:`${s}// Empty schema for ${r}`};for(let[e,t]of Object.entries(p)){let n=m.includes(e);l.push(c(t,e,n))}let h=[],g=t(n(r));h.push(`${s}export const ${g} = defineSchemaModel({`),h.push(`${s} name: '${g}',`),d&&h.push(`${s} description: ${JSON.stringify(d)},`),h.push(`${s} fields: {`);for(let e of l){let t=u(e,o+2);h.push(t)}return h.push(`${s} },`),h.push(`${s}});`),{name:g,description:d,fields:l,code:h.join(`
2
+ `)}}function u(e,t){let n=` `.repeat(t),r=[];return r.push(`${n}${e.name}: {`),e.enumValues?r.push(`${n} type: new EnumType([${e.enumValues.map(e=>`'${e}'`).join(`, `)}]),`):e.scalarType?r.push(`${n} type: ${e.scalarType},`):r.push(`${n} type: ${e.type.type}, // TODO: Define or import this type`),e.type.optional&&r.push(`${n} isOptional: true,`),e.type.array&&r.push(`${n} isArray: true,`),r.push(`${n}},`),r.join(`
3
+ `)}function d(e){let t=new Set;t.add(`import { defineSchemaModel, ScalarTypeEnum, EnumType } from '@lssm/lib.schema';`);for(let t of e)!t.type.primitive&&!t.enumValues&&t.scalarType;return Array.from(t).join(`
4
+ `)}export{d as generateImports,l as generateSchemaModelCode,s as getScalarType,c as jsonSchemaToField,o as jsonSchemaToType};
package/package.json CHANGED
@@ -1,11 +1,10 @@
1
1
  {
2
2
  "name": "@lssm/lib.contracts-transformers",
3
- "version": "0.0.0-canary-20251217083314",
3
+ "version": "1.41.0",
4
4
  "description": "Contract format transformations: import/export between ContractSpec and external formats (OpenAPI, AsyncAPI, etc.)",
5
5
  "type": "module",
6
6
  "scripts": {
7
7
  "publish:pkg": "bun publish --tolerate-republish --ignore-scripts --verbose",
8
- "publish:pkg:canary": "bun publish:pkg --tag canary",
9
8
  "build": "bun build:bundle && bun build:types",
10
9
  "build:bundle": "tsdown",
11
10
  "build:types": "tsc --noEmit",
@@ -17,15 +16,15 @@
17
16
  "test": "bun test"
18
17
  },
19
18
  "dependencies": {
20
- "@lssm/lib.contracts": "0.0.0-canary-20251217083314",
21
- "@lssm/lib.schema": "0.0.0-canary-20251217083314",
19
+ "@lssm/lib.contracts": "workspace:*",
20
+ "@lssm/lib.schema": "workspace:*",
22
21
  "openapi-types": "^12.1.3",
23
22
  "yaml": "^2.7.1",
24
23
  "zod": "^4.1.13"
25
24
  },
26
25
  "devDependencies": {
27
- "@lssm/tool.tsdown": "0.0.0-canary-20251217083314",
28
- "@lssm/tool.typescript": "0.0.0-canary-20251217083314",
26
+ "@lssm/tool.tsdown": "workspace:*",
27
+ "@lssm/tool.typescript": "workspace:*",
29
28
  "tsdown": "^0.17.4",
30
29
  "typescript": "^5.9.3"
31
30
  },
@@ -37,9 +36,9 @@
37
36
  ],
38
37
  "module": "./dist/index.js",
39
38
  "exports": {
40
- ".": "./dist/index.js",
41
- "./common": "./dist/common/index.js",
42
- "./openapi": "./dist/openapi/index.js",
39
+ ".": "./src/index.ts",
40
+ "./common": "./src/common/index.ts",
41
+ "./openapi": "./src/openapi/index.ts",
43
42
  "./*": "./*"
44
43
  },
45
44
  "publishConfig": {
@@ -1,3 +0,0 @@
1
- import { DiffChange, DiffChangeType, ImportResult, ImportedSpec, SpecDiff, SpecSource, SyncResult, TransportHints, ValidationResult } from "./types.js";
2
- import { deepEqual, extractPathParams, getByPath, normalizePath, toCamelCase, toFileName, toKebabCase, toPascalCase, toSnakeCase, toSpecName, toValidIdentifier } from "./utils.js";
3
- export { DiffChange, DiffChangeType, ImportResult, ImportedSpec, SpecDiff, SpecSource, SyncResult, TransportHints, ValidationResult, deepEqual, extractPathParams, getByPath, normalizePath, toCamelCase, toFileName, toKebabCase, toPascalCase, toSnakeCase, toSpecName, toValidIdentifier };
@@ -1,152 +0,0 @@
1
- import { AnyContractSpec } from "@lssm/lib.contracts";
2
-
3
- //#region src/common/types.d.ts
4
-
5
- /**
6
- * Source information for imported specs.
7
- */
8
- interface SpecSource {
9
- /** The format the spec was imported from */
10
- type: 'openapi' | 'asyncapi' | 'graphql' | 'protobuf';
11
- /** URL if fetched from remote */
12
- url?: string;
13
- /** File path if loaded from local file */
14
- file?: string;
15
- /** Original identifier in source format */
16
- sourceId: string;
17
- /** Timestamp of import */
18
- importedAt: Date;
19
- }
20
- /**
21
- * Transport hints preserved from external formats.
22
- * These enable accurate round-trip transformations.
23
- */
24
- interface TransportHints {
25
- rest?: {
26
- method: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'HEAD' | 'OPTIONS';
27
- path: string;
28
- params?: {
29
- path?: string[];
30
- query?: string[];
31
- header?: string[];
32
- cookie?: string[];
33
- };
34
- };
35
- graphql?: {
36
- type: 'query' | 'mutation' | 'subscription';
37
- fieldName: string;
38
- };
39
- }
40
- /**
41
- * Result of importing a single spec from an external format.
42
- */
43
- interface ImportedSpec {
44
- /** The generated ContractSpec */
45
- spec: AnyContractSpec;
46
- /** Generated TypeScript code for the spec */
47
- code: string;
48
- /** Suggested file name for the spec */
49
- fileName: string;
50
- /** Source information for provenance tracking */
51
- source: SpecSource;
52
- /** Transport hints for accurate round-trips */
53
- transportHints: TransportHints;
54
- }
55
- /**
56
- * Result of an import operation.
57
- */
58
- interface ImportResult {
59
- /** Successfully imported specs */
60
- specs: ImportedSpec[];
61
- /** Specs that were skipped (e.g., unsupported features) */
62
- skipped: Array<{
63
- sourceId: string;
64
- reason: string;
65
- }>;
66
- /** Errors encountered during import */
67
- errors: Array<{
68
- sourceId: string;
69
- error: string;
70
- }>;
71
- /** Summary statistics */
72
- summary: {
73
- total: number;
74
- imported: number;
75
- skipped: number;
76
- errors: number;
77
- };
78
- }
79
- /**
80
- * Type of change detected during diff.
81
- */
82
- type DiffChangeType = 'added' | 'removed' | 'modified' | 'type_changed' | 'required_changed';
83
- /**
84
- * A single change detected during diff.
85
- */
86
- interface DiffChange {
87
- /** JSON path to the changed property */
88
- path: string;
89
- /** Type of change */
90
- type: DiffChangeType;
91
- /** Previous value (for modified/removed) */
92
- oldValue?: unknown;
93
- /** New value (for modified/added) */
94
- newValue?: unknown;
95
- /** Human-readable description of the change */
96
- description: string;
97
- }
98
- /**
99
- * Result of diffing two specs.
100
- */
101
- interface SpecDiff {
102
- /** Identifier for the operation */
103
- operationId: string;
104
- /** Existing ContractSpec (if any) */
105
- existing?: AnyContractSpec;
106
- /** Incoming imported spec */
107
- incoming: ImportedSpec;
108
- /** List of detected changes */
109
- changes: DiffChange[];
110
- /** Whether specs are semantically equivalent */
111
- isEquivalent: boolean;
112
- /** User's resolution choice (for interactive sync) */
113
- resolution?: 'keep' | 'replace' | 'merge' | 'skip';
114
- }
115
- /**
116
- * Result of a sync operation.
117
- */
118
- interface SyncResult {
119
- /** Specs that were added (new imports) */
120
- added: ImportedSpec[];
121
- /** Specs that were updated */
122
- updated: Array<{
123
- spec: ImportedSpec;
124
- changes: DiffChange[];
125
- }>;
126
- /** Specs that were kept unchanged */
127
- unchanged: string[];
128
- /** Specs that had conflicts requiring resolution */
129
- conflicts: SpecDiff[];
130
- /** Summary statistics */
131
- summary: {
132
- added: number;
133
- updated: number;
134
- unchanged: number;
135
- conflicts: number;
136
- };
137
- }
138
- /**
139
- * Validation result for a single spec.
140
- */
141
- interface ValidationResult {
142
- /** Whether the spec is valid against the source */
143
- valid: boolean;
144
- /** Detected differences */
145
- diffs: DiffChange[];
146
- /** Validation errors */
147
- errors: string[];
148
- /** Validation warnings */
149
- warnings: string[];
150
- }
151
- //#endregion
152
- export { DiffChange, DiffChangeType, ImportResult, ImportedSpec, SpecDiff, SpecSource, SyncResult, TransportHints, ValidationResult };
@@ -1,51 +0,0 @@
1
- //#region src/common/utils.d.ts
2
- /**
3
- * Common utilities for contract transformations.
4
- */
5
- /**
6
- * Convert a string to PascalCase.
7
- */
8
- declare function toPascalCase(str: string): string;
9
- /**
10
- * Convert a string to camelCase.
11
- */
12
- declare function toCamelCase(str: string): string;
13
- /**
14
- * Convert a string to kebab-case.
15
- */
16
- declare function toKebabCase(str: string): string;
17
- /**
18
- * Convert a string to snake_case.
19
- */
20
- declare function toSnakeCase(str: string): string;
21
- /**
22
- * Sanitize a string to be a valid TypeScript identifier.
23
- */
24
- declare function toValidIdentifier(str: string): string;
25
- /**
26
- * Generate a ContractSpec name from an operation identifier.
27
- */
28
- declare function toSpecName(operationId: string, prefix?: string): string;
29
- /**
30
- * Generate a file name from a spec name.
31
- */
32
- declare function toFileName(specName: string): string;
33
- /**
34
- * Deep equality check for objects.
35
- */
36
- declare function deepEqual(a: unknown, b: unknown): boolean;
37
- /**
38
- * Get a value from an object by JSON path.
39
- */
40
- declare function getByPath(obj: unknown, path: string): unknown;
41
- /**
42
- * Extract path parameters from a URL path template.
43
- * e.g., "/users/{userId}/orders/{orderId}" -> ["userId", "orderId"]
44
- */
45
- declare function extractPathParams(path: string): string[];
46
- /**
47
- * Normalize a URL path for comparison.
48
- */
49
- declare function normalizePath(path: string): string;
50
- //#endregion
51
- export { deepEqual, extractPathParams, getByPath, normalizePath, toCamelCase, toFileName, toKebabCase, toPascalCase, toSnakeCase, toSpecName, toValidIdentifier };
package/dist/index.d.ts DELETED
@@ -1,9 +0,0 @@
1
- import { DiffChange, DiffChangeType, ImportResult, ImportedSpec, SpecDiff, SpecSource, SyncResult, TransportHints, ValidationResult } from "./common/types.js";
2
- import { deepEqual, extractPathParams, getByPath, normalizePath, toCamelCase, toFileName, toKebabCase, toPascalCase, toSnakeCase, toSpecName, toValidIdentifier } from "./common/utils.js";
3
- import { ContractSpecOpenApiDocument, HttpMethod, OpenApiDocument, OpenApiExportOptions, OpenApiImportOptions, OpenApiOperation, OpenApiParameter, OpenApiParseOptions, OpenApiSchema, OpenApiServer, OpenApiSource, OpenApiTransportHints, OpenApiVersion, ParameterLocation, ParseResult, ParsedOperation, ParsedParameter } from "./openapi/types.js";
4
- import { detectFormat, detectVersion, parseOpenApi, parseOpenApiDocument, parseOpenApiString } from "./openapi/parser.js";
5
- import { defaultRestPath, openApiForRegistry, openApiToJson, openApiToYaml } from "./openapi/exporter.js";
6
- import { importFromOpenApi, importOperation } from "./openapi/importer.js";
7
- import { GeneratedModel, SchemaField, TypescriptType, generateImports, generateSchemaModelCode, getScalarType, jsonSchemaToField, jsonSchemaToType } from "./openapi/schema-converter.js";
8
- import { DiffOptions, createSpecDiff, diffAll, diffSpecVsOperation, diffSpecs, formatDiffChanges } from "./openapi/differ.js";
9
- export { ContractSpecOpenApiDocument, DiffChange, DiffChangeType, DiffOptions, GeneratedModel, HttpMethod, ImportResult, ImportedSpec, OpenApiDocument, OpenApiExportOptions, OpenApiImportOptions, OpenApiOperation, OpenApiParameter, OpenApiParseOptions, OpenApiSchema, OpenApiServer, OpenApiSource, OpenApiTransportHints, OpenApiVersion, ParameterLocation, ParseResult, ParsedOperation, ParsedParameter, SchemaField, SpecDiff, SpecSource, SyncResult, TransportHints, TypescriptType, ValidationResult, createSpecDiff, deepEqual, defaultRestPath, detectFormat, detectVersion, diffAll, diffSpecVsOperation, diffSpecs, extractPathParams, formatDiffChanges, generateImports, generateSchemaModelCode, getByPath, getScalarType, importFromOpenApi, importOperation, jsonSchemaToField, jsonSchemaToType, normalizePath, openApiForRegistry, openApiToJson, openApiToYaml, parseOpenApi, parseOpenApiDocument, parseOpenApiString, toCamelCase, toFileName, toKebabCase, toPascalCase, toSnakeCase, toSpecName, toValidIdentifier };
@@ -1,41 +0,0 @@
1
- import { DiffChange, ImportedSpec, SpecDiff } from "../common/types.js";
2
- import { ParsedOperation } from "./types.js";
3
- import { AnyContractSpec } from "@lssm/lib.contracts";
4
-
5
- //#region src/openapi/differ.d.ts
6
-
7
- /**
8
- * Options for diffing specs.
9
- */
10
- interface DiffOptions {
11
- /** Ignore description changes */
12
- ignoreDescriptions?: boolean;
13
- /** Ignore tag changes */
14
- ignoreTags?: boolean;
15
- /** Ignore transport changes (path, method) */
16
- ignoreTransport?: boolean;
17
- /** Custom paths to ignore */
18
- ignorePaths?: string[];
19
- }
20
- /**
21
- * Diff a ContractSpec against an OpenAPI operation.
22
- */
23
- declare function diffSpecVsOperation(spec: AnyContractSpec, operation: ParsedOperation, options?: DiffOptions): DiffChange[];
24
- /**
25
- * Diff two ContractSpecs.
26
- */
27
- declare function diffSpecs(oldSpec: AnyContractSpec, newSpec: AnyContractSpec, options?: DiffOptions): DiffChange[];
28
- /**
29
- * Create a SpecDiff from an existing spec and an imported spec.
30
- */
31
- declare function createSpecDiff(operationId: string, existing: AnyContractSpec | undefined, incoming: ImportedSpec, options?: DiffOptions): SpecDiff;
32
- /**
33
- * Batch diff multiple specs against OpenAPI operations.
34
- */
35
- declare function diffAll(existingSpecs: Map<string, AnyContractSpec>, importedSpecs: ImportedSpec[], options?: DiffOptions): SpecDiff[];
36
- /**
37
- * Format diff changes for display.
38
- */
39
- declare function formatDiffChanges(changes: DiffChange[]): string;
40
- //#endregion
41
- export { DiffOptions, createSpecDiff, diffAll, diffSpecVsOperation, diffSpecs, formatDiffChanges };
@@ -1,27 +0,0 @@
1
- import { ContractSpecOpenApiDocument, OpenApiExportOptions, OpenApiServer } from "./types.js";
2
- import { SpecRegistry } from "@lssm/lib.contracts";
3
-
4
- //#region src/openapi/exporter.d.ts
5
-
6
- /**
7
- * Generate default REST path from spec name and version.
8
- */
9
- declare function defaultRestPath(name: string, version: number): string;
10
- /**
11
- * Export a SpecRegistry to an OpenAPI 3.1 document.
12
- *
13
- * @param registry - The SpecRegistry containing specs to export
14
- * @param options - Export options (title, version, description, servers)
15
- * @returns OpenAPI 3.1 document
16
- */
17
- declare function openApiForRegistry(registry: SpecRegistry, options?: OpenApiExportOptions): ContractSpecOpenApiDocument;
18
- /**
19
- * Export a SpecRegistry to OpenAPI JSON string.
20
- */
21
- declare function openApiToJson(registry: SpecRegistry, options?: OpenApiExportOptions): string;
22
- /**
23
- * Export a SpecRegistry to OpenAPI YAML string.
24
- */
25
- declare function openApiToYaml(registry: SpecRegistry, options?: OpenApiExportOptions): string;
26
- //#endregion
27
- export { defaultRestPath, openApiForRegistry, openApiToJson, openApiToYaml };
@@ -1,15 +0,0 @@
1
- import { ImportResult } from "../common/types.js";
2
- import { OpenApiImportOptions, ParseResult, ParsedOperation } from "./types.js";
3
-
4
- //#region src/openapi/importer.d.ts
5
-
6
- /**
7
- * Import operations from a parsed OpenAPI document.
8
- */
9
- declare function importFromOpenApi(parseResult: ParseResult, options?: OpenApiImportOptions): ImportResult;
10
- /**
11
- * Import a single operation to ContractSpec code.
12
- */
13
- declare function importOperation(operation: ParsedOperation, options?: OpenApiImportOptions): string;
14
- //#endregion
15
- export { importFromOpenApi, importOperation };
@@ -1,7 +0,0 @@
1
- import { ContractSpecOpenApiDocument, HttpMethod, OpenApiDocument, OpenApiExportOptions, OpenApiImportOptions, OpenApiOperation, OpenApiParameter, OpenApiParseOptions, OpenApiSchema, OpenApiServer, OpenApiSource, OpenApiTransportHints, OpenApiVersion, ParameterLocation, ParseResult, ParsedOperation, ParsedParameter } from "./types.js";
2
- import { detectFormat, detectVersion, parseOpenApi, parseOpenApiDocument, parseOpenApiString } from "./parser.js";
3
- import { defaultRestPath, openApiForRegistry, openApiToJson, openApiToYaml } from "./exporter.js";
4
- import { importFromOpenApi, importOperation } from "./importer.js";
5
- import { GeneratedModel, SchemaField, TypescriptType, generateImports, generateSchemaModelCode, getScalarType, jsonSchemaToField, jsonSchemaToType } from "./schema-converter.js";
6
- import { DiffOptions, createSpecDiff, diffAll, diffSpecVsOperation, diffSpecs, formatDiffChanges } from "./differ.js";
7
- export { type ContractSpecOpenApiDocument, type DiffOptions, type GeneratedModel, type HttpMethod, type OpenApiDocument, type OpenApiExportOptions, type OpenApiImportOptions, type OpenApiOperation, type OpenApiParameter, type OpenApiParseOptions, type OpenApiSchema, type OpenApiServer, type OpenApiSource, type OpenApiTransportHints, type OpenApiVersion, type ParameterLocation, type ParseResult, type ParsedOperation, type ParsedParameter, type SchemaField, type TypescriptType, createSpecDiff, defaultRestPath, detectFormat, detectVersion, diffAll, diffSpecVsOperation, diffSpecs, formatDiffChanges, generateImports, generateSchemaModelCode, getScalarType, importFromOpenApi, importOperation, jsonSchemaToField, jsonSchemaToType, openApiForRegistry, openApiToJson, openApiToYaml, parseOpenApi, parseOpenApiDocument, parseOpenApiString };
@@ -1,31 +0,0 @@
1
- import { OpenApiDocument, OpenApiParseOptions, OpenApiVersion, ParseResult } from "./types.js";
2
-
3
- //#region src/openapi/parser.d.ts
4
-
5
- /**
6
- * Parse an OpenAPI document from a string (JSON or YAML).
7
- */
8
- declare function parseOpenApiString(content: string, format?: 'json' | 'yaml'): OpenApiDocument;
9
- /**
10
- * Detect the format of content (JSON or YAML).
11
- */
12
- declare function detectFormat(content: string): 'json' | 'yaml';
13
- /**
14
- * Detect OpenAPI version from document.
15
- */
16
- declare function detectVersion(doc: OpenApiDocument): OpenApiVersion;
17
- /**
18
- * Parse an OpenAPI document into a structured result.
19
- */
20
- declare function parseOpenApiDocument(doc: OpenApiDocument, _options?: OpenApiParseOptions): ParseResult;
21
- /**
22
- * Parse OpenAPI from a file path or URL.
23
- * Note: This is an async function that requires I/O adapters.
24
- * For pure parsing, use parseOpenApiString or parseOpenApiDocument.
25
- */
26
- declare function parseOpenApi(source: string, options?: OpenApiParseOptions & {
27
- fetch?: typeof globalThis.fetch;
28
- readFile?: (path: string) => Promise<string>;
29
- }): Promise<ParseResult>;
30
- //#endregion
31
- export { detectFormat, detectVersion, parseOpenApi, parseOpenApiDocument, parseOpenApiString };
@@ -1,69 +0,0 @@
1
- import { OpenApiSchema } from "./types.js";
2
-
3
- //#region src/openapi/schema-converter.d.ts
4
-
5
- /**
6
- * TypeScript type representation for code generation.
7
- */
8
- interface TypescriptType {
9
- /** The type expression (e.g., "string", "number", "MyModel") */
10
- type: string;
11
- /** Whether the type is optional */
12
- optional: boolean;
13
- /** Whether the type is an array */
14
- array: boolean;
15
- /** Whether this is a primitive type */
16
- primitive: boolean;
17
- /** Description for documentation */
18
- description?: string;
19
- }
20
- /**
21
- * SchemaModel field representation for code generation.
22
- */
23
- interface SchemaField {
24
- /** Field name */
25
- name: string;
26
- /** Field type */
27
- type: TypescriptType;
28
- /** Scalar type enum value (for FieldType) */
29
- scalarType?: string;
30
- /** Enum values if this is an enum type */
31
- enumValues?: string[];
32
- /** Nested model if this is an object type */
33
- nestedModel?: GeneratedModel;
34
- }
35
- /**
36
- * Generated model representation.
37
- */
38
- interface GeneratedModel {
39
- /** Model name (PascalCase) */
40
- name: string;
41
- /** Model description */
42
- description?: string;
43
- /** Fields */
44
- fields: SchemaField[];
45
- /** Generated TypeScript code */
46
- code: string;
47
- }
48
- /**
49
- * Convert a JSON Schema to a TypeScript type representation.
50
- */
51
- declare function jsonSchemaToType(schema: OpenApiSchema, name?: string): TypescriptType;
52
- /**
53
- * Get the ScalarTypeEnum value for a JSON Schema type.
54
- */
55
- declare function getScalarType(schema: OpenApiSchema): string | undefined;
56
- /**
57
- * Convert a JSON Schema to a SchemaModel field definition.
58
- */
59
- declare function jsonSchemaToField(schema: OpenApiSchema, fieldName: string, required: boolean): SchemaField;
60
- /**
61
- * Generate SchemaModel TypeScript code for a JSON Schema object.
62
- */
63
- declare function generateSchemaModelCode(schema: OpenApiSchema, modelName: string, indent?: number): GeneratedModel;
64
- /**
65
- * Generate import statements for a SchemaModel.
66
- */
67
- declare function generateImports(fields: SchemaField[]): string;
68
- //#endregion
69
- export { GeneratedModel, SchemaField, TypescriptType, generateImports, generateSchemaModelCode, getScalarType, jsonSchemaToField, jsonSchemaToType };