@f3liz/rescript-autogen-openapi 0.5.4 → 0.6.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.
- package/lib/es6/src/bindings/Handlebars.mjs +43 -0
- package/lib/es6/src/core/CodegenUtils.mjs +17 -39
- package/lib/es6/src/core/DocOverride.mjs +14 -123
- package/lib/es6/src/core/Templates.mjs +341 -0
- package/lib/es6/src/generators/ComponentSchemaGenerator.mjs +10 -4
- package/lib/es6/src/generators/DiffReportGenerator.mjs +12 -28
- package/lib/es6/src/generators/EndpointGenerator.mjs +25 -31
- package/lib/es6/src/generators/ModuleGenerator.mjs +29 -37
- package/lib/es6/src/generators/SchemaCodeGenerator.mjs +10 -7
- package/lib/es6/src/generators/ThinWrapperGenerator.mjs +21 -24
- package/lib/es6/src/generators/TypeScriptDtsGenerator.mjs +52 -58
- package/lib/es6/src/generators/TypeScriptWrapperGenerator.mjs +76 -80
- package/package.json +2 -1
- package/src/bindings/Handlebars.res +43 -0
- package/src/core/CodegenUtils.res +9 -33
- package/src/core/DocOverride.res +10 -124
- package/src/core/Templates.res +330 -0
- package/src/generators/ComponentSchemaGenerator.res +8 -4
- package/src/generators/DiffReportGenerator.res +11 -29
- package/src/generators/EndpointGenerator.res +32 -28
- package/src/generators/ModuleGenerator.res +41 -39
- package/src/generators/SchemaCodeGenerator.res +8 -6
- package/src/generators/ThinWrapperGenerator.res +24 -24
- package/src/generators/TypeScriptDtsGenerator.res +41 -61
- package/src/generators/TypeScriptWrapperGenerator.res +58 -83
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
2
|
|
|
3
|
+
import * as Templates from "../core/Templates.mjs";
|
|
4
|
+
import * as Handlebars from "../bindings/Handlebars.mjs";
|
|
3
5
|
import * as SpecDiffer from "../core/SpecDiffer.mjs";
|
|
4
|
-
import * as CodegenUtils from "../core/CodegenUtils.mjs";
|
|
5
6
|
import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.js";
|
|
6
7
|
import * as Primitive_string from "@rescript/runtime/lib/es6/Primitive_string.js";
|
|
7
8
|
|
|
@@ -84,32 +85,15 @@ function generateCompactSummary(diff) {
|
|
|
84
85
|
}
|
|
85
86
|
|
|
86
87
|
function generateMergeReport(stats, baseName, forkName) {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|- **Shared Endpoints**: ` + sharedEndpoints + `
|
|
97
|
-
|- **Shared Schemas**: ` + sharedSchemas + `
|
|
98
|
-
|
|
|
99
|
-
|## ` + forkName + ` Extensions
|
|
100
|
-
|
|
|
101
|
-
|- **Extension Endpoints**: ` + extensionEndpoints + `
|
|
102
|
-
|- **Extension Schemas**: ` + extensionSchemas + `
|
|
103
|
-
|
|
|
104
|
-
|## Summary
|
|
105
|
-
|
|
|
106
|
-
|The shared base contains ` + sharedEndpoints + ` endpoints and ` + sharedSchemas + ` schemas.
|
|
107
|
-
|
|
|
108
|
-
|` + forkName + ` adds ` + extensionEndpoints + ` endpoints and ` + extensionSchemas + ` schemas.
|
|
109
|
-
|
|
|
110
|
-
|---
|
|
111
|
-
|*Generated on ` + new Date().toISOString() + `*
|
|
112
|
-
|`, undefined);
|
|
88
|
+
return Handlebars.render(Templates.mergeReport, {
|
|
89
|
+
baseName: baseName,
|
|
90
|
+
forkName: forkName,
|
|
91
|
+
sharedEndpoints: stats.sharedEndpointCount.toString(),
|
|
92
|
+
sharedSchemas: stats.sharedSchemaCount.toString(),
|
|
93
|
+
extensionEndpoints: stats.forkExtensionCount.toString(),
|
|
94
|
+
extensionSchemas: stats.forkSchemaCount.toString(),
|
|
95
|
+
timestamp: new Date().toISOString()
|
|
96
|
+
});
|
|
113
97
|
}
|
|
114
98
|
|
|
115
99
|
function generateEndpointsByTagReport(endpoints) {
|
|
@@ -152,4 +136,4 @@ export {
|
|
|
152
136
|
generateMergeReport,
|
|
153
137
|
generateEndpointsByTagReport,
|
|
154
138
|
}
|
|
155
|
-
/*
|
|
139
|
+
/* Handlebars Not a pure module */
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
2
|
|
|
3
|
+
import * as Templates from "../core/Templates.mjs";
|
|
4
|
+
import * as Handlebars from "../bindings/Handlebars.mjs";
|
|
3
5
|
import * as DocOverride from "../core/DocOverride.mjs";
|
|
4
6
|
import * as CodegenUtils from "../core/CodegenUtils.mjs";
|
|
5
7
|
import * as Stdlib_Array from "@rescript/runtime/lib/es6/Stdlib_Array.js";
|
|
@@ -85,22 +87,18 @@ function generateEndpointFunction(endpoint, overrideDir, moduleName) {
|
|
|
85
87
|
description = endpoint.description;
|
|
86
88
|
}
|
|
87
89
|
let docComment = CodegenUtils.generateDocString(endpoint.summary, description, undefined);
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
| ->Promise.resolve
|
|
101
|
-
| })
|
|
102
|
-
|}`;
|
|
103
|
-
return CodegenUtils.trimMargin(code, undefined);
|
|
90
|
+
return Handlebars.render(Templates.endpointFunction, {
|
|
91
|
+
docComment: docComment,
|
|
92
|
+
functionName: functionName,
|
|
93
|
+
bodyParam: bodyParam,
|
|
94
|
+
paramSep: paramSep,
|
|
95
|
+
fetchTypeSignature: CodegenUtils.fetchTypeSignature,
|
|
96
|
+
bodyValueConversion: bodyValueConversion,
|
|
97
|
+
path: endpoint.path,
|
|
98
|
+
methodUpper: endpoint.method.toUpperCase(),
|
|
99
|
+
bodyArg: hasRequestBody ? "Some(jsonBody)" : "None",
|
|
100
|
+
responseHandling: responseHandling
|
|
101
|
+
});
|
|
104
102
|
}
|
|
105
103
|
|
|
106
104
|
function generateEndpointCode(endpoint, overrideDir, moduleName, modulePrefixOpt) {
|
|
@@ -132,26 +130,22 @@ function generateEndpointModule(endpoint, modulePrefixOpt) {
|
|
|
132
130
|
let modulePrefix = modulePrefixOpt !== undefined ? modulePrefixOpt : "";
|
|
133
131
|
let functionName = CodegenUtils.generateOperationName(endpoint.operationId, endpoint.path, endpoint.method);
|
|
134
132
|
let header = CodegenUtils.generateFileHeader(Stdlib_Option.getOr(endpoint.summary, `API: ` + endpoint.path));
|
|
135
|
-
return
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|}
|
|
141
|
-
|`, undefined);
|
|
133
|
+
return Handlebars.render(Templates.moduleWrapped, {
|
|
134
|
+
header: header.trimEnd(),
|
|
135
|
+
moduleName: JsConvertCase.toPascalCase(functionName),
|
|
136
|
+
body: CodegenUtils.indent(generateEndpointCode(endpoint, undefined, undefined, modulePrefix), 2)
|
|
137
|
+
});
|
|
142
138
|
}
|
|
143
139
|
|
|
144
140
|
function generateEndpointsModule(moduleName, endpoints, description, overrideDir, modulePrefixOpt) {
|
|
145
141
|
let modulePrefix = modulePrefixOpt !== undefined ? modulePrefixOpt : "";
|
|
146
142
|
let header = CodegenUtils.generateFileHeader(Stdlib_Option.getOr(description, `API for ` + moduleName));
|
|
147
143
|
let body = endpoints.map(ep => CodegenUtils.indent(generateEndpointCode(ep, overrideDir, moduleName, modulePrefix), 2)).join("\n\n");
|
|
148
|
-
return
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|}
|
|
154
|
-
|`, undefined);
|
|
144
|
+
return Handlebars.render(Templates.moduleWrapped, {
|
|
145
|
+
header: header.trimEnd(),
|
|
146
|
+
moduleName: moduleName,
|
|
147
|
+
body: body
|
|
148
|
+
});
|
|
155
149
|
}
|
|
156
150
|
|
|
157
151
|
function generateEndpointSignature(endpoint) {
|
|
@@ -170,4 +164,4 @@ export {
|
|
|
170
164
|
generateEndpointsModule,
|
|
171
165
|
generateEndpointSignature,
|
|
172
166
|
}
|
|
173
|
-
/*
|
|
167
|
+
/* Handlebars Not a pure module */
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
2
|
|
|
3
3
|
import * as Pipeline from "../core/Pipeline.mjs";
|
|
4
|
+
import * as Templates from "../core/Templates.mjs";
|
|
4
5
|
import * as Belt_Array from "@rescript/runtime/lib/es6/Belt_Array.js";
|
|
5
6
|
import * as FileSystem from "../core/FileSystem.mjs";
|
|
7
|
+
import * as Handlebars from "../bindings/Handlebars.mjs";
|
|
6
8
|
import * as CodegenUtils from "../core/CodegenUtils.mjs";
|
|
7
9
|
import * as Stdlib_Array from "@rescript/runtime/lib/es6/Stdlib_Array.js";
|
|
8
10
|
import * as OpenAPIParser from "../core/OpenAPIParser.mjs";
|
|
@@ -66,19 +68,16 @@ function generateTagModuleFile(tag, endpoints, $staropt$star, $staropt$star$1, o
|
|
|
66
68
|
let header = CodegenUtils.generateFileHeader(`API endpoints for ` + tag);
|
|
67
69
|
let body = endpoints.map(endpoint => EndpointGenerator.generateEndpointCode(endpoint, overrideDir, moduleName, undefined)).join("\n\n");
|
|
68
70
|
if (wrapInModule) {
|
|
69
|
-
return
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|}
|
|
75
|
-
|`, undefined);
|
|
71
|
+
return Handlebars.render(Templates.moduleWrapped, {
|
|
72
|
+
header: header.trimEnd(),
|
|
73
|
+
moduleName: moduleName,
|
|
74
|
+
body: CodegenUtils.indent(body, 2)
|
|
75
|
+
});
|
|
76
76
|
} else {
|
|
77
|
-
return
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|`, undefined);
|
|
77
|
+
return Handlebars.render(Templates.moduleUnwrapped, {
|
|
78
|
+
header: header.trimEnd(),
|
|
79
|
+
body: body
|
|
80
|
+
});
|
|
82
81
|
}
|
|
83
82
|
}
|
|
84
83
|
|
|
@@ -98,29 +97,24 @@ function generateAllTagModules(endpoints, includeSchemasOpt, wrapInModuleOpt, ov
|
|
|
98
97
|
function generateIndexModule(tags, moduleNameOpt) {
|
|
99
98
|
let moduleName = moduleNameOpt !== undefined ? moduleNameOpt : "API";
|
|
100
99
|
let header = CodegenUtils.generateFileHeader("Main API module index");
|
|
101
|
-
let
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|` + modules + `
|
|
110
|
-
|}
|
|
111
|
-
|`, undefined);
|
|
100
|
+
let tagData = tags.toSorted(Primitive_string.compare).map(tag => ({
|
|
101
|
+
modulePascal: JsConvertCase.toPascalCase(tag)
|
|
102
|
+
}));
|
|
103
|
+
return Handlebars.render(Templates.indexModule, {
|
|
104
|
+
header: header.trimEnd(),
|
|
105
|
+
moduleName: moduleName,
|
|
106
|
+
tags: tagData
|
|
107
|
+
});
|
|
112
108
|
}
|
|
113
109
|
|
|
114
110
|
function generateFlatModuleCode(moduleName, endpoints, overrideDir) {
|
|
115
111
|
let header = CodegenUtils.generateFileHeader(`All API endpoints in ` + moduleName);
|
|
116
112
|
let body = endpoints.map(endpoint => CodegenUtils.indent(EndpointGenerator.generateEndpointCode(endpoint, overrideDir, moduleName, undefined), 2)).join("\n\n");
|
|
117
|
-
return
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|}
|
|
123
|
-
|`, undefined);
|
|
113
|
+
return Handlebars.render(Templates.moduleWrapped, {
|
|
114
|
+
header: header.trimEnd(),
|
|
115
|
+
moduleName: moduleName,
|
|
116
|
+
body: body
|
|
117
|
+
});
|
|
124
118
|
}
|
|
125
119
|
|
|
126
120
|
function internalGenerateIntegratedModule(name, description, endpoints, schemas, overrideDir, isExtensionOpt, includeHeaderOpt) {
|
|
@@ -169,13 +163,11 @@ function generateCombinedModule(forkName, sharedEndpoints, extensionEndpoints, s
|
|
|
169
163
|
let header = CodegenUtils.generateFileHeader(`Combined Shared and ` + forkName + ` extensions`);
|
|
170
164
|
let shared = generateSharedModule(sharedEndpoints, sharedSchemas, overrideDir, false);
|
|
171
165
|
let extension = generateExtensionModule(forkName, extensionEndpoints, extensionSchemas, overrideDir, false);
|
|
172
|
-
return
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|` + extension + `
|
|
178
|
-
|`, undefined);
|
|
166
|
+
return Handlebars.render(Templates.combinedModule, {
|
|
167
|
+
header: header.trimEnd(),
|
|
168
|
+
shared: shared,
|
|
169
|
+
extension: extension
|
|
170
|
+
});
|
|
179
171
|
}
|
|
180
172
|
|
|
181
173
|
function generateTagModuleFiles(endpoints, outputDir, wrapInModuleOpt, overrideDir) {
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
2
|
|
|
3
|
+
import * as Templates from "../core/Templates.mjs";
|
|
4
|
+
import * as Handlebars from "../bindings/Handlebars.mjs";
|
|
3
5
|
import * as CodegenUtils from "../core/CodegenUtils.mjs";
|
|
4
6
|
import * as OpenAPIParser from "../core/OpenAPIParser.mjs";
|
|
5
7
|
import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.js";
|
|
@@ -59,12 +61,13 @@ function generateEndpointModule(path, method, operation) {
|
|
|
59
61
|
)
|
|
60
62
|
);
|
|
61
63
|
let schemasCode = generateOperationSchemas(operationId, operation);
|
|
62
|
-
return
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
64
|
+
return Handlebars.render(Templates.endpointModule, {
|
|
65
|
+
docComment: docComment,
|
|
66
|
+
moduleName: JsConvertCase.toPascalCase(operationId),
|
|
67
|
+
schemasCode: CodegenUtils.indent(schemasCode, 2),
|
|
68
|
+
path: path,
|
|
69
|
+
methodStr: methodStr
|
|
70
|
+
});
|
|
68
71
|
}
|
|
69
72
|
|
|
70
73
|
export {
|
|
@@ -74,4 +77,4 @@ export {
|
|
|
74
77
|
generateOperationSchemas,
|
|
75
78
|
generateEndpointModule,
|
|
76
79
|
}
|
|
77
|
-
/*
|
|
80
|
+
/* Handlebars Not a pure module */
|
|
@@ -1,30 +1,24 @@
|
|
|
1
1
|
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
2
|
|
|
3
3
|
import * as Pipeline from "../core/Pipeline.mjs";
|
|
4
|
+
import * as Templates from "../core/Templates.mjs";
|
|
4
5
|
import * as FileSystem from "../core/FileSystem.mjs";
|
|
6
|
+
import * as Handlebars from "../bindings/Handlebars.mjs";
|
|
5
7
|
import * as CodegenUtils from "../core/CodegenUtils.mjs";
|
|
6
8
|
import * as Stdlib_Array from "@rescript/runtime/lib/es6/Stdlib_Array.js";
|
|
7
9
|
import * as OpenAPIParser from "../core/OpenAPIParser.mjs";
|
|
8
10
|
import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.js";
|
|
9
11
|
import * as JsConvertCase from "js-convert-case";
|
|
10
12
|
|
|
11
|
-
let clientTypeCode =
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
| token: option<string>,
|
|
15
|
-
| fetch: ` + CodegenUtils.fetchTypeSignature + `,
|
|
16
|
-
|}
|
|
17
|
-
|`, undefined);
|
|
13
|
+
let clientTypeCode = Handlebars.render(Templates.clientType, {
|
|
14
|
+
fetchTypeSignature: CodegenUtils.fetchTypeSignature
|
|
15
|
+
});
|
|
18
16
|
|
|
19
17
|
function generateConnectFunction(title) {
|
|
20
|
-
return
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
| token,
|
|
25
|
-
| fetch,
|
|
26
|
-
|}
|
|
27
|
-
|`, undefined);
|
|
18
|
+
return Handlebars.render(Templates.connectFunction, {
|
|
19
|
+
title: title,
|
|
20
|
+
fetchTypeSignature: CodegenUtils.fetchTypeSignature
|
|
21
|
+
});
|
|
28
22
|
}
|
|
29
23
|
|
|
30
24
|
function generateWrapperFunction(endpoint, generatedModuleName) {
|
|
@@ -42,8 +36,13 @@ function generateWrapperFunction(endpoint, generatedModuleName) {
|
|
|
42
36
|
});
|
|
43
37
|
let signature = hasRequestBody ? `let ` + operationName + ` = (request: ` + generatedModuleName + `.` + operationName + `Request, ~client: client)` : `let ` + operationName + ` = (~client: client)`;
|
|
44
38
|
let callArguments = hasRequestBody ? "~body=request, " : "";
|
|
45
|
-
return
|
|
46
|
-
|
|
39
|
+
return Handlebars.render(Templates.wrapperFunction, {
|
|
40
|
+
docComment: docComment,
|
|
41
|
+
signature: signature,
|
|
42
|
+
generatedModuleName: generatedModuleName,
|
|
43
|
+
operationName: operationName,
|
|
44
|
+
callArguments: callArguments
|
|
45
|
+
});
|
|
47
46
|
}
|
|
48
47
|
|
|
49
48
|
function generateWrapper(spec, endpoints, extensionEndpointsOpt, outputDir, wrapperModuleNameOpt, generatedModulePrefixOpt, baseModulePrefixOpt) {
|
|
@@ -75,13 +74,11 @@ function generateWrapper(spec, endpoints, extensionEndpointsOpt, outputDir, wrap
|
|
|
75
74
|
}).join("\n\n");
|
|
76
75
|
return `module ` + moduleName + ` = {\n` + wrapperFunctions + `\n}`;
|
|
77
76
|
}).join("\n\n");
|
|
78
|
-
let fileContent =
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
` + modulesCode;
|
|
77
|
+
let fileContent = Handlebars.render(Templates.wrapperFile, {
|
|
78
|
+
clientTypeCode: clientTypeCode,
|
|
79
|
+
connectFunctionCode: generateConnectFunction(spec.info.title),
|
|
80
|
+
modulesCode: modulesCode
|
|
81
|
+
});
|
|
85
82
|
return Pipeline.fromFilesAndWarnings([{
|
|
86
83
|
path: FileSystem.makePath(outputDir, wrapperModuleName + `.res`),
|
|
87
84
|
content: fileContent
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
2
|
|
|
3
|
+
import * as Templates from "../core/Templates.mjs";
|
|
3
4
|
import * as FileSystem from "../core/FileSystem.mjs";
|
|
5
|
+
import * as Handlebars from "../bindings/Handlebars.mjs";
|
|
4
6
|
import * as CodegenUtils from "../core/CodegenUtils.mjs";
|
|
5
7
|
import * as Stdlib_Array from "@rescript/runtime/lib/es6/Stdlib_Array.js";
|
|
6
8
|
import * as OpenAPIParser from "../core/OpenAPIParser.mjs";
|
|
@@ -41,24 +43,44 @@ function generateResponseInterface(endpoint, functionName) {
|
|
|
41
43
|
|
|
42
44
|
function generateMethodSignature(endpoint, functionName) {
|
|
43
45
|
let params = Stdlib_Option.isSome(endpoint.requestBody) ? `client: MisskeyClient, request: ` + JsConvertCase.toPascalCase(functionName) + `Request` : "client: MisskeyClient";
|
|
44
|
-
let
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
46
|
+
let match = endpoint.summary;
|
|
47
|
+
let match$1 = endpoint.description;
|
|
48
|
+
let docLines;
|
|
49
|
+
if (match !== undefined) {
|
|
50
|
+
if (match$1 !== undefined) {
|
|
51
|
+
if (match === match$1) {
|
|
52
|
+
docLines = ` /** ` + match + ` */`;
|
|
53
|
+
} else {
|
|
54
|
+
let descLines = match$1.split("\n").map(line => {
|
|
55
|
+
if (line === "") {
|
|
56
|
+
return " *";
|
|
57
|
+
} else {
|
|
58
|
+
return ` * ` + line;
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
docLines = ` /**\n * ` + match + `\n *\n` + descLines.join("\n") + `\n */`;
|
|
62
|
+
}
|
|
63
|
+
} else {
|
|
64
|
+
docLines = ` /** ` + match + ` */`;
|
|
65
|
+
}
|
|
66
|
+
} else if (match$1 !== undefined) {
|
|
67
|
+
let lines = match$1.split("\n").map(line => {
|
|
68
|
+
if (line === "") {
|
|
69
|
+
return " *";
|
|
70
|
+
} else {
|
|
71
|
+
return ` * ` + line;
|
|
53
72
|
}
|
|
54
73
|
});
|
|
55
|
-
lines.
|
|
56
|
-
|
|
74
|
+
docLines = ` /**\n` + lines.join("\n") + `\n */`;
|
|
75
|
+
} else {
|
|
76
|
+
docLines = "";
|
|
77
|
+
}
|
|
78
|
+
return Handlebars.render(Templates.methodSignature, {
|
|
79
|
+
docLines: docLines,
|
|
80
|
+
functionName: functionName,
|
|
81
|
+
params: params,
|
|
82
|
+
responsePascalName: JsConvertCase.toPascalCase(functionName)
|
|
57
83
|
});
|
|
58
|
-
let code = `
|
|
59
|
-
|` + docLines.join("\n") + `
|
|
60
|
-
| ` + functionName + `(` + params + `): Promise<` + JsConvertCase.toPascalCase(functionName) + `Response>;`;
|
|
61
|
-
return CodegenUtils.trimMargin(code, undefined);
|
|
62
84
|
}
|
|
63
85
|
|
|
64
86
|
function generateModuleDts(moduleName, endpoints) {
|
|
@@ -72,25 +94,11 @@ function generateModuleDts(moduleName, endpoints) {
|
|
|
72
94
|
].filter(s => s !== "").join("\n");
|
|
73
95
|
}).join("\n\n");
|
|
74
96
|
let methodSignatures = endpoints.map(endpoint => generateMethodSignature(endpoint, CodegenUtils.generateOperationName(endpoint.operationId, endpoint.path, endpoint.method))).join("\n");
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|import { MisskeyClient } from './index';
|
|
81
|
-
|import * as ComponentSchemas from './ComponentSchemas';
|
|
82
|
-
|`, undefined);
|
|
83
|
-
return CodegenUtils.trimMargin(`
|
|
84
|
-
|` + header + `
|
|
85
|
-
|
|
|
86
|
-
|` + interfaces + `
|
|
87
|
-
|
|
|
88
|
-
|export interface ` + moduleName + `Module {
|
|
89
|
-
|` + methodSignatures + `
|
|
90
|
-
|}
|
|
91
|
-
|
|
|
92
|
-
|export const ` + moduleName + `: ` + moduleName + `Module;
|
|
93
|
-
|`, undefined);
|
|
97
|
+
return Handlebars.render(Templates.moduleDts, {
|
|
98
|
+
moduleName: moduleName,
|
|
99
|
+
interfaces: interfaces,
|
|
100
|
+
methodSignatures: methodSignatures
|
|
101
|
+
});
|
|
94
102
|
}
|
|
95
103
|
|
|
96
104
|
function generateComponentSchemasDts(schemas) {
|
|
@@ -98,33 +106,19 @@ function generateComponentSchemasDts(schemas) {
|
|
|
98
106
|
let schema = param[1];
|
|
99
107
|
return generateTypeScriptType(param[0], schema.description, schema);
|
|
100
108
|
}).join("\n\n");
|
|
101
|
-
return
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|// DO NOT EDIT
|
|
105
|
-
|
|
|
106
|
-
|` + content + `
|
|
107
|
-
|`, undefined);
|
|
109
|
+
return Handlebars.render(Templates.componentSchemasDts, {
|
|
110
|
+
content: content
|
|
111
|
+
});
|
|
108
112
|
}
|
|
109
113
|
|
|
110
114
|
function generateIndexDts(moduleNames) {
|
|
111
|
-
let
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|` + imports + `
|
|
119
|
-
|
|
|
120
|
-
|export class MisskeyClient {
|
|
121
|
-
| constructor(baseUrl: string, token?: string);
|
|
122
|
-
| readonly baseUrl: string;
|
|
123
|
-
| readonly token?: string;
|
|
124
|
-
|}
|
|
125
|
-
|
|
|
126
|
-
|` + $$exports + `
|
|
127
|
-
|`, undefined);
|
|
115
|
+
let modules = moduleNames.map(m => ({
|
|
116
|
+
importLine: `import { ` + m + `Module } from './` + m + `';`,
|
|
117
|
+
exportLine: `export const ` + m + `: ` + m + `Module;`
|
|
118
|
+
}));
|
|
119
|
+
return Handlebars.render(Templates.indexDts, {
|
|
120
|
+
modules: modules
|
|
121
|
+
});
|
|
128
122
|
}
|
|
129
123
|
|
|
130
124
|
function generate(spec, endpoints, outputDir) {
|