@lssm/lib.contracts-transformers 0.0.0-canary-20251220041653 → 0.0.0-canary-20251221132705
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 +2 -2
- package/dist/common/index.d.ts +2 -2
- package/dist/common/types.d.ts +16 -10
- package/dist/common/types.d.ts.map +1 -1
- package/dist/index.d.ts +15 -6
- package/dist/index.js +13 -4
- package/dist/openapi/differ.d.ts +6 -6
- package/dist/openapi/differ.d.ts.map +1 -1
- package/dist/openapi/differ.js +11 -4
- package/dist/openapi/differ.js.map +1 -1
- package/dist/openapi/exporter/data-views.d.ts +38 -0
- package/dist/openapi/exporter/data-views.d.ts.map +1 -0
- package/dist/openapi/exporter/data-views.js +47 -0
- package/dist/openapi/exporter/data-views.js.map +1 -0
- package/dist/openapi/exporter/events.d.ts +28 -0
- package/dist/openapi/exporter/events.d.ts.map +1 -0
- package/dist/openapi/exporter/events.js +39 -0
- package/dist/openapi/exporter/events.js.map +1 -0
- package/dist/openapi/exporter/features.d.ts +37 -0
- package/dist/openapi/exporter/features.d.ts.map +1 -0
- package/dist/openapi/exporter/features.js +46 -0
- package/dist/openapi/exporter/features.js.map +1 -0
- package/dist/openapi/exporter/forms.d.ts +30 -0
- package/dist/openapi/exporter/forms.d.ts.map +1 -0
- package/dist/openapi/exporter/forms.js +49 -0
- package/dist/openapi/exporter/forms.js.map +1 -0
- package/dist/openapi/exporter/index.js +8 -0
- package/dist/openapi/exporter/operations.d.ts +65 -0
- package/dist/openapi/exporter/operations.d.ts.map +1 -0
- package/dist/openapi/exporter/operations.js +142 -0
- package/dist/openapi/exporter/operations.js.map +1 -0
- package/dist/openapi/exporter/presentations.d.ts +48 -0
- package/dist/openapi/exporter/presentations.d.ts.map +1 -0
- package/dist/openapi/exporter/presentations.js +66 -0
- package/dist/openapi/exporter/presentations.js.map +1 -0
- package/dist/openapi/exporter/registries.d.ts +23 -0
- package/dist/openapi/exporter/registries.d.ts.map +1 -0
- package/dist/openapi/exporter/registries.js +29 -0
- package/dist/openapi/exporter/registries.js.map +1 -0
- package/dist/openapi/exporter/workflows.d.ts +36 -0
- package/dist/openapi/exporter/workflows.d.ts.map +1 -0
- package/dist/openapi/exporter/workflows.js +54 -0
- package/dist/openapi/exporter/workflows.js.map +1 -0
- package/dist/openapi/exporter.d.ts +35 -15
- package/dist/openapi/exporter.d.ts.map +1 -1
- package/dist/openapi/exporter.js +78 -104
- package/dist/openapi/exporter.js.map +1 -1
- package/dist/openapi/importer/analyzer.js +28 -0
- package/dist/openapi/importer/analyzer.js.map +1 -0
- package/dist/openapi/importer/events.js +36 -0
- package/dist/openapi/importer/events.js.map +1 -0
- package/dist/openapi/importer/generator.js +71 -0
- package/dist/openapi/importer/generator.js.map +1 -0
- package/dist/openapi/importer/grouping.js +73 -0
- package/dist/openapi/importer/grouping.js.map +1 -0
- package/dist/openapi/importer/index.d.ts +17 -0
- package/dist/openapi/importer/index.d.ts.map +1 -0
- package/dist/openapi/importer/index.js +161 -0
- package/dist/openapi/importer/index.js.map +1 -0
- package/dist/openapi/importer/models.js +19 -0
- package/dist/openapi/importer/models.js.map +1 -0
- package/dist/openapi/importer/schemas.js +80 -0
- package/dist/openapi/importer/schemas.js.map +1 -0
- package/dist/openapi/index.d.ts +14 -5
- package/dist/openapi/index.js +15 -4
- package/dist/openapi/parser/document.d.ts +20 -0
- package/dist/openapi/parser/document.d.ts.map +1 -0
- package/dist/openapi/parser/document.js +95 -0
- package/dist/openapi/parser/document.js.map +1 -0
- package/dist/openapi/parser/index.js +5 -0
- package/dist/openapi/parser/operation.js +59 -0
- package/dist/openapi/parser/operation.js.map +1 -0
- package/dist/openapi/parser/parameters.js +37 -0
- package/dist/openapi/parser/parameters.js.map +1 -0
- package/dist/openapi/parser/resolvers.js +63 -0
- package/dist/openapi/parser/resolvers.js.map +1 -0
- package/dist/openapi/parser/utils.d.ts +19 -0
- package/dist/openapi/parser/utils.d.ts.map +1 -0
- package/dist/openapi/parser/utils.js +48 -0
- package/dist/openapi/parser/utils.js.map +1 -0
- package/dist/openapi/parser.js +6 -232
- package/dist/openapi/schema-converter.d.ts +7 -1
- package/dist/openapi/schema-converter.d.ts.map +1 -1
- package/dist/openapi/schema-converter.js +117 -20
- package/dist/openapi/schema-converter.js.map +1 -1
- package/dist/openapi/types.d.ts +75 -20
- package/dist/openapi/types.d.ts.map +1 -1
- package/package.json +5 -5
- package/dist/openapi/importer.d.ts +0 -16
- package/dist/openapi/importer.d.ts.map +0 -1
- package/dist/openapi/importer.js +0 -265
- package/dist/openapi/importer.js.map +0 -1
- package/dist/openapi/parser.d.ts +0 -32
- package/dist/openapi/parser.d.ts.map +0 -1
- package/dist/openapi/parser.js.map +0 -1
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import { toFileName, toSpecName } from "../../common/utils.js";
|
|
2
|
+
import { generateSchemaModelCode } from "../schema-converter.js";
|
|
3
|
+
import { buildInputSchema, getOutputSchema } from "./schemas.js";
|
|
4
|
+
import { COMMAND_METHODS, inferAuthLevel, inferOpKind } from "./analyzer.js";
|
|
5
|
+
import { generateSpecCode } from "./generator.js";
|
|
6
|
+
import { generateModelCode } from "./models.js";
|
|
7
|
+
import { generateEventCode } from "./events.js";
|
|
8
|
+
import { resolveEventGroupFolder, resolveModelGroupFolder, resolveOperationGroupFolder } from "./grouping.js";
|
|
9
|
+
|
|
10
|
+
//#region src/openapi/importer/index.ts
|
|
11
|
+
/**
|
|
12
|
+
* Import operations from a parsed OpenAPI document.
|
|
13
|
+
*/
|
|
14
|
+
const importFromOpenApi = (parseResult, contractspecOptions, importOptions = {}) => {
|
|
15
|
+
const { tags, exclude = [], include } = importOptions;
|
|
16
|
+
const specs = [];
|
|
17
|
+
const skipped = [];
|
|
18
|
+
const errors = [];
|
|
19
|
+
for (const operation of parseResult.operations) {
|
|
20
|
+
if (tags && tags.length > 0) {
|
|
21
|
+
if (!operation.tags.some((t) => tags.includes(t))) {
|
|
22
|
+
skipped.push({
|
|
23
|
+
sourceId: operation.operationId,
|
|
24
|
+
reason: `No matching tags (has: ${operation.tags.join(", ")})`
|
|
25
|
+
});
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
if (include && include.length > 0) {
|
|
30
|
+
if (!include.includes(operation.operationId)) {
|
|
31
|
+
skipped.push({
|
|
32
|
+
sourceId: operation.operationId,
|
|
33
|
+
reason: "Not in include list"
|
|
34
|
+
});
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
} else if (exclude.includes(operation.operationId)) {
|
|
38
|
+
skipped.push({
|
|
39
|
+
sourceId: operation.operationId,
|
|
40
|
+
reason: "In exclude list"
|
|
41
|
+
});
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
if (operation.deprecated && importOptions.defaultStability !== "deprecated") {
|
|
45
|
+
skipped.push({
|
|
46
|
+
sourceId: operation.operationId,
|
|
47
|
+
reason: "Deprecated operation"
|
|
48
|
+
});
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
try {
|
|
52
|
+
const { schema: inputSchema } = buildInputSchema(operation);
|
|
53
|
+
const inputModel = inputSchema ? generateSchemaModelCode(inputSchema, `${operation.operationId}Input`) : null;
|
|
54
|
+
const outputSchema = getOutputSchema(operation);
|
|
55
|
+
let outputModel = outputSchema ? generateSchemaModelCode(outputSchema, `${operation.operationId}Output`) : null;
|
|
56
|
+
if (outputModel && !outputModel.code.includes("defineSchemaModel")) outputModel = null;
|
|
57
|
+
const code = generateSpecCode(operation, contractspecOptions, importOptions, inputModel, outputModel);
|
|
58
|
+
const fileName = toFileName(toSpecName(operation.operationId, importOptions.prefix));
|
|
59
|
+
const transportHints = { rest: {
|
|
60
|
+
method: operation.method.toUpperCase(),
|
|
61
|
+
path: operation.path,
|
|
62
|
+
params: {
|
|
63
|
+
path: operation.pathParams.map((p) => p.name),
|
|
64
|
+
query: operation.queryParams.map((p) => p.name),
|
|
65
|
+
header: operation.headerParams.map((p) => p.name),
|
|
66
|
+
cookie: operation.cookieParams.map((p) => p.name)
|
|
67
|
+
}
|
|
68
|
+
} };
|
|
69
|
+
const source = {
|
|
70
|
+
type: "openapi",
|
|
71
|
+
sourceId: operation.operationId,
|
|
72
|
+
operationId: operation.operationId,
|
|
73
|
+
openApiVersion: parseResult.version,
|
|
74
|
+
importedAt: /* @__PURE__ */ new Date()
|
|
75
|
+
};
|
|
76
|
+
const groupFolder = resolveOperationGroupFolder(operation, contractspecOptions.conventions);
|
|
77
|
+
specs.push({
|
|
78
|
+
code,
|
|
79
|
+
fileName,
|
|
80
|
+
groupFolder: groupFolder || void 0,
|
|
81
|
+
source,
|
|
82
|
+
transportHints
|
|
83
|
+
});
|
|
84
|
+
} catch (error) {
|
|
85
|
+
errors.push({
|
|
86
|
+
sourceId: operation.operationId,
|
|
87
|
+
error: error instanceof Error ? error.message : String(error)
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
for (const [name, schema] of Object.entries(parseResult.schemas)) try {
|
|
92
|
+
const code = generateModelCode(name, schema, contractspecOptions);
|
|
93
|
+
const fileName = toFileName(toSpecName(name, importOptions.prefix));
|
|
94
|
+
const groupFolder = resolveModelGroupFolder(name, contractspecOptions.conventions);
|
|
95
|
+
specs.push({
|
|
96
|
+
code,
|
|
97
|
+
fileName,
|
|
98
|
+
groupFolder: groupFolder || void 0,
|
|
99
|
+
source: {
|
|
100
|
+
type: "openapi",
|
|
101
|
+
sourceId: name,
|
|
102
|
+
operationId: name,
|
|
103
|
+
openApiVersion: parseResult.version,
|
|
104
|
+
importedAt: /* @__PURE__ */ new Date()
|
|
105
|
+
},
|
|
106
|
+
transportHints: {}
|
|
107
|
+
});
|
|
108
|
+
} catch (error) {
|
|
109
|
+
errors.push({
|
|
110
|
+
sourceId: name,
|
|
111
|
+
error: error instanceof Error ? "Model conversion failed: " + error.message : String(error)
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
for (const event of parseResult.events) try {
|
|
115
|
+
const code = generateEventCode(event, contractspecOptions);
|
|
116
|
+
const fileName = toFileName(toSpecName(event.name, importOptions.prefix));
|
|
117
|
+
const groupFolder = resolveEventGroupFolder(event.name, contractspecOptions.conventions);
|
|
118
|
+
specs.push({
|
|
119
|
+
code,
|
|
120
|
+
fileName,
|
|
121
|
+
groupFolder: groupFolder || void 0,
|
|
122
|
+
source: {
|
|
123
|
+
type: "openapi",
|
|
124
|
+
sourceId: event.name,
|
|
125
|
+
operationId: event.name,
|
|
126
|
+
openApiVersion: parseResult.version,
|
|
127
|
+
importedAt: /* @__PURE__ */ new Date()
|
|
128
|
+
},
|
|
129
|
+
transportHints: {}
|
|
130
|
+
});
|
|
131
|
+
} catch (error) {
|
|
132
|
+
errors.push({
|
|
133
|
+
sourceId: event.name,
|
|
134
|
+
error: error instanceof Error ? "Event conversion failed: " + error.message : String(error)
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
return {
|
|
138
|
+
operationSpecs: specs,
|
|
139
|
+
skipped,
|
|
140
|
+
errors,
|
|
141
|
+
summary: {
|
|
142
|
+
total: parseResult.operations.length + Object.keys(parseResult.schemas).length + parseResult.events.length,
|
|
143
|
+
imported: specs.length,
|
|
144
|
+
skipped: skipped.length,
|
|
145
|
+
errors: errors.length
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
};
|
|
149
|
+
/**
|
|
150
|
+
* Import a single operation to ContractSpec code.
|
|
151
|
+
*/
|
|
152
|
+
function importOperation(operation, options = {}, contractspecOptions) {
|
|
153
|
+
const { schema: inputSchema } = buildInputSchema(operation);
|
|
154
|
+
const inputModel = inputSchema ? generateSchemaModelCode(inputSchema, `${operation.operationId}Input`) : null;
|
|
155
|
+
const outputSchema = getOutputSchema(operation);
|
|
156
|
+
return generateSpecCode(operation, contractspecOptions, options, inputModel, outputSchema ? generateSchemaModelCode(outputSchema, `${operation.operationId}Output`) : null);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
//#endregion
|
|
160
|
+
export { importFromOpenApi, importOperation };
|
|
161
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":["specs: ImportedOperationSpec[]","skipped: ImportResult['skipped']","errors: ImportResult['errors']","transportHints: OpenApiTransportHints","source: OpenApiSource"],"sources":["../../../src/openapi/importer/index.ts"],"sourcesContent":["import type {\n OpenApiSource,\n OpenApiTransportHints,\n ParsedOperation,\n ParseResult,\n} from '../types';\nimport type { ImportedOperationSpec, ImportResult } from '../../common/types';\nimport { toFileName, toSpecName } from '../../common/utils';\nimport { generateSchemaModelCode } from '../schema-converter';\nimport { buildInputSchema, getOutputSchema } from './schemas';\nimport { generateSpecCode } from './generator';\nimport { generateModelCode } from './models';\nimport { generateEventCode } from './events';\nimport {\n resolveOperationGroupFolder,\n resolveModelGroupFolder,\n resolveEventGroupFolder,\n} from './grouping';\nimport type {\n ContractsrcConfig,\n OpenApiSourceConfig,\n} from '@lssm/lib.contracts';\n\nexport * from './analyzer';\nexport * from './schemas';\nexport * from './generator';\nexport * from './models';\nexport * from './events';\nexport * from './grouping';\n\n/**\n * Import operations from a parsed OpenAPI document.\n */\nexport const importFromOpenApi = (\n parseResult: ParseResult,\n contractspecOptions: ContractsrcConfig,\n importOptions: Partial<OpenApiSourceConfig> = {}\n): ImportResult => {\n const { tags, exclude = [], include } = importOptions;\n const specs: ImportedOperationSpec[] = [];\n const skipped: ImportResult['skipped'] = [];\n const errors: ImportResult['errors'] = [];\n\n for (const operation of parseResult.operations) {\n // Filter by tags if specified\n if (tags && tags.length > 0) {\n const hasMatchingTag = operation.tags.some((t) => tags.includes(t));\n if (!hasMatchingTag) {\n skipped.push({\n sourceId: operation.operationId,\n reason: `No matching tags (has: ${operation.tags.join(', ')})`,\n });\n continue;\n }\n }\n\n // Filter by include/exclude\n if (include && include.length > 0) {\n if (!include.includes(operation.operationId)) {\n skipped.push({\n sourceId: operation.operationId,\n reason: 'Not in include list',\n });\n continue;\n }\n } else if (exclude.includes(operation.operationId)) {\n skipped.push({\n sourceId: operation.operationId,\n reason: 'In exclude list',\n });\n continue;\n }\n\n // Skip deprecated operations by default\n if (\n operation.deprecated &&\n importOptions.defaultStability !== 'deprecated'\n ) {\n skipped.push({\n sourceId: operation.operationId,\n reason: 'Deprecated operation',\n });\n continue;\n }\n\n try {\n // Build input schema\n const { schema: inputSchema } = buildInputSchema(operation);\n const inputModel = inputSchema\n ? generateSchemaModelCode(inputSchema, `${operation.operationId}Input`)\n : null;\n\n // Get output schema\n const outputSchema = getOutputSchema(operation);\n let outputModel = outputSchema\n ? generateSchemaModelCode(\n outputSchema,\n `${operation.operationId}Output`\n )\n : null;\n\n // Filter out empty/comment-only output models\n if (outputModel && !outputModel.code.includes('defineSchemaModel')) {\n outputModel = null;\n }\n\n // Generate spec code\n const code = generateSpecCode(\n operation,\n contractspecOptions,\n importOptions,\n inputModel,\n outputModel\n );\n const specName = toSpecName(operation.operationId, importOptions.prefix);\n const fileName = toFileName(specName);\n\n // Build transport hints\n const transportHints: OpenApiTransportHints = {\n rest: {\n method:\n operation.method.toUpperCase() as OpenApiTransportHints['rest']['method'],\n path: operation.path,\n params: {\n path: operation.pathParams.map((p) => p.name),\n query: operation.queryParams.map((p) => p.name),\n header: operation.headerParams.map((p) => p.name),\n cookie: operation.cookieParams.map((p) => p.name),\n },\n },\n };\n\n // Build source info\n const source: OpenApiSource = {\n type: 'openapi',\n sourceId: operation.operationId,\n operationId: operation.operationId,\n openApiVersion: parseResult.version,\n importedAt: new Date(),\n };\n\n // Resolve group folder based on config\n const groupFolder = resolveOperationGroupFolder(\n operation,\n contractspecOptions.conventions\n );\n\n specs.push({\n code,\n fileName,\n groupFolder: groupFolder || undefined,\n source,\n transportHints,\n });\n } catch (error) {\n errors.push({\n sourceId: operation.operationId,\n error: error instanceof Error ? error.message : String(error),\n });\n }\n }\n\n // Import standalone models\n for (const [name, schema] of Object.entries(parseResult.schemas)) {\n try {\n const code = generateModelCode(name, schema, contractspecOptions);\n const fileName = toFileName(toSpecName(name, importOptions.prefix));\n const groupFolder = resolveModelGroupFolder(\n name,\n contractspecOptions.conventions\n );\n\n specs.push({\n code,\n fileName,\n groupFolder: groupFolder || undefined,\n source: {\n type: 'openapi',\n sourceId: name,\n operationId: name,\n openApiVersion: parseResult.version,\n importedAt: new Date(),\n } as OpenApiSource,\n transportHints: {},\n });\n } catch (error) {\n errors.push({\n sourceId: name,\n error:\n error instanceof Error\n ? 'Model conversion failed: ' + error.message\n : String(error),\n });\n }\n }\n\n // Import events\n for (const event of parseResult.events) {\n try {\n const code = generateEventCode(event, contractspecOptions);\n const fileName = toFileName(toSpecName(event.name, importOptions.prefix));\n const groupFolder = resolveEventGroupFolder(\n event.name,\n contractspecOptions.conventions\n );\n\n specs.push({\n code,\n fileName,\n groupFolder: groupFolder || undefined,\n source: {\n type: 'openapi',\n sourceId: event.name,\n operationId: event.name,\n openApiVersion: parseResult.version,\n importedAt: new Date(),\n } as OpenApiSource,\n transportHints: {},\n });\n } catch (error) {\n errors.push({\n sourceId: event.name,\n error:\n error instanceof Error\n ? 'Event conversion failed: ' + error.message\n : String(error),\n });\n }\n }\n\n return {\n operationSpecs: specs,\n skipped,\n errors,\n summary: {\n total:\n parseResult.operations.length +\n Object.keys(parseResult.schemas).length +\n parseResult.events.length,\n imported: specs.length,\n skipped: skipped.length,\n errors: errors.length,\n },\n };\n};\n\n/**\n * Import a single operation to ContractSpec code.\n */\nexport function importOperation(\n operation: ParsedOperation,\n options: Partial<OpenApiSourceConfig> = {},\n contractspecOptions: ContractsrcConfig\n): string {\n const { schema: inputSchema } = buildInputSchema(operation);\n const inputModel = inputSchema\n ? generateSchemaModelCode(inputSchema, `${operation.operationId}Input`)\n : null;\n\n const outputSchema = getOutputSchema(operation);\n const outputModel = outputSchema\n ? generateSchemaModelCode(outputSchema, `${operation.operationId}Output`)\n : null;\n\n return generateSpecCode(\n operation,\n contractspecOptions,\n options,\n inputModel,\n outputModel\n );\n}\n"],"mappings":"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"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { toPascalCase, toValidIdentifier } from "../../common/utils.js";
|
|
2
|
+
import { generateImports, generateSchemaModelCode } from "../schema-converter.js";
|
|
3
|
+
|
|
4
|
+
//#region src/openapi/importer/models.ts
|
|
5
|
+
/**
|
|
6
|
+
* Generate code for a standalone model.
|
|
7
|
+
*/
|
|
8
|
+
function generateModelCode(name, schema, options) {
|
|
9
|
+
const model = generateSchemaModelCode(schema, toPascalCase(toValidIdentifier(name)));
|
|
10
|
+
return `
|
|
11
|
+
${generateImports(model.fields, options)}
|
|
12
|
+
|
|
13
|
+
${model.code}
|
|
14
|
+
`.trim();
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
//#endregion
|
|
18
|
+
export { generateModelCode };
|
|
19
|
+
//# sourceMappingURL=models.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"models.js","names":[],"sources":["../../../src/openapi/importer/models.ts"],"sourcesContent":["import type { OpenApiSchema } from '../types';\nimport { generateImports, generateSchemaModelCode } from '../schema-converter';\nimport { toPascalCase, toValidIdentifier } from '../../common/utils';\nimport type { ContractsrcConfig } from '@lssm/lib.contracts';\n\n/**\n * Generate code for a standalone model.\n */\nexport function generateModelCode(\n name: string,\n schema: OpenApiSchema,\n options: ContractsrcConfig\n): string {\n const modelName = toPascalCase(toValidIdentifier(name));\n const model = generateSchemaModelCode(schema, modelName);\n\n const imports = generateImports(model.fields, options);\n\n return `\n${imports}\n\n${model.code}\n`.trim();\n}\n"],"mappings":";;;;;;;AAQA,SAAgB,kBACd,MACA,QACA,SACQ;CAER,MAAM,QAAQ,wBAAwB,QADpB,aAAa,kBAAkB,KAAK,CAAC,CACC;AAIxD,QAAO;EAFS,gBAAgB,MAAM,QAAQ,QAAQ,CAG9C;;EAER,MAAM,KAAK;EACX,MAAM"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
//#region src/openapi/importer/schemas.ts
|
|
2
|
+
/**
|
|
3
|
+
* Build a merged input schema from all parameter sources.
|
|
4
|
+
*/
|
|
5
|
+
function buildInputSchema(operation) {
|
|
6
|
+
const fields = [];
|
|
7
|
+
for (const param of operation.pathParams) fields.push({
|
|
8
|
+
name: param.name,
|
|
9
|
+
schema: param.schema,
|
|
10
|
+
required: true
|
|
11
|
+
});
|
|
12
|
+
for (const param of operation.queryParams) fields.push({
|
|
13
|
+
name: param.name,
|
|
14
|
+
schema: param.schema,
|
|
15
|
+
required: param.required
|
|
16
|
+
});
|
|
17
|
+
const excludedHeaders = [
|
|
18
|
+
"authorization",
|
|
19
|
+
"content-type",
|
|
20
|
+
"accept",
|
|
21
|
+
"user-agent"
|
|
22
|
+
];
|
|
23
|
+
for (const param of operation.headerParams) if (!excludedHeaders.includes(param.name.toLowerCase())) fields.push({
|
|
24
|
+
name: param.name,
|
|
25
|
+
schema: param.schema,
|
|
26
|
+
required: param.required
|
|
27
|
+
});
|
|
28
|
+
if (operation.requestBody?.schema) {
|
|
29
|
+
const bodySchema = operation.requestBody.schema;
|
|
30
|
+
if (!("$ref" in bodySchema)) {
|
|
31
|
+
const schemaObj = bodySchema;
|
|
32
|
+
const properties = schemaObj["properties"];
|
|
33
|
+
const required = schemaObj["required"] ?? [];
|
|
34
|
+
if (properties) for (const [propName, propSchema] of Object.entries(properties)) fields.push({
|
|
35
|
+
name: propName,
|
|
36
|
+
schema: propSchema,
|
|
37
|
+
required: required.includes(propName)
|
|
38
|
+
});
|
|
39
|
+
} else fields.push({
|
|
40
|
+
name: "body",
|
|
41
|
+
schema: bodySchema,
|
|
42
|
+
required: operation.requestBody.required
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
if (fields.length === 0) return {
|
|
46
|
+
schema: null,
|
|
47
|
+
fields: []
|
|
48
|
+
};
|
|
49
|
+
return {
|
|
50
|
+
schema: {
|
|
51
|
+
type: "object",
|
|
52
|
+
properties: fields.reduce((acc, f) => {
|
|
53
|
+
acc[f.name] = f.schema;
|
|
54
|
+
return acc;
|
|
55
|
+
}, {}),
|
|
56
|
+
required: fields.filter((f) => f.required).map((f) => f.name)
|
|
57
|
+
},
|
|
58
|
+
fields
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Get the output schema from the operation responses.
|
|
63
|
+
*/
|
|
64
|
+
function getOutputSchema(operation) {
|
|
65
|
+
for (const code of [
|
|
66
|
+
"200",
|
|
67
|
+
"201",
|
|
68
|
+
"202",
|
|
69
|
+
"204"
|
|
70
|
+
]) {
|
|
71
|
+
const response = operation.responses[code];
|
|
72
|
+
if (response?.schema) return response.schema;
|
|
73
|
+
}
|
|
74
|
+
for (const [code, response] of Object.entries(operation.responses)) if (code.startsWith("2") && response.schema) return response.schema;
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
//#endregion
|
|
79
|
+
export { buildInputSchema, getOutputSchema };
|
|
80
|
+
//# sourceMappingURL=schemas.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schemas.js","names":["fields: {\n name: string;\n schema: OpenApiSchema;\n required: boolean;\n }[]"],"sources":["../../../src/openapi/importer/schemas.ts"],"sourcesContent":["import type { ParsedOperation, OpenApiSchema } from '../types';\n\n/**\n * Build a merged input schema from all parameter sources.\n */\nexport function buildInputSchema(operation: ParsedOperation): {\n schema: OpenApiSchema | null;\n fields: { name: string; schema: OpenApiSchema; required: boolean }[];\n} {\n const fields: {\n name: string;\n schema: OpenApiSchema;\n required: boolean;\n }[] = [];\n\n // Add path parameters\n for (const param of operation.pathParams) {\n fields.push({\n name: param.name,\n schema: param.schema,\n required: true, // Path params are always required\n });\n }\n\n // Add query parameters\n for (const param of operation.queryParams) {\n fields.push({\n name: param.name,\n schema: param.schema,\n required: param.required,\n });\n }\n\n // Add header parameters (excluding common headers)\n const excludedHeaders = [\n 'authorization',\n 'content-type',\n 'accept',\n 'user-agent',\n ];\n for (const param of operation.headerParams) {\n if (!excludedHeaders.includes(param.name.toLowerCase())) {\n fields.push({\n name: param.name,\n schema: param.schema,\n required: param.required,\n });\n }\n }\n\n // Add request body fields\n if (operation.requestBody?.schema) {\n const bodySchema = operation.requestBody.schema;\n if (!('$ref' in bodySchema)) {\n const schemaObj = bodySchema as Record<string, unknown>;\n const properties = schemaObj['properties'] as\n | Record<string, OpenApiSchema>\n | undefined;\n const required = (schemaObj['required'] as string[]) ?? [];\n\n if (properties) {\n for (const [propName, propSchema] of Object.entries(properties)) {\n fields.push({\n name: propName,\n schema: propSchema,\n required: required.includes(propName),\n });\n }\n }\n } else {\n // Reference to a schema - add as a single field\n fields.push({\n name: 'body',\n schema: bodySchema,\n required: operation.requestBody.required,\n });\n }\n }\n\n if (fields.length === 0) {\n return { schema: null, fields: [] };\n }\n\n // Build a merged schema\n const mergedSchema: OpenApiSchema = {\n type: 'object',\n properties: fields.reduce(\n (acc, f) => {\n acc[f.name] = f.schema;\n return acc;\n },\n {} as Record<string, OpenApiSchema>\n ),\n required: fields.filter((f) => f.required).map((f) => f.name),\n } as unknown as OpenApiSchema;\n\n return { schema: mergedSchema, fields };\n}\n\n/**\n * Get the output schema from the operation responses.\n */\nexport function getOutputSchema(\n operation: ParsedOperation\n): OpenApiSchema | null {\n // Prefer 200, then 201, then 2xx responses\n const successCodes = ['200', '201', '202', '204'];\n\n for (const code of successCodes) {\n const response = operation.responses[code];\n if (response?.schema) {\n return response.schema;\n }\n }\n\n // Check for any 2xx response\n for (const [code, response] of Object.entries(operation.responses)) {\n if (code.startsWith('2') && response.schema) {\n return response.schema;\n }\n }\n\n return null;\n}\n"],"mappings":";;;;AAKA,SAAgB,iBAAiB,WAG/B;CACA,MAAMA,SAIA,EAAE;AAGR,MAAK,MAAM,SAAS,UAAU,WAC5B,QAAO,KAAK;EACV,MAAM,MAAM;EACZ,QAAQ,MAAM;EACd,UAAU;EACX,CAAC;AAIJ,MAAK,MAAM,SAAS,UAAU,YAC5B,QAAO,KAAK;EACV,MAAM,MAAM;EACZ,QAAQ,MAAM;EACd,UAAU,MAAM;EACjB,CAAC;CAIJ,MAAM,kBAAkB;EACtB;EACA;EACA;EACA;EACD;AACD,MAAK,MAAM,SAAS,UAAU,aAC5B,KAAI,CAAC,gBAAgB,SAAS,MAAM,KAAK,aAAa,CAAC,CACrD,QAAO,KAAK;EACV,MAAM,MAAM;EACZ,QAAQ,MAAM;EACd,UAAU,MAAM;EACjB,CAAC;AAKN,KAAI,UAAU,aAAa,QAAQ;EACjC,MAAM,aAAa,UAAU,YAAY;AACzC,MAAI,EAAE,UAAU,aAAa;GAC3B,MAAM,YAAY;GAClB,MAAM,aAAa,UAAU;GAG7B,MAAM,WAAY,UAAU,eAA4B,EAAE;AAE1D,OAAI,WACF,MAAK,MAAM,CAAC,UAAU,eAAe,OAAO,QAAQ,WAAW,CAC7D,QAAO,KAAK;IACV,MAAM;IACN,QAAQ;IACR,UAAU,SAAS,SAAS,SAAS;IACtC,CAAC;QAKN,QAAO,KAAK;GACV,MAAM;GACN,QAAQ;GACR,UAAU,UAAU,YAAY;GACjC,CAAC;;AAIN,KAAI,OAAO,WAAW,EACpB,QAAO;EAAE,QAAQ;EAAM,QAAQ,EAAE;EAAE;AAgBrC,QAAO;EAAE,QAZ2B;GAClC,MAAM;GACN,YAAY,OAAO,QAChB,KAAK,MAAM;AACV,QAAI,EAAE,QAAQ,EAAE;AAChB,WAAO;MAET,EAAE,CACH;GACD,UAAU,OAAO,QAAQ,MAAM,EAAE,SAAS,CAAC,KAAK,MAAM,EAAE,KAAK;GAC9D;EAE8B;EAAQ;;;;;AAMzC,SAAgB,gBACd,WACsB;AAItB,MAAK,MAAM,QAFU;EAAC;EAAO;EAAO;EAAO;EAAM,EAEhB;EAC/B,MAAM,WAAW,UAAU,UAAU;AACrC,MAAI,UAAU,OACZ,QAAO,SAAS;;AAKpB,MAAK,MAAM,CAAC,MAAM,aAAa,OAAO,QAAQ,UAAU,UAAU,CAChE,KAAI,KAAK,WAAW,IAAI,IAAI,SAAS,OACnC,QAAO,SAAS;AAIpB,QAAO"}
|
package/dist/openapi/index.d.ts
CHANGED
|
@@ -1,7 +1,16 @@
|
|
|
1
|
-
import { ContractSpecOpenApiDocument, HttpMethod, OpenApiDocument, OpenApiExportOptions,
|
|
2
|
-
import { detectFormat, detectVersion,
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import { ContractSpecOpenApiDocument, HttpMethod, OpenApiDocument, OpenApiExportOptions, OpenApiOperation, OpenApiParameter, OpenApiParseOptions, OpenApiSchema, OpenApiServer, OpenApiSource, OpenApiTransportHints, OpenApiVersion, ParameterLocation, ParseResult, ParsedOperation, ParsedParameter } from "./types.js";
|
|
2
|
+
import { detectFormat, detectVersion, parseOpenApiString } from "./parser/utils.js";
|
|
3
|
+
import { parseOpenApi, parseOpenApiDocument } from "./parser/document.js";
|
|
4
|
+
import { OperationsExportResult, defaultRestPath, exportOperations, generateOperationsRegistry, jsonSchemaForSpec, schemaModelToJsonSchema, toHttpMethod, toOperationId, toRestPath, toSchemaName } from "./exporter/operations.js";
|
|
5
|
+
import { ContractSpecRegistries, contractSpecToJson, contractSpecToYaml, exportContractSpec, openApiForRegistry, openApiToJson, openApiToYaml } from "./exporter.js";
|
|
6
|
+
import { ExportedEvent, exportEvents, generateEventsExports } from "./exporter/events.js";
|
|
7
|
+
import { ExportedFeature, exportFeatures, generateFeaturesRegistry } from "./exporter/features.js";
|
|
8
|
+
import { ExportedPresentation, ExportedPresentationV2, exportPresentations, exportPresentationsV1, exportPresentationsV2, generatePresentationsRegistry } from "./exporter/presentations.js";
|
|
9
|
+
import { ExportedForm, exportForms, generateFormsRegistry } from "./exporter/forms.js";
|
|
10
|
+
import { ExportedDataView, exportDataViews, generateDataViewsRegistry } from "./exporter/data-views.js";
|
|
11
|
+
import { ExportedWorkflow, exportWorkflows, generateWorkflowsRegistry } from "./exporter/workflows.js";
|
|
12
|
+
import { RegistryGenerationOptions, generateRegistryIndex } from "./exporter/registries.js";
|
|
5
13
|
import { GeneratedModel, SchemaField, TypescriptType, generateImports, generateSchemaModelCode, getScalarType, jsonSchemaToField, jsonSchemaToType } from "./schema-converter.js";
|
|
14
|
+
import { importFromOpenApi, importOperation } from "./importer/index.js";
|
|
6
15
|
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
|
|
16
|
+
export { type ContractSpecOpenApiDocument, type ContractSpecRegistries, type DiffOptions, ExportedDataView, ExportedEvent, ExportedFeature, ExportedForm, ExportedPresentation, ExportedPresentationV2, ExportedWorkflow, type GeneratedModel, type HttpMethod, type OpenApiDocument, type OpenApiExportOptions, type OpenApiOperation, type OpenApiParameter, type OpenApiParseOptions, type OpenApiSchema, type OpenApiServer, type OpenApiSource, type OpenApiTransportHints, type OpenApiVersion, OperationsExportResult, type ParameterLocation, type ParseResult, type ParsedOperation, type ParsedParameter, RegistryGenerationOptions, type SchemaField, type TypescriptType, contractSpecToJson, contractSpecToYaml, createSpecDiff, defaultRestPath, detectFormat, detectVersion, diffAll, diffSpecVsOperation, diffSpecs, exportContractSpec, exportDataViews, exportEvents, exportFeatures, exportForms, exportOperations, exportPresentations, exportPresentationsV1, exportPresentationsV2, exportWorkflows, formatDiffChanges, generateDataViewsRegistry, generateEventsExports, generateFeaturesRegistry, generateFormsRegistry, generateImports, generateOperationsRegistry, generatePresentationsRegistry, generateRegistryIndex, generateSchemaModelCode, generateWorkflowsRegistry, getScalarType, importFromOpenApi, importOperation, jsonSchemaForSpec, jsonSchemaToField, jsonSchemaToType, openApiForRegistry, openApiToJson, openApiToYaml, parseOpenApi, parseOpenApiDocument, parseOpenApiString, schemaModelToJsonSchema, toHttpMethod, toOperationId, toRestPath, toSchemaName };
|
package/dist/openapi/index.js
CHANGED
|
@@ -1,7 +1,18 @@
|
|
|
1
|
-
import { detectFormat, detectVersion,
|
|
2
|
-
import {
|
|
1
|
+
import { detectFormat, detectVersion, parseOpenApiString } from "./parser/utils.js";
|
|
2
|
+
import { parseOpenApi, parseOpenApiDocument } from "./parser/document.js";
|
|
3
|
+
import "./parser.js";
|
|
4
|
+
import { defaultRestPath, exportOperations, generateOperationsRegistry, jsonSchemaForSpec, schemaModelToJsonSchema, toHttpMethod, toOperationId, toRestPath, toSchemaName } from "./exporter/operations.js";
|
|
5
|
+
import { exportEvents, generateEventsExports } from "./exporter/events.js";
|
|
6
|
+
import { exportFeatures, generateFeaturesRegistry } from "./exporter/features.js";
|
|
7
|
+
import { exportPresentations, exportPresentationsV1, exportPresentationsV2, generatePresentationsRegistry } from "./exporter/presentations.js";
|
|
8
|
+
import { exportForms, generateFormsRegistry } from "./exporter/forms.js";
|
|
9
|
+
import { exportDataViews, generateDataViewsRegistry } from "./exporter/data-views.js";
|
|
10
|
+
import { exportWorkflows, generateWorkflowsRegistry } from "./exporter/workflows.js";
|
|
11
|
+
import { generateRegistryIndex } from "./exporter/registries.js";
|
|
12
|
+
import { contractSpecToJson, contractSpecToYaml, exportContractSpec, openApiForRegistry, openApiToJson, openApiToYaml } from "./exporter.js";
|
|
13
|
+
import "./exporter/index.js";
|
|
3
14
|
import { generateImports, generateSchemaModelCode, getScalarType, jsonSchemaToField, jsonSchemaToType } from "./schema-converter.js";
|
|
4
|
-
import { importFromOpenApi, importOperation } from "./importer.js";
|
|
15
|
+
import { importFromOpenApi, importOperation } from "./importer/index.js";
|
|
5
16
|
import { createSpecDiff, diffAll, diffSpecVsOperation, diffSpecs, formatDiffChanges } from "./differ.js";
|
|
6
17
|
|
|
7
|
-
export { createSpecDiff, defaultRestPath, detectFormat, detectVersion, diffAll, diffSpecVsOperation, diffSpecs, formatDiffChanges, generateImports, generateSchemaModelCode, getScalarType, importFromOpenApi, importOperation, jsonSchemaToField, jsonSchemaToType, openApiForRegistry, openApiToJson, openApiToYaml, parseOpenApi, parseOpenApiDocument, parseOpenApiString };
|
|
18
|
+
export { contractSpecToJson, contractSpecToYaml, createSpecDiff, defaultRestPath, detectFormat, detectVersion, diffAll, diffSpecVsOperation, diffSpecs, exportContractSpec, exportDataViews, exportEvents, exportFeatures, exportForms, exportOperations, exportPresentations, exportPresentationsV1, exportPresentationsV2, exportWorkflows, formatDiffChanges, generateDataViewsRegistry, generateEventsExports, generateFeaturesRegistry, generateFormsRegistry, generateImports, generateOperationsRegistry, generatePresentationsRegistry, generateRegistryIndex, generateSchemaModelCode, generateWorkflowsRegistry, getScalarType, importFromOpenApi, importOperation, jsonSchemaForSpec, jsonSchemaToField, jsonSchemaToType, openApiForRegistry, openApiToJson, openApiToYaml, parseOpenApi, parseOpenApiDocument, parseOpenApiString, schemaModelToJsonSchema, toHttpMethod, toOperationId, toRestPath, toSchemaName };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { OpenApiDocument, OpenApiParseOptions, ParseResult } from "../types.js";
|
|
2
|
+
|
|
3
|
+
//#region src/openapi/parser/document.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Parse an OpenAPI document into a structured result.
|
|
7
|
+
*/
|
|
8
|
+
declare function parseOpenApiDocument(doc: OpenApiDocument, _options?: OpenApiParseOptions): ParseResult;
|
|
9
|
+
/**
|
|
10
|
+
* Parse OpenAPI from a file path or URL.
|
|
11
|
+
* Note: This is an async function that requires I/O adapters.
|
|
12
|
+
* For pure parsing, use parseOpenApiString or parseOpenApiDocument.
|
|
13
|
+
*/
|
|
14
|
+
declare function parseOpenApi(source: string, options?: OpenApiParseOptions & {
|
|
15
|
+
fetch?: typeof globalThis.fetch;
|
|
16
|
+
readFile?: (path: string) => Promise<string>;
|
|
17
|
+
}): Promise<ParseResult>;
|
|
18
|
+
//#endregion
|
|
19
|
+
export { parseOpenApi, parseOpenApiDocument };
|
|
20
|
+
//# sourceMappingURL=document.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"document.d.ts","names":[],"sources":["../../../src/openapi/parser/document.ts"],"sourcesContent":[],"mappings":";;;;;;AAsBA;AACO,iBADS,oBAAA,CACT,GAAA,EAAA,eAAA,EAAA,QAAA,CAAA,EACK,mBADL,CAAA,EAEJ,WAFI;;;;AA0GP;;AAGmB,iBAHG,YAAA,CAGQ,MAAA,EAAA,MAAA,EAAA,OAG3B,CAH2B,EADnB,mBACmB,GAAA;EACG,KAAA,CAAA,EAAA,OADd,UAAA,CAAW,KACG;EAEtB,QAAA,CAAA,EAAA,CAAA,IAAA,EAAA,MAAA,EAAA,GAFsB,OAEtB,CAAA,MAAA,CAAA;CAAR,CAAA,EAAA,OAAA,CAAQ,WAAR,CAAA"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { HTTP_METHODS, detectFormat, detectVersion, parseOpenApiString } from "./utils.js";
|
|
2
|
+
import { parseOperation } from "./operation.js";
|
|
3
|
+
|
|
4
|
+
//#region src/openapi/parser/document.ts
|
|
5
|
+
/**
|
|
6
|
+
* Parse an OpenAPI document into a structured result.
|
|
7
|
+
*/
|
|
8
|
+
function parseOpenApiDocument(doc, _options = {}) {
|
|
9
|
+
const version = detectVersion(doc);
|
|
10
|
+
const warnings = [];
|
|
11
|
+
const operations = [];
|
|
12
|
+
for (const [path, pathItem] of Object.entries(doc.paths ?? {})) {
|
|
13
|
+
if (!pathItem) continue;
|
|
14
|
+
const pathParams = pathItem.parameters;
|
|
15
|
+
for (const method of HTTP_METHODS) {
|
|
16
|
+
const operation = pathItem[method];
|
|
17
|
+
if (operation) try {
|
|
18
|
+
operations.push(parseOperation(doc, method, path, operation, pathParams));
|
|
19
|
+
} catch (error) {
|
|
20
|
+
warnings.push(`Failed to parse ${method.toUpperCase()} ${path}: ${error}`);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
const schemas = {};
|
|
25
|
+
const components = doc.components;
|
|
26
|
+
if (components?.schemas) for (const [name, schema] of Object.entries(components.schemas)) schemas[name] = schema;
|
|
27
|
+
const servers = (doc.servers ?? []).map((s) => ({
|
|
28
|
+
url: s.url,
|
|
29
|
+
description: s.description,
|
|
30
|
+
variables: s.variables
|
|
31
|
+
}));
|
|
32
|
+
const events = [];
|
|
33
|
+
if ("webhooks" in doc && doc.webhooks) for (const [name, pathItem] of Object.entries(doc.webhooks)) {
|
|
34
|
+
if (typeof pathItem !== "object" || !pathItem) continue;
|
|
35
|
+
const operation = pathItem["post"];
|
|
36
|
+
if (operation && operation.requestBody) {
|
|
37
|
+
if ("$ref" in operation.requestBody) throw new Error(`'$ref' isn't supported`);
|
|
38
|
+
const content = operation.requestBody.content?.["application/json"];
|
|
39
|
+
if (content?.schema) events.push({
|
|
40
|
+
name,
|
|
41
|
+
description: operation.summary || operation.description,
|
|
42
|
+
payload: content.schema
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return {
|
|
47
|
+
document: doc,
|
|
48
|
+
version,
|
|
49
|
+
info: {
|
|
50
|
+
title: doc.info.title,
|
|
51
|
+
version: doc.info.version,
|
|
52
|
+
description: doc.info.description
|
|
53
|
+
},
|
|
54
|
+
operations,
|
|
55
|
+
schemas,
|
|
56
|
+
servers,
|
|
57
|
+
warnings,
|
|
58
|
+
events
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Parse OpenAPI from a file path or URL.
|
|
63
|
+
* Note: This is an async function that requires I/O adapters.
|
|
64
|
+
* For pure parsing, use parseOpenApiString or parseOpenApiDocument.
|
|
65
|
+
*/
|
|
66
|
+
async function parseOpenApi(source, options = {}) {
|
|
67
|
+
const { fetch: fetchFn = globalThis.fetch, readFile, timeout = 3e4 } = options;
|
|
68
|
+
let content;
|
|
69
|
+
let format;
|
|
70
|
+
if (source.startsWith("http://") || source.startsWith("https://")) {
|
|
71
|
+
const controller = new AbortController();
|
|
72
|
+
const timeoutId = setTimeout(() => controller.abort(), timeout);
|
|
73
|
+
try {
|
|
74
|
+
const response = await fetchFn(source, { signal: controller.signal });
|
|
75
|
+
if (!response.ok) throw new Error(`HTTP ${response.status}: ${response.statusText}`);
|
|
76
|
+
content = await response.text();
|
|
77
|
+
} finally {
|
|
78
|
+
clearTimeout(timeoutId);
|
|
79
|
+
}
|
|
80
|
+
if (source.endsWith(".yaml") || source.endsWith(".yml")) format = "yaml";
|
|
81
|
+
else if (source.endsWith(".json")) format = "json";
|
|
82
|
+
else format = detectFormat(content);
|
|
83
|
+
} else {
|
|
84
|
+
if (!readFile) throw new Error("readFile adapter required for file paths");
|
|
85
|
+
content = await readFile(source);
|
|
86
|
+
if (source.endsWith(".yaml") || source.endsWith(".yml")) format = "yaml";
|
|
87
|
+
else if (source.endsWith(".json")) format = "json";
|
|
88
|
+
else format = detectFormat(content);
|
|
89
|
+
}
|
|
90
|
+
return parseOpenApiDocument(parseOpenApiString(content, format), options);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
//#endregion
|
|
94
|
+
export { parseOpenApi, parseOpenApiDocument };
|
|
95
|
+
//# sourceMappingURL=document.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"document.js","names":["warnings: string[]","operations: ParsedOperation[]","schemas: Record<string, OpenApiSchema>","servers: OpenApiServer[]","events: ParsedEvent[]","content: string","format: 'json' | 'yaml'"],"sources":["../../../src/openapi/parser/document.ts"],"sourcesContent":["import type {\n OpenApiDocument,\n OpenApiParameter,\n OpenApiParseOptions,\n OpenApiSchema,\n OpenApiServer,\n ParsedEvent,\n ParsedOperation,\n ParseResult,\n} from '../types';\nimport type { OpenAPIV3, OpenAPIV3_1 } from 'openapi-types';\nimport {\n detectFormat,\n detectVersion,\n HTTP_METHODS,\n parseOpenApiString,\n} from './utils';\nimport { parseOperation } from './operation';\n\n/**\n * Parse an OpenAPI document into a structured result.\n */\nexport function parseOpenApiDocument(\n doc: OpenApiDocument,\n _options: OpenApiParseOptions = {}\n): ParseResult {\n const version = detectVersion(doc);\n const warnings: string[] = [];\n const operations: ParsedOperation[] = [];\n\n // Parse operations from paths\n for (const [path, pathItem] of Object.entries(doc.paths ?? {})) {\n if (!pathItem) continue;\n\n // Get path-level parameters\n const pathParams = (pathItem as OpenAPIV3.PathItemObject).parameters;\n\n for (const method of HTTP_METHODS) {\n const operation = (pathItem as Record<string, unknown>)[method] as\n | OpenAPIV3.OperationObject\n | OpenAPIV3_1.OperationObject\n | undefined;\n\n if (operation) {\n try {\n operations.push(\n parseOperation(\n doc,\n method,\n path,\n operation,\n pathParams as OpenApiParameter[]\n )\n );\n } catch (error) {\n warnings.push(\n `Failed to parse ${method.toUpperCase()} ${path}: ${error}`\n );\n }\n }\n }\n }\n\n // Extract component schemas\n const schemas: Record<string, OpenApiSchema> = {};\n const components = doc.components;\n if (components?.schemas) {\n for (const [name, schema] of Object.entries(components.schemas)) {\n schemas[name] = schema as OpenApiSchema;\n }\n }\n\n // Parse servers\n // Parse servers\n const servers: OpenApiServer[] = (doc.servers ?? []).map((s) => ({\n url: s.url,\n description: s.description,\n variables: s.variables as OpenApiServer['variables'],\n }));\n\n // Parse webhooks (as events)\n const events: ParsedEvent[] = [];\n if ('webhooks' in doc && doc.webhooks) {\n for (const [name, pathItem] of Object.entries(doc.webhooks)) {\n if (typeof pathItem !== 'object' || !pathItem) continue;\n // Webhooks usually have a POST method defining the payload\n const operation = (pathItem as Record<string, unknown>)['post'] as\n | OpenAPIV3.OperationObject\n | OpenAPIV3_1.OperationObject\n | undefined;\n\n if (operation && operation.requestBody) {\n if ('$ref' in operation.requestBody) {\n throw new Error(`'$ref' isn't supported`);\n }\n // Extract payload schema\n const content = operation.requestBody.content?.['application/json'];\n if (content?.schema) {\n events.push({\n name,\n description: operation.summary || operation.description,\n payload: content.schema,\n });\n }\n }\n }\n }\n\n return {\n document: doc,\n version,\n info: {\n title: doc.info.title,\n version: doc.info.version,\n description: doc.info.description,\n },\n operations,\n schemas,\n servers,\n warnings,\n events,\n };\n}\n\n/**\n * Parse OpenAPI from a file path or URL.\n * Note: This is an async function that requires I/O adapters.\n * For pure parsing, use parseOpenApiString or parseOpenApiDocument.\n */\nexport async function parseOpenApi(\n source: string,\n options: OpenApiParseOptions & {\n fetch?: typeof globalThis.fetch;\n readFile?: (path: string) => Promise<string>;\n } = {}\n): Promise<ParseResult> {\n const {\n fetch: fetchFn = globalThis.fetch,\n readFile,\n timeout = 30000,\n } = options;\n\n let content: string;\n let format: 'json' | 'yaml';\n\n if (source.startsWith('http://') || source.startsWith('https://')) {\n // Fetch from URL\n const controller = new AbortController();\n const timeoutId = setTimeout(() => controller.abort(), timeout);\n\n try {\n const response = await fetchFn(source, { signal: controller.signal });\n if (!response.ok) {\n throw new Error(`HTTP ${response.status}: ${response.statusText}`);\n }\n content = await response.text();\n } finally {\n clearTimeout(timeoutId);\n }\n\n // Detect format from URL or content\n if (source.endsWith('.yaml') || source.endsWith('.yml')) {\n format = 'yaml';\n } else if (source.endsWith('.json')) {\n format = 'json';\n } else {\n format = detectFormat(content);\n }\n } else {\n // Read from file\n if (!readFile) {\n throw new Error('readFile adapter required for file paths');\n }\n content = await readFile(source);\n\n // Detect format from extension or content\n if (source.endsWith('.yaml') || source.endsWith('.yml')) {\n format = 'yaml';\n } else if (source.endsWith('.json')) {\n format = 'json';\n } else {\n format = detectFormat(content);\n }\n }\n\n const doc = parseOpenApiString(content, format);\n return parseOpenApiDocument(doc, options);\n}\n"],"mappings":";;;;;;;AAsBA,SAAgB,qBACd,KACA,WAAgC,EAAE,EACrB;CACb,MAAM,UAAU,cAAc,IAAI;CAClC,MAAMA,WAAqB,EAAE;CAC7B,MAAMC,aAAgC,EAAE;AAGxC,MAAK,MAAM,CAAC,MAAM,aAAa,OAAO,QAAQ,IAAI,SAAS,EAAE,CAAC,EAAE;AAC9D,MAAI,CAAC,SAAU;EAGf,MAAM,aAAc,SAAsC;AAE1D,OAAK,MAAM,UAAU,cAAc;GACjC,MAAM,YAAa,SAAqC;AAKxD,OAAI,UACF,KAAI;AACF,eAAW,KACT,eACE,KACA,QACA,MACA,WACA,WACD,CACF;YACM,OAAO;AACd,aAAS,KACP,mBAAmB,OAAO,aAAa,CAAC,GAAG,KAAK,IAAI,QACrD;;;;CAOT,MAAMC,UAAyC,EAAE;CACjD,MAAM,aAAa,IAAI;AACvB,KAAI,YAAY,QACd,MAAK,MAAM,CAAC,MAAM,WAAW,OAAO,QAAQ,WAAW,QAAQ,CAC7D,SAAQ,QAAQ;CAMpB,MAAMC,WAA4B,IAAI,WAAW,EAAE,EAAE,KAAK,OAAO;EAC/D,KAAK,EAAE;EACP,aAAa,EAAE;EACf,WAAW,EAAE;EACd,EAAE;CAGH,MAAMC,SAAwB,EAAE;AAChC,KAAI,cAAc,OAAO,IAAI,SAC3B,MAAK,MAAM,CAAC,MAAM,aAAa,OAAO,QAAQ,IAAI,SAAS,EAAE;AAC3D,MAAI,OAAO,aAAa,YAAY,CAAC,SAAU;EAE/C,MAAM,YAAa,SAAqC;AAKxD,MAAI,aAAa,UAAU,aAAa;AACtC,OAAI,UAAU,UAAU,YACtB,OAAM,IAAI,MAAM,yBAAyB;GAG3C,MAAM,UAAU,UAAU,YAAY,UAAU;AAChD,OAAI,SAAS,OACX,QAAO,KAAK;IACV;IACA,aAAa,UAAU,WAAW,UAAU;IAC5C,SAAS,QAAQ;IAClB,CAAC;;;AAMV,QAAO;EACL,UAAU;EACV;EACA,MAAM;GACJ,OAAO,IAAI,KAAK;GAChB,SAAS,IAAI,KAAK;GAClB,aAAa,IAAI,KAAK;GACvB;EACD;EACA;EACA;EACA;EACA;EACD;;;;;;;AAQH,eAAsB,aACpB,QACA,UAGI,EAAE,EACgB;CACtB,MAAM,EACJ,OAAO,UAAU,WAAW,OAC5B,UACA,UAAU,QACR;CAEJ,IAAIC;CACJ,IAAIC;AAEJ,KAAI,OAAO,WAAW,UAAU,IAAI,OAAO,WAAW,WAAW,EAAE;EAEjE,MAAM,aAAa,IAAI,iBAAiB;EACxC,MAAM,YAAY,iBAAiB,WAAW,OAAO,EAAE,QAAQ;AAE/D,MAAI;GACF,MAAM,WAAW,MAAM,QAAQ,QAAQ,EAAE,QAAQ,WAAW,QAAQ,CAAC;AACrE,OAAI,CAAC,SAAS,GACZ,OAAM,IAAI,MAAM,QAAQ,SAAS,OAAO,IAAI,SAAS,aAAa;AAEpE,aAAU,MAAM,SAAS,MAAM;YACvB;AACR,gBAAa,UAAU;;AAIzB,MAAI,OAAO,SAAS,QAAQ,IAAI,OAAO,SAAS,OAAO,CACrD,UAAS;WACA,OAAO,SAAS,QAAQ,CACjC,UAAS;MAET,UAAS,aAAa,QAAQ;QAE3B;AAEL,MAAI,CAAC,SACH,OAAM,IAAI,MAAM,2CAA2C;AAE7D,YAAU,MAAM,SAAS,OAAO;AAGhC,MAAI,OAAO,SAAS,QAAQ,IAAI,OAAO,SAAS,OAAO,CACrD,UAAS;WACA,OAAO,SAAS,QAAQ,CACjC,UAAS;MAET,UAAS,aAAa,QAAQ;;AAKlC,QAAO,qBADK,mBAAmB,SAAS,OAAO,EACd,QAAQ"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { HTTP_METHODS, detectFormat, detectVersion, generateOperationId, parseOpenApiString } from "./utils.js";
|
|
2
|
+
import { dereferenceSchema, isReference, resolveRef } from "./resolvers.js";
|
|
3
|
+
import { parseParameters } from "./parameters.js";
|
|
4
|
+
import { parseOperation } from "./operation.js";
|
|
5
|
+
import { parseOpenApi, parseOpenApiDocument } from "./document.js";
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { generateOperationId } from "./utils.js";
|
|
2
|
+
import { dereferenceSchema, isReference, resolveRef } from "./resolvers.js";
|
|
3
|
+
import { parseParameters } from "./parameters.js";
|
|
4
|
+
|
|
5
|
+
//#region src/openapi/parser/operation.ts
|
|
6
|
+
/**
|
|
7
|
+
* Parse a single operation.
|
|
8
|
+
*/
|
|
9
|
+
function parseOperation(doc, method, path, operation, pathParams) {
|
|
10
|
+
const params = parseParameters(doc, [...pathParams ?? [], ...operation.parameters ?? []]);
|
|
11
|
+
let requestBody;
|
|
12
|
+
if (operation.requestBody) {
|
|
13
|
+
const body = isReference(operation.requestBody) ? resolveRef(doc, operation.requestBody.$ref) : operation.requestBody;
|
|
14
|
+
if (body) {
|
|
15
|
+
const contentType = Object.keys(body.content ?? {})[0] ?? "application/json";
|
|
16
|
+
const content = body.content?.[contentType];
|
|
17
|
+
if (content?.schema) requestBody = {
|
|
18
|
+
required: body.required ?? false,
|
|
19
|
+
schema: dereferenceSchema(doc, content.schema) ?? {},
|
|
20
|
+
contentType
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
const responses = {};
|
|
25
|
+
for (const [status, response] of Object.entries(operation.responses ?? {})) {
|
|
26
|
+
const resolved = isReference(response) ? resolveRef(doc, response.$ref) : response;
|
|
27
|
+
if (resolved) {
|
|
28
|
+
const contentType = Object.keys(resolved.content ?? {})[0];
|
|
29
|
+
const content = contentType ? resolved.content?.[contentType] : void 0;
|
|
30
|
+
responses[status] = {
|
|
31
|
+
description: resolved.description,
|
|
32
|
+
schema: content?.schema ? dereferenceSchema(doc, content.schema) : void 0,
|
|
33
|
+
contentType
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
const contractSpecMeta = operation?.["x-contractspec"];
|
|
38
|
+
return {
|
|
39
|
+
operationId: operation.operationId ?? generateOperationId(method, path),
|
|
40
|
+
method,
|
|
41
|
+
path,
|
|
42
|
+
summary: operation.summary,
|
|
43
|
+
description: operation.description,
|
|
44
|
+
tags: operation.tags ?? [],
|
|
45
|
+
pathParams: params.path,
|
|
46
|
+
queryParams: params.query,
|
|
47
|
+
headerParams: params.header,
|
|
48
|
+
cookieParams: params.cookie,
|
|
49
|
+
requestBody,
|
|
50
|
+
responses,
|
|
51
|
+
deprecated: operation.deprecated ?? false,
|
|
52
|
+
security: operation.security,
|
|
53
|
+
contractSpecMeta
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
//#endregion
|
|
58
|
+
export { parseOperation };
|
|
59
|
+
//# sourceMappingURL=operation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"operation.js","names":["requestBody: ParsedOperation['requestBody']","responses: ParsedOperation['responses']"],"sources":["../../../src/openapi/parser/operation.ts"],"sourcesContent":["import type {\n HttpMethod,\n OpenApiDocument,\n OpenApiParameter,\n OpenApiSchema,\n ParsedOperation,\n} from '../types';\nimport type { OpenAPIV3, OpenAPIV3_1 } from 'openapi-types';\nimport { dereferenceSchema, isReference, resolveRef } from './resolvers';\nimport { parseParameters } from './parameters';\nimport { generateOperationId } from './utils';\n\n/**\n * Parse a single operation.\n */\nexport function parseOperation(\n doc: OpenApiDocument,\n method: HttpMethod,\n path: string,\n operation: OpenAPIV3.OperationObject | OpenAPIV3_1.OperationObject,\n pathParams: OpenApiParameter[] | undefined\n): ParsedOperation {\n // Merge path-level and operation-level parameters\n const allParams = [...(pathParams ?? []), ...(operation.parameters ?? [])];\n const params = parseParameters(doc, allParams as OpenApiParameter[]);\n\n // Parse request body\n let requestBody: ParsedOperation['requestBody'];\n if (operation.requestBody) {\n const body = isReference(operation.requestBody)\n ? resolveRef<OpenAPIV3.RequestBodyObject | OpenAPIV3_1.RequestBodyObject>(\n doc,\n operation.requestBody.$ref\n )\n : operation.requestBody;\n\n if (body) {\n const contentType =\n Object.keys(body.content ?? {})[0] ?? 'application/json';\n const content = body.content?.[contentType];\n if (content?.schema) {\n requestBody = {\n required: body.required ?? false,\n schema:\n dereferenceSchema(doc, content.schema as OpenApiSchema) ??\n ({} as OpenApiSchema),\n contentType,\n };\n }\n }\n }\n\n // Parse responses\n const responses: ParsedOperation['responses'] = {};\n for (const [status, response] of Object.entries(operation.responses ?? {})) {\n const resolved = isReference(response)\n ? resolveRef<OpenAPIV3.ResponseObject | OpenAPIV3_1.ResponseObject>(\n doc,\n response.$ref\n )\n : response;\n\n if (resolved) {\n const contentType = Object.keys(resolved.content ?? {})[0];\n const content = contentType ? resolved.content?.[contentType] : undefined;\n\n responses[status] = {\n description: resolved.description,\n schema: content?.schema\n ? dereferenceSchema(doc, content.schema as OpenApiSchema)\n : undefined,\n contentType,\n };\n }\n }\n\n // Check for x-contractspec extension\n const contractSpecMeta = (operation as Record<string, unknown>)?.[\n 'x-contractspec'\n ] as ParsedOperation['contractSpecMeta'];\n\n return {\n operationId: operation.operationId ?? generateOperationId(method, path),\n method,\n path,\n summary: operation.summary,\n description: operation.description,\n tags: operation.tags ?? [],\n pathParams: params.path,\n queryParams: params.query,\n headerParams: params.header,\n cookieParams: params.cookie,\n requestBody,\n responses,\n deprecated: operation.deprecated ?? false,\n security: operation.security as ParsedOperation['security'],\n contractSpecMeta,\n };\n}\n"],"mappings":";;;;;;;;AAeA,SAAgB,eACd,KACA,QACA,MACA,WACA,YACiB;CAGjB,MAAM,SAAS,gBAAgB,KADb,CAAC,GAAI,cAAc,EAAE,EAAG,GAAI,UAAU,cAAc,EAAE,CAAE,CACN;CAGpE,IAAIA;AACJ,KAAI,UAAU,aAAa;EACzB,MAAM,OAAO,YAAY,UAAU,YAAY,GAC3C,WACE,KACA,UAAU,YAAY,KACvB,GACD,UAAU;AAEd,MAAI,MAAM;GACR,MAAM,cACJ,OAAO,KAAK,KAAK,WAAW,EAAE,CAAC,CAAC,MAAM;GACxC,MAAM,UAAU,KAAK,UAAU;AAC/B,OAAI,SAAS,OACX,eAAc;IACZ,UAAU,KAAK,YAAY;IAC3B,QACE,kBAAkB,KAAK,QAAQ,OAAwB,IACtD,EAAE;IACL;IACD;;;CAMP,MAAMC,YAA0C,EAAE;AAClD,MAAK,MAAM,CAAC,QAAQ,aAAa,OAAO,QAAQ,UAAU,aAAa,EAAE,CAAC,EAAE;EAC1E,MAAM,WAAW,YAAY,SAAS,GAClC,WACE,KACA,SAAS,KACV,GACD;AAEJ,MAAI,UAAU;GACZ,MAAM,cAAc,OAAO,KAAK,SAAS,WAAW,EAAE,CAAC,CAAC;GACxD,MAAM,UAAU,cAAc,SAAS,UAAU,eAAe;AAEhE,aAAU,UAAU;IAClB,aAAa,SAAS;IACtB,QAAQ,SAAS,SACb,kBAAkB,KAAK,QAAQ,OAAwB,GACvD;IACJ;IACD;;;CAKL,MAAM,mBAAoB,YACxB;AAGF,QAAO;EACL,aAAa,UAAU,eAAe,oBAAoB,QAAQ,KAAK;EACvE;EACA;EACA,SAAS,UAAU;EACnB,aAAa,UAAU;EACvB,MAAM,UAAU,QAAQ,EAAE;EAC1B,YAAY,OAAO;EACnB,aAAa,OAAO;EACpB,cAAc,OAAO;EACrB,cAAc,OAAO;EACrB;EACA;EACA,YAAY,UAAU,cAAc;EACpC,UAAU,UAAU;EACpB;EACD"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { dereferenceSchema, isReference, resolveRef } from "./resolvers.js";
|
|
2
|
+
|
|
3
|
+
//#region src/openapi/parser/parameters.ts
|
|
4
|
+
/**
|
|
5
|
+
* Parse parameters from an operation.
|
|
6
|
+
*/
|
|
7
|
+
function parseParameters(doc, params) {
|
|
8
|
+
const result = {
|
|
9
|
+
path: [],
|
|
10
|
+
query: [],
|
|
11
|
+
header: [],
|
|
12
|
+
cookie: []
|
|
13
|
+
};
|
|
14
|
+
if (!params) return result;
|
|
15
|
+
for (const param of params) {
|
|
16
|
+
let resolved;
|
|
17
|
+
if (isReference(param)) {
|
|
18
|
+
const ref = resolveRef(doc, param.$ref);
|
|
19
|
+
if (!ref) continue;
|
|
20
|
+
resolved = ref;
|
|
21
|
+
} else resolved = param;
|
|
22
|
+
const parsed = {
|
|
23
|
+
name: resolved.name,
|
|
24
|
+
in: resolved.in,
|
|
25
|
+
required: resolved.required ?? resolved.in === "path",
|
|
26
|
+
description: resolved.description,
|
|
27
|
+
schema: dereferenceSchema(doc, resolved.schema),
|
|
28
|
+
deprecated: resolved.deprecated ?? false
|
|
29
|
+
};
|
|
30
|
+
result[resolved.in]?.push(parsed);
|
|
31
|
+
}
|
|
32
|
+
return result;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
//#endregion
|
|
36
|
+
export { parseParameters };
|
|
37
|
+
//# sourceMappingURL=parameters.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parameters.js","names":["resolved: OpenAPIV3.ParameterObject | OpenAPIV3_1.ParameterObject","parsed: ParsedParameter"],"sources":["../../../src/openapi/parser/parameters.ts"],"sourcesContent":["import type {\n OpenApiDocument,\n OpenApiParameter,\n ParsedParameter,\n OpenApiSchema,\n} from '../types';\nimport type { OpenAPIV3, OpenAPIV3_1 } from 'openapi-types';\nimport { isReference, resolveRef, dereferenceSchema } from './resolvers';\n\n/**\n * Parse parameters from an operation.\n */\nexport function parseParameters(\n doc: OpenApiDocument,\n params: OpenApiParameter[] | undefined\n): {\n path: ParsedParameter[];\n query: ParsedParameter[];\n header: ParsedParameter[];\n cookie: ParsedParameter[];\n} {\n const result = {\n path: [] as ParsedParameter[],\n query: [] as ParsedParameter[],\n header: [] as ParsedParameter[],\n cookie: [] as ParsedParameter[],\n };\n\n if (!params) return result;\n\n for (const param of params) {\n let resolved: OpenAPIV3.ParameterObject | OpenAPIV3_1.ParameterObject;\n\n if (isReference(param)) {\n const ref = resolveRef<\n OpenAPIV3.ParameterObject | OpenAPIV3_1.ParameterObject\n >(doc, param.$ref);\n if (!ref) continue;\n resolved = ref;\n } else {\n resolved = param;\n }\n\n const parsed: ParsedParameter = {\n name: resolved.name,\n in: resolved.in as ParsedParameter['in'],\n required: resolved.required ?? resolved.in === 'path',\n description: resolved.description,\n schema: dereferenceSchema(\n doc,\n resolved.schema as OpenApiSchema\n ) as OpenApiSchema,\n deprecated: resolved.deprecated ?? false,\n };\n\n result[resolved.in as keyof typeof result]?.push(parsed);\n }\n\n return result;\n}\n"],"mappings":";;;;;;AAYA,SAAgB,gBACd,KACA,QAMA;CACA,MAAM,SAAS;EACb,MAAM,EAAE;EACR,OAAO,EAAE;EACT,QAAQ,EAAE;EACV,QAAQ,EAAE;EACX;AAED,KAAI,CAAC,OAAQ,QAAO;AAEpB,MAAK,MAAM,SAAS,QAAQ;EAC1B,IAAIA;AAEJ,MAAI,YAAY,MAAM,EAAE;GACtB,MAAM,MAAM,WAEV,KAAK,MAAM,KAAK;AAClB,OAAI,CAAC,IAAK;AACV,cAAW;QAEX,YAAW;EAGb,MAAMC,SAA0B;GAC9B,MAAM,SAAS;GACf,IAAI,SAAS;GACb,UAAU,SAAS,YAAY,SAAS,OAAO;GAC/C,aAAa,SAAS;GACtB,QAAQ,kBACN,KACA,SAAS,OACV;GACD,YAAY,SAAS,cAAc;GACpC;AAED,SAAO,SAAS,KAA4B,KAAK,OAAO;;AAG1D,QAAO"}
|