@contractkit/openapi-to-ck 0.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build$colon$ci.log +40 -0
- package/.turbo/turbo-build.log +20 -0
- package/.turbo/turbo-format.log +36 -0
- package/.turbo/turbo-test$colon$ci.log +77 -0
- package/.turbo/turbo-test.log +19 -0
- package/CHANGELOG.md +108 -0
- package/coverage/base.css +224 -0
- package/coverage/block-navigation.js +87 -0
- package/coverage/clover.xml +878 -0
- package/coverage/coverage-final.json +10 -0
- package/coverage/favicon.png +0 -0
- package/coverage/index.html +131 -0
- package/coverage/prettify.css +1 -0
- package/coverage/prettify.js +2 -0
- package/coverage/sort-arrow-sprite.png +0 -0
- package/coverage/sorter.js +210 -0
- package/coverage/src/ast-to-ck.ts.html +1336 -0
- package/coverage/src/circular-refs.ts.html +298 -0
- package/coverage/src/convert.ts.html +535 -0
- package/coverage/src/index.html +221 -0
- package/coverage/src/normalize.ts.html +1162 -0
- package/coverage/src/paths-to-ast.ts.html +1165 -0
- package/coverage/src/schema-to-ast.ts.html +1378 -0
- package/coverage/src/tag-splitter.ts.html +685 -0
- package/coverage/src/warnings.ts.html +154 -0
- package/coverage/tests/helpers.ts.html +559 -0
- package/coverage/tests/index.html +116 -0
- package/dist/ast-to-ck.d.ts +8 -0
- package/dist/ast-to-ck.d.ts.map +1 -0
- package/dist/chunk-CQGFQKBJ.js +1681 -0
- package/dist/chunk-CQGFQKBJ.js.map +1 -0
- package/dist/chunk-FNUU2DWY.js +1779 -0
- package/dist/chunk-FNUU2DWY.js.map +1 -0
- package/dist/chunk-LD2HAFZG.js +1681 -0
- package/dist/chunk-LD2HAFZG.js.map +1 -0
- package/dist/chunk-LQ2B3EJG.js +1777 -0
- package/dist/chunk-LQ2B3EJG.js.map +1 -0
- package/dist/chunk-M6JA6WY2.js +1714 -0
- package/dist/chunk-M6JA6WY2.js.map +1 -0
- package/dist/chunk-MQTKLXTN.js +1681 -0
- package/dist/chunk-MQTKLXTN.js.map +1 -0
- package/dist/chunk-NV7RGUUS.js +1699 -0
- package/dist/chunk-NV7RGUUS.js.map +1 -0
- package/dist/chunk-REM25FDE.js +1779 -0
- package/dist/chunk-REM25FDE.js.map +1 -0
- package/dist/chunk-SNW7GJOM.js +1681 -0
- package/dist/chunk-SNW7GJOM.js.map +1 -0
- package/dist/chunk-UWOSCBRG.js +1681 -0
- package/dist/chunk-UWOSCBRG.js.map +1 -0
- package/dist/chunk-YP7FWA4H.js +1779 -0
- package/dist/chunk-YP7FWA4H.js.map +1 -0
- package/dist/circular-refs.d.ts +12 -0
- package/dist/circular-refs.d.ts.map +1 -0
- package/dist/convert.d.ts +6 -0
- package/dist/convert.d.ts.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +29 -0
- package/dist/index.js.map +1 -0
- package/dist/normalize.d.ts +12 -0
- package/dist/normalize.d.ts.map +1 -0
- package/dist/paths-to-ast.d.ts +22 -0
- package/dist/paths-to-ast.d.ts.map +1 -0
- package/dist/plugin.d.ts +4 -0
- package/dist/plugin.d.ts.map +1 -0
- package/dist/plugin.js +86 -0
- package/dist/plugin.js.map +1 -0
- package/dist/schema-to-ast.d.ts +39 -0
- package/dist/schema-to-ast.d.ts.map +1 -0
- package/dist/tag-splitter.d.ts +16 -0
- package/dist/tag-splitter.d.ts.map +1 -0
- package/dist/types.d.ts +137 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/warnings.d.ts +10 -0
- package/dist/warnings.d.ts.map +1 -0
- package/eslint.config.js +6 -0
- package/package.json +46 -0
- package/src/ast-to-ck.ts +417 -0
- package/src/circular-refs.ts +71 -0
- package/src/convert.ts +150 -0
- package/src/index.ts +8 -0
- package/src/normalize.ts +359 -0
- package/src/paths-to-ast.ts +360 -0
- package/src/plugin.ts +89 -0
- package/src/schema-to-ast.ts +431 -0
- package/src/tag-splitter.ts +200 -0
- package/src/types.ts +133 -0
- package/src/warnings.ts +23 -0
- package/tests/ast-to-ck.test.ts +425 -0
- package/tests/circular-refs.test.ts +71 -0
- package/tests/convert.test.ts +330 -0
- package/tests/fixtures/petstore-3.1.json +187 -0
- package/tests/helpers.ts +158 -0
- package/tests/normalize.test.ts +114 -0
- package/tests/schema-to-ast.test.ts +341 -0
- package/tests/tag-splitter.test.ts +75 -0
- package/tsconfig.json +9 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tag-splitter.d.ts","sourceRoot":"","sources":["../src/tag-splitter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,WAAW,EAAoB,MAAM,mBAAmB,CAAC;AAE9F;;;;;;;;GAQG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,SAAS,EAAE,EAAE,MAAM,EAAE,WAAW,EAAE,EAAE,SAAS,EAAE,GAAG,CAAC,WAAW,EAAE,MAAM,CAAC,GAAG,GAAG,CAAC,MAAM,EAAE,UAAU,CAAC,CAyFnI;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,SAAS,EAAE,EAAE,MAAM,EAAE,WAAW,EAAE,EAAE,QAAQ,GAAE,MAAc,GAAG,UAAU,CAShH"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
export interface ConvertOptions {
|
|
2
|
+
/** File path, JSON/YAML string, or pre-parsed OpenAPI document object. */
|
|
3
|
+
input: string | Record<string, unknown>;
|
|
4
|
+
/** Output mode: single .ck file or split by OpenAPI tag. Default: 'by-tag'. */
|
|
5
|
+
split?: 'single' | 'by-tag';
|
|
6
|
+
/** Emit OpenAPI descriptions as # comments. Default: true. */
|
|
7
|
+
includeComments?: boolean;
|
|
8
|
+
/** Called for each warning during conversion. */
|
|
9
|
+
onWarning?: (warning: Warning) => void;
|
|
10
|
+
}
|
|
11
|
+
export interface ConvertResult {
|
|
12
|
+
/** Map of filename -> .ck source text. */
|
|
13
|
+
files: Map<string, string>;
|
|
14
|
+
/** All warnings collected during conversion. */
|
|
15
|
+
warnings: Warning[];
|
|
16
|
+
}
|
|
17
|
+
export interface Warning {
|
|
18
|
+
/** JSON pointer path into the OpenAPI spec (e.g. "#/components/schemas/Foo"). */
|
|
19
|
+
path: string;
|
|
20
|
+
/** Human-readable description of the issue. */
|
|
21
|
+
message: string;
|
|
22
|
+
/** Severity level. */
|
|
23
|
+
severity: 'info' | 'warn';
|
|
24
|
+
}
|
|
25
|
+
/** Normalized OpenAPI 3.1 schema object (subset of fields we use). */
|
|
26
|
+
export interface NormalizedSchema {
|
|
27
|
+
type?: string | string[];
|
|
28
|
+
format?: string;
|
|
29
|
+
items?: NormalizedSchema;
|
|
30
|
+
prefixItems?: NormalizedSchema[];
|
|
31
|
+
properties?: Record<string, NormalizedSchema>;
|
|
32
|
+
additionalProperties?: boolean | NormalizedSchema;
|
|
33
|
+
required?: string[];
|
|
34
|
+
enum?: unknown[];
|
|
35
|
+
const?: unknown;
|
|
36
|
+
oneOf?: NormalizedSchema[];
|
|
37
|
+
anyOf?: NormalizedSchema[];
|
|
38
|
+
allOf?: NormalizedSchema[];
|
|
39
|
+
$ref?: string;
|
|
40
|
+
nullable?: boolean;
|
|
41
|
+
readOnly?: boolean;
|
|
42
|
+
writeOnly?: boolean;
|
|
43
|
+
deprecated?: boolean;
|
|
44
|
+
default?: unknown;
|
|
45
|
+
description?: string;
|
|
46
|
+
minLength?: number;
|
|
47
|
+
maxLength?: number;
|
|
48
|
+
pattern?: string;
|
|
49
|
+
minimum?: number;
|
|
50
|
+
maximum?: number;
|
|
51
|
+
minItems?: number;
|
|
52
|
+
maxItems?: number;
|
|
53
|
+
discriminator?: {
|
|
54
|
+
propertyName?: string;
|
|
55
|
+
mapping?: Record<string, string>;
|
|
56
|
+
};
|
|
57
|
+
xml?: unknown;
|
|
58
|
+
externalDocs?: unknown;
|
|
59
|
+
not?: unknown;
|
|
60
|
+
}
|
|
61
|
+
/** Normalized OpenAPI 3.1 document (post-upgrade, post-dereference). */
|
|
62
|
+
export interface NormalizedDocument {
|
|
63
|
+
openapi: string;
|
|
64
|
+
info: {
|
|
65
|
+
title: string;
|
|
66
|
+
version: string;
|
|
67
|
+
description?: string;
|
|
68
|
+
};
|
|
69
|
+
paths?: Record<string, NormalizedPathItem>;
|
|
70
|
+
components?: {
|
|
71
|
+
schemas?: Record<string, NormalizedSchema>;
|
|
72
|
+
securitySchemes?: Record<string, unknown>;
|
|
73
|
+
};
|
|
74
|
+
security?: Record<string, string[]>[];
|
|
75
|
+
servers?: {
|
|
76
|
+
url: string;
|
|
77
|
+
description?: string;
|
|
78
|
+
}[];
|
|
79
|
+
tags?: {
|
|
80
|
+
name: string;
|
|
81
|
+
description?: string;
|
|
82
|
+
}[];
|
|
83
|
+
}
|
|
84
|
+
export interface NormalizedPathItem {
|
|
85
|
+
summary?: string;
|
|
86
|
+
description?: string;
|
|
87
|
+
parameters?: NormalizedParameter[];
|
|
88
|
+
get?: NormalizedOperation;
|
|
89
|
+
post?: NormalizedOperation;
|
|
90
|
+
put?: NormalizedOperation;
|
|
91
|
+
patch?: NormalizedOperation;
|
|
92
|
+
delete?: NormalizedOperation;
|
|
93
|
+
head?: NormalizedOperation;
|
|
94
|
+
options?: NormalizedOperation;
|
|
95
|
+
trace?: NormalizedOperation;
|
|
96
|
+
}
|
|
97
|
+
export interface NormalizedOperation {
|
|
98
|
+
operationId?: string;
|
|
99
|
+
summary?: string;
|
|
100
|
+
description?: string;
|
|
101
|
+
tags?: string[];
|
|
102
|
+
parameters?: NormalizedParameter[];
|
|
103
|
+
requestBody?: NormalizedRequestBody;
|
|
104
|
+
responses?: Record<string, NormalizedResponse>;
|
|
105
|
+
security?: Record<string, string[]>[];
|
|
106
|
+
deprecated?: boolean;
|
|
107
|
+
}
|
|
108
|
+
export interface NormalizedParameter {
|
|
109
|
+
name: string;
|
|
110
|
+
in: 'path' | 'query' | 'header' | 'cookie';
|
|
111
|
+
required?: boolean;
|
|
112
|
+
description?: string;
|
|
113
|
+
deprecated?: boolean;
|
|
114
|
+
schema?: NormalizedSchema;
|
|
115
|
+
}
|
|
116
|
+
export interface NormalizedRequestBody {
|
|
117
|
+
description?: string;
|
|
118
|
+
required?: boolean;
|
|
119
|
+
content?: Record<string, {
|
|
120
|
+
schema?: NormalizedSchema;
|
|
121
|
+
}>;
|
|
122
|
+
}
|
|
123
|
+
export interface NormalizedResponse {
|
|
124
|
+
description?: string;
|
|
125
|
+
content?: Record<string, {
|
|
126
|
+
schema?: NormalizedSchema;
|
|
127
|
+
}>;
|
|
128
|
+
/** OpenAPI Header Objects keyed by header name (case-insensitive on the wire). */
|
|
129
|
+
headers?: Record<string, NormalizedHeader>;
|
|
130
|
+
}
|
|
131
|
+
export interface NormalizedHeader {
|
|
132
|
+
description?: string;
|
|
133
|
+
required?: boolean;
|
|
134
|
+
deprecated?: boolean;
|
|
135
|
+
schema?: NormalizedSchema;
|
|
136
|
+
}
|
|
137
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,cAAc;IAC3B,0EAA0E;IAC1E,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACxC,+EAA+E;IAC/E,KAAK,CAAC,EAAE,QAAQ,GAAG,QAAQ,CAAC;IAC5B,8DAA8D;IAC9D,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,iDAAiD;IACjD,SAAS,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI,CAAC;CAC1C;AAED,MAAM,WAAW,aAAa;IAC1B,0CAA0C;IAC1C,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC3B,gDAAgD;IAChD,QAAQ,EAAE,OAAO,EAAE,CAAC;CACvB;AAED,MAAM,WAAW,OAAO;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,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE;QAAE,MAAM,CAAC,EAAE,gBAAgB,CAAA;KAAE,CAAC,CAAC;IACxD,kFAAkF;IAClF,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC;CAC9C;AAED,MAAM,WAAW,gBAAgB;IAC7B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,MAAM,CAAC,EAAE,gBAAgB,CAAC;CAC7B"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Warning } from './types.js';
|
|
2
|
+
export declare class WarningCollector {
|
|
3
|
+
readonly warnings: Warning[];
|
|
4
|
+
private onWarning?;
|
|
5
|
+
constructor(onWarning?: (w: Warning) => void);
|
|
6
|
+
warn(path: string, message: string): void;
|
|
7
|
+
info(path: string, message: string): void;
|
|
8
|
+
private add;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=warnings.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"warnings.d.ts","sourceRoot":"","sources":["../src/warnings.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAE1C,qBAAa,gBAAgB;IACzB,QAAQ,CAAC,QAAQ,EAAE,OAAO,EAAE,CAAM;IAClC,OAAO,CAAC,SAAS,CAAC,CAAuB;gBAE7B,SAAS,CAAC,EAAE,CAAC,CAAC,EAAE,OAAO,KAAK,IAAI;IAI5C,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI;IAIzC,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI;IAIzC,OAAO,CAAC,GAAG;CAId"}
|
package/eslint.config.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@contractkit/openapi-to-ck",
|
|
3
|
+
"version": "0.7.1",
|
|
4
|
+
"description": "Convert OpenAPI specs (2.0/3.0/3.1) to Contract Kit .ck files",
|
|
5
|
+
"author": {
|
|
6
|
+
"name": "Marooned Software",
|
|
7
|
+
"url": "https://github.com/MaroonedSoftware/contractkit"
|
|
8
|
+
},
|
|
9
|
+
"bugs": {
|
|
10
|
+
"url": "https://github.com/MaroonedSoftware/contractkit/issues"
|
|
11
|
+
},
|
|
12
|
+
"homepage": "https://github.com/MaroonedSoftware/contractkit/packages/openapi-to-ck#readme",
|
|
13
|
+
"keywords": [
|
|
14
|
+
"contractkit",
|
|
15
|
+
"openapi"
|
|
16
|
+
],
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "https://github.com/MaroonedSoftware/contractkit.git"
|
|
20
|
+
},
|
|
21
|
+
"type": "module",
|
|
22
|
+
"main": "./dist/index.js",
|
|
23
|
+
"module": "./dist/index.js",
|
|
24
|
+
"types": "./dist/index.d.ts",
|
|
25
|
+
"exports": {
|
|
26
|
+
".": "./dist/index.js",
|
|
27
|
+
"./plugin": "./dist/plugin.js"
|
|
28
|
+
},
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"@scalar/openapi-parser": "^0.26.1",
|
|
31
|
+
"yaml": "^2.8.3",
|
|
32
|
+
"@contractkit/core": "0.11.0"
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"@repo/config-eslint": "0.3.1",
|
|
36
|
+
"@repo/config-typescript": "0.1.0"
|
|
37
|
+
},
|
|
38
|
+
"scripts": {
|
|
39
|
+
"build": "tsup src/index.ts src/plugin.ts --format esm --sourcemap --dts && tsc --emitDeclarationOnly --declaration",
|
|
40
|
+
"build:ci": "eslint --max-warnings=0 && pnpm run build",
|
|
41
|
+
"lint": "eslint --fix",
|
|
42
|
+
"format": "prettier --write .",
|
|
43
|
+
"test": "vitest run",
|
|
44
|
+
"test:ci": "vitest run --coverage"
|
|
45
|
+
}
|
|
46
|
+
}
|
package/src/ast-to-ck.ts
ADDED
|
@@ -0,0 +1,417 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
CkRootNode,
|
|
3
|
+
ModelNode,
|
|
4
|
+
FieldNode,
|
|
5
|
+
ContractTypeNode,
|
|
6
|
+
OpRouteNode,
|
|
7
|
+
OpOperationNode,
|
|
8
|
+
OpRequestNode,
|
|
9
|
+
OpResponseNode,
|
|
10
|
+
ParamSource,
|
|
11
|
+
SecurityNode,
|
|
12
|
+
SecurityFields,
|
|
13
|
+
ObjectMode,
|
|
14
|
+
RouteModifier,
|
|
15
|
+
} from '@contractkit/core';
|
|
16
|
+
|
|
17
|
+
const INDENT = ' '; // 4 spaces
|
|
18
|
+
|
|
19
|
+
// ─── Public API ───────────────────────────────────────────────────────────
|
|
20
|
+
|
|
21
|
+
export interface SerializeOptions {
|
|
22
|
+
/** Emit descriptions as inline # comments. Default: true. */
|
|
23
|
+
includeComments?: boolean;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function astToCk(root: CkRootNode, options: SerializeOptions = {}): string {
|
|
27
|
+
const { includeComments = true } = options;
|
|
28
|
+
const ctx: Ctx = { includeComments };
|
|
29
|
+
const parts: string[] = [];
|
|
30
|
+
|
|
31
|
+
// Options block
|
|
32
|
+
const optionsBlock = serializeOptions(root);
|
|
33
|
+
if (optionsBlock) parts.push(optionsBlock);
|
|
34
|
+
|
|
35
|
+
// Models
|
|
36
|
+
for (const model of root.models) {
|
|
37
|
+
parts.push(serializeModel(model, ctx));
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// Routes
|
|
41
|
+
for (const route of root.routes) {
|
|
42
|
+
parts.push(serializeRoute(route, ctx));
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return parts.join('\n\n') + '\n';
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// ─── Context ──────────────────────────────────────────────────────────────
|
|
49
|
+
|
|
50
|
+
interface Ctx {
|
|
51
|
+
includeComments: boolean;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// ─── Options block ────────────────────────────────────────────────────────
|
|
55
|
+
|
|
56
|
+
function serializeOptions(root: CkRootNode): string | null {
|
|
57
|
+
const hasKeys = Object.keys(root.meta).length > 0;
|
|
58
|
+
const hasServices = root.services && Object.keys(root.services).length > 0;
|
|
59
|
+
const hasSecurity = root.security !== undefined;
|
|
60
|
+
|
|
61
|
+
if (!hasKeys && !hasServices && !hasSecurity) return null;
|
|
62
|
+
|
|
63
|
+
const lines: string[] = ['options {'];
|
|
64
|
+
|
|
65
|
+
if (hasKeys) {
|
|
66
|
+
lines.push(`${INDENT}keys: {`);
|
|
67
|
+
for (const [key, value] of Object.entries(root.meta)) {
|
|
68
|
+
lines.push(`${INDENT}${INDENT}${key}: ${value}`);
|
|
69
|
+
}
|
|
70
|
+
lines.push(`${INDENT}}`);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (hasServices) {
|
|
74
|
+
lines.push(`${INDENT}services: {`);
|
|
75
|
+
for (const [name, path] of Object.entries(root.services)) {
|
|
76
|
+
lines.push(`${INDENT}${INDENT}${name}: "${path}"`);
|
|
77
|
+
}
|
|
78
|
+
lines.push(`${INDENT}}`);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if (hasSecurity) {
|
|
82
|
+
lines.push(`${INDENT}security: {`);
|
|
83
|
+
if (root.security === 'none') {
|
|
84
|
+
lines.push(`${INDENT}${INDENT}none`);
|
|
85
|
+
} else {
|
|
86
|
+
const sec = root.security as SecurityFields;
|
|
87
|
+
if (sec.roles && sec.roles.length > 0) {
|
|
88
|
+
lines.push(`${INDENT}${INDENT}roles: [${sec.roles.join(', ')}]`);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
lines.push(`${INDENT}}`);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
lines.push('}');
|
|
95
|
+
return lines.join('\n');
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// ─── Models ───────────────────────────────────────────────────────────────
|
|
99
|
+
|
|
100
|
+
function serializeModel(model: ModelNode, ctx: Ctx): string {
|
|
101
|
+
const parts: string[] = [];
|
|
102
|
+
|
|
103
|
+
// Modifiers: format(input=snake) mode(loose) deprecated
|
|
104
|
+
const prefixes: string[] = [];
|
|
105
|
+
if (model.inputCase && model.inputCase !== 'camel') {
|
|
106
|
+
prefixes.push(`format(input=${model.inputCase})`);
|
|
107
|
+
}
|
|
108
|
+
if (model.mode && model.mode !== 'strict') {
|
|
109
|
+
prefixes.push(`mode(${model.mode})`);
|
|
110
|
+
}
|
|
111
|
+
if (model.deprecated) {
|
|
112
|
+
prefixes.push('deprecated');
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const prefix = prefixes.length > 0 ? prefixes.join(' ') + ' ' : '';
|
|
116
|
+
const comment = ctx.includeComments && model.description ? ` # ${model.description}` : '';
|
|
117
|
+
|
|
118
|
+
// Type alias: contract Name: typeExpression
|
|
119
|
+
if (model.type) {
|
|
120
|
+
parts.push(`contract ${prefix}${model.name}: ${serializeType(model.type)}${comment}`);
|
|
121
|
+
return parts.join('');
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// Inheritance: contract Name: Base1 & Base2 & { ... }
|
|
125
|
+
if (model.bases && model.bases.length > 0) {
|
|
126
|
+
parts.push(`contract ${prefix}${model.name}: ${model.bases.join(' & ')} & {${comment}`);
|
|
127
|
+
} else {
|
|
128
|
+
parts.push(`contract ${prefix}${model.name}: {${comment}`);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
for (const field of model.fields) {
|
|
132
|
+
parts.push(serializeField(field, 1, ctx));
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
parts.push('}');
|
|
136
|
+
return parts.join('\n');
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function serializeField(field: FieldNode, depth: number, ctx: Ctx): string {
|
|
140
|
+
const indent = INDENT.repeat(depth);
|
|
141
|
+
const optional = field.optional ? '?' : '';
|
|
142
|
+
const visibility = field.visibility !== 'normal' ? `${field.visibility} ` : '';
|
|
143
|
+
const deprecated = field.deprecated ? 'deprecated ' : '';
|
|
144
|
+
|
|
145
|
+
let typeStr = serializeType(field.type);
|
|
146
|
+
|
|
147
|
+
// Nullable fields: if the type doesn't already contain null, append `| null`
|
|
148
|
+
if (field.nullable && !typeContainsNull(field.type)) {
|
|
149
|
+
typeStr = `${typeStr} | null`;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
const defaultVal = field.default !== undefined ? ` = ${serializeDefault(field.default)}` : '';
|
|
153
|
+
const comment = ctx.includeComments && field.description ? ` # ${field.description}` : '';
|
|
154
|
+
|
|
155
|
+
return `${indent}${field.name}${optional}: ${deprecated}${visibility}${typeStr}${defaultVal}${comment}`;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
function typeContainsNull(type: ContractTypeNode): boolean {
|
|
159
|
+
if (type.kind === 'scalar' && type.name === 'null') return true;
|
|
160
|
+
if (type.kind === 'union') return type.members.some(typeContainsNull);
|
|
161
|
+
return false;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
function serializeDefault(value: string | number | boolean): string {
|
|
165
|
+
if (typeof value === 'string') {
|
|
166
|
+
// If it looks like an identifier (e.g. enum value), don't quote it
|
|
167
|
+
if (/^[a-zA-Z_$][a-zA-Z0-9_$\-.]*$/.test(value)) return value;
|
|
168
|
+
return `"${value}"`;
|
|
169
|
+
}
|
|
170
|
+
return String(value);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
// ─── Types ────────────────────────────────────────────────────────────────
|
|
174
|
+
|
|
175
|
+
export function serializeType(type: ContractTypeNode): string {
|
|
176
|
+
switch (type.kind) {
|
|
177
|
+
case 'scalar':
|
|
178
|
+
return serializeScalar(type);
|
|
179
|
+
case 'array':
|
|
180
|
+
return serializeArray(type);
|
|
181
|
+
case 'tuple':
|
|
182
|
+
return `tuple(${type.items.map(serializeType).join(', ')})`;
|
|
183
|
+
case 'record':
|
|
184
|
+
return `record(${serializeType(type.key)}, ${serializeType(type.value)})`;
|
|
185
|
+
case 'enum':
|
|
186
|
+
return `enum(${type.values.join(', ')})`;
|
|
187
|
+
case 'literal':
|
|
188
|
+
return serializeLiteral(type);
|
|
189
|
+
case 'union':
|
|
190
|
+
return type.members.map(serializeType).join(' | ');
|
|
191
|
+
case 'discriminatedUnion':
|
|
192
|
+
return `discriminated(by=${type.discriminator}, ${type.members.map(serializeType).join(' | ')})`;
|
|
193
|
+
case 'intersection':
|
|
194
|
+
return type.members.map(serializeType).join(' & ');
|
|
195
|
+
case 'ref':
|
|
196
|
+
return type.name;
|
|
197
|
+
case 'inlineObject':
|
|
198
|
+
return serializeInlineObject(type);
|
|
199
|
+
case 'lazy':
|
|
200
|
+
return `lazy(${serializeType(type.inner)})`;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
function serializeScalar(type: {
|
|
205
|
+
name: string;
|
|
206
|
+
min?: number | bigint | string;
|
|
207
|
+
max?: number | bigint | string;
|
|
208
|
+
len?: number;
|
|
209
|
+
regex?: string;
|
|
210
|
+
format?: string;
|
|
211
|
+
}): string {
|
|
212
|
+
const args: string[] = [];
|
|
213
|
+
if (type.len !== undefined) args.push(`length=${type.len}`);
|
|
214
|
+
if (type.min !== undefined) args.push(typeof type.min === 'string' ? `min="${type.min}"` : `min=${type.min}`);
|
|
215
|
+
if (type.max !== undefined) args.push(typeof type.max === 'string' ? `max="${type.max}"` : `max=${type.max}`);
|
|
216
|
+
if (type.regex !== undefined) args.push(`regex=${type.regex}`);
|
|
217
|
+
if (type.format !== undefined) args.push(`format=${type.format}`);
|
|
218
|
+
|
|
219
|
+
if (args.length === 0) return type.name;
|
|
220
|
+
return `${type.name}(${args.join(', ')})`;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
function serializeArray(type: { item: ContractTypeNode; min?: number; max?: number }): string {
|
|
224
|
+
const args: string[] = [serializeType(type.item)];
|
|
225
|
+
if (type.min !== undefined) args.push(`min=${type.min}`);
|
|
226
|
+
if (type.max !== undefined) args.push(`max=${type.max}`);
|
|
227
|
+
return `array(${args.join(', ')})`;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
function serializeLiteral(type: { value: string | number | boolean }): string {
|
|
231
|
+
if (typeof type.value === 'string') return `literal("${type.value}")`;
|
|
232
|
+
return `literal(${type.value})`;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
function serializeInlineObject(type: { fields: FieldNode[]; mode?: ObjectMode }): string {
|
|
236
|
+
const modePrefix = type.mode ? `mode(${type.mode}) ` : '';
|
|
237
|
+
if (type.fields.length === 0) return `${modePrefix}{}`;
|
|
238
|
+
|
|
239
|
+
const lines: string[] = [`${modePrefix}{`];
|
|
240
|
+
for (const field of type.fields) {
|
|
241
|
+
lines.push(serializeField(field, 2, { includeComments: true }));
|
|
242
|
+
}
|
|
243
|
+
lines.push(`${INDENT}}`);
|
|
244
|
+
return lines.join('\n');
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
// ─── Routes ───────────────────────────────────────────────────────────────
|
|
248
|
+
|
|
249
|
+
function serializeRoute(route: OpRouteNode, ctx: Ctx): string {
|
|
250
|
+
const lines: string[] = [];
|
|
251
|
+
|
|
252
|
+
const modStr = serializeModifiers(route.modifiers);
|
|
253
|
+
const comment = ctx.includeComments && route.description ? ` # ${route.description}` : '';
|
|
254
|
+
lines.push(`operation${modStr} ${route.path}: {${comment}`);
|
|
255
|
+
|
|
256
|
+
// Route-level params
|
|
257
|
+
if (route.params) {
|
|
258
|
+
serializeParamSource(lines, 'params', route.params, route.paramsMode, 1, ctx);
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
// Route-level security
|
|
262
|
+
if (route.security !== undefined) {
|
|
263
|
+
serializeSecurityBlock(lines, route.security, 1, ctx);
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
// Operations
|
|
267
|
+
for (const op of route.operations) {
|
|
268
|
+
serializeOperation(lines, op, 1, ctx);
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
lines.push('}');
|
|
272
|
+
return lines.join('\n');
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
function serializeOperation(lines: string[], op: OpOperationNode, depth: number, ctx: Ctx): string[] {
|
|
276
|
+
const indent = INDENT.repeat(depth);
|
|
277
|
+
const modStr = serializeModifiers(op.modifiers);
|
|
278
|
+
const comment = ctx.includeComments && op.description ? ` # ${op.description}` : '';
|
|
279
|
+
lines.push(`${indent}${op.method}${modStr}: {${comment}`);
|
|
280
|
+
|
|
281
|
+
const inner = INDENT.repeat(depth + 1);
|
|
282
|
+
|
|
283
|
+
// Service
|
|
284
|
+
if (op.service) {
|
|
285
|
+
lines.push(`${inner}service: ${op.service}`);
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
// SDK
|
|
289
|
+
if (op.sdk) {
|
|
290
|
+
lines.push(`${inner}sdk: ${op.sdk}`);
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
// Signature
|
|
294
|
+
if (op.signature) {
|
|
295
|
+
const sigComment = ctx.includeComments && op.signatureDescription ? ` # ${op.signatureDescription}` : '';
|
|
296
|
+
lines.push(`${inner}signature: ${op.signature}${sigComment}`);
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
// Security
|
|
300
|
+
if (op.security !== undefined) {
|
|
301
|
+
serializeSecurityBlock(lines, op.security, depth + 1, ctx);
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
// Query
|
|
305
|
+
if (op.query) {
|
|
306
|
+
serializeParamSource(lines, 'query', op.query, op.queryMode, depth + 1, ctx);
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
// Headers
|
|
310
|
+
if (op.headers) {
|
|
311
|
+
serializeParamSource(lines, 'headers', op.headers, op.headersMode, depth + 1, ctx);
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
// Request
|
|
315
|
+
if (op.request) {
|
|
316
|
+
serializeRequest(lines, op.request, depth + 1);
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
// Responses
|
|
320
|
+
if (op.responses.length > 0) {
|
|
321
|
+
serializeResponses(lines, op.responses, depth + 1);
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
lines.push(`${indent}}`);
|
|
325
|
+
return lines;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
function serializeModifiers(modifiers?: RouteModifier[]): string {
|
|
329
|
+
if (!modifiers || modifiers.length === 0) return '';
|
|
330
|
+
return `(${modifiers.join(', ')})`;
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
function serializeParamSource(lines: string[], keyword: string, source: ParamSource, mode: ObjectMode | undefined, depth: number, ctx: Ctx): void {
|
|
334
|
+
const indent = INDENT.repeat(depth);
|
|
335
|
+
|
|
336
|
+
// String reference: `query: TypeName`
|
|
337
|
+
if (source.kind === 'ref') {
|
|
338
|
+
lines.push(`${indent}${keyword}: ${source.name}`);
|
|
339
|
+
return;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
// ContractTypeNode reference
|
|
343
|
+
if (source.kind === 'type') {
|
|
344
|
+
lines.push(`${indent}${keyword}: ${serializeType(source.node)}`);
|
|
345
|
+
return;
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
// Inline param declarations: `params: { name: type }`
|
|
349
|
+
const modeStr = mode ? `mode(${mode}) ` : '';
|
|
350
|
+
lines.push(`${indent}${keyword}: ${modeStr}{`);
|
|
351
|
+
for (const param of source.nodes) {
|
|
352
|
+
const optional = param.optional ? '?' : '';
|
|
353
|
+
let typeStr = serializeType(param.type);
|
|
354
|
+
if (param.nullable && !typeContainsNull(param.type)) {
|
|
355
|
+
typeStr = `${typeStr} | null`;
|
|
356
|
+
}
|
|
357
|
+
const defaultVal = param.default !== undefined ? ` = ${serializeDefault(param.default)}` : '';
|
|
358
|
+
const comment = ctx.includeComments && param.description ? ` # ${param.description}` : '';
|
|
359
|
+
lines.push(`${INDENT.repeat(depth + 1)}${param.name}${optional}: ${typeStr}${defaultVal}${comment}`);
|
|
360
|
+
}
|
|
361
|
+
lines.push(`${indent}}`);
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
function serializeRequest(lines: string[], request: OpRequestNode, depth: number): void {
|
|
365
|
+
const indent = INDENT.repeat(depth);
|
|
366
|
+
lines.push(`${indent}request: {`);
|
|
367
|
+
for (const body of request.bodies) {
|
|
368
|
+
lines.push(`${INDENT.repeat(depth + 1)}${body.contentType}: ${serializeType(body.bodyType)}`);
|
|
369
|
+
}
|
|
370
|
+
lines.push(`${indent}}`);
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
function serializeResponses(lines: string[], responses: OpResponseNode[], depth: number): void {
|
|
374
|
+
const indent = INDENT.repeat(depth);
|
|
375
|
+
lines.push(`${indent}response: {`);
|
|
376
|
+
for (const resp of responses) {
|
|
377
|
+
const hasBody = resp.bodyType && resp.contentType;
|
|
378
|
+
const hasHeaders = resp.headers && resp.headers.length > 0;
|
|
379
|
+
if (hasBody || hasHeaders) {
|
|
380
|
+
lines.push(`${INDENT.repeat(depth + 1)}${resp.statusCode}: {`);
|
|
381
|
+
if (hasBody) {
|
|
382
|
+
lines.push(`${INDENT.repeat(depth + 2)}${resp.contentType}: ${serializeType(resp.bodyType!)}`);
|
|
383
|
+
}
|
|
384
|
+
if (hasHeaders) {
|
|
385
|
+
lines.push(`${INDENT.repeat(depth + 2)}headers: {`);
|
|
386
|
+
for (const h of resp.headers!) {
|
|
387
|
+
const opt = h.optional ? '?' : '';
|
|
388
|
+
const trail = h.description ? ` # ${h.description}` : '';
|
|
389
|
+
lines.push(`${INDENT.repeat(depth + 3)}${h.name}${opt}: ${serializeType(h.type)}${trail}`);
|
|
390
|
+
}
|
|
391
|
+
lines.push(`${INDENT.repeat(depth + 2)}}`);
|
|
392
|
+
}
|
|
393
|
+
lines.push(`${INDENT.repeat(depth + 1)}}`);
|
|
394
|
+
} else {
|
|
395
|
+
lines.push(`${INDENT.repeat(depth + 1)}${resp.statusCode}:`);
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
lines.push(`${indent}}`);
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
function serializeSecurityBlock(lines: string[], security: SecurityNode, depth: number, ctx: Ctx): void {
|
|
402
|
+
const indent = INDENT.repeat(depth);
|
|
403
|
+
if (security === 'none') {
|
|
404
|
+
lines.push(`${indent}security: none`);
|
|
405
|
+
return;
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
const sec = security as SecurityFields;
|
|
409
|
+
if (sec.roles && sec.roles.length > 0) {
|
|
410
|
+
const rolesComment = ctx.includeComments && sec.rolesDescription ? ` # ${sec.rolesDescription}` : '';
|
|
411
|
+
lines.push(`${indent}security: {`);
|
|
412
|
+
lines.push(`${INDENT.repeat(depth + 1)}roles: [${sec.roles.join(', ')}]${rolesComment}`);
|
|
413
|
+
lines.push(`${indent}}`);
|
|
414
|
+
} else {
|
|
415
|
+
lines.push(`${indent}security: {}`);
|
|
416
|
+
}
|
|
417
|
+
}
|