@f3liz/rescript-autogen-openapi 0.1.0 → 0.1.6
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/Codegen.mjs +8 -8
- package/lib/es6/src/core/CodegenUtils.mjs +5 -5
- package/lib/es6/src/core/DocOverride.mjs +2 -2
- package/lib/es6/src/core/FileSystem.mjs +3 -3
- package/lib/es6/src/core/ReferenceResolver.mjs +4 -4
- package/lib/es6/src/core/SpecDiffer.mjs +6 -6
- package/lib/es6/src/generators/ComponentSchemaGenerator.mjs +3 -3
- package/lib/es6/src/generators/EndpointGenerator.mjs +3 -3
- package/lib/es6/src/generators/IRToSuryGenerator.mjs +4 -4
- package/lib/es6/src/generators/IRToTypeGenerator.mjs +5 -5
- package/lib/es6/src/generators/IRToTypeScriptGenerator.mjs +3 -3
- package/lib/es6/src/generators/ModuleGenerator.mjs +9 -9
- package/lib/es6/src/generators/SchemaCodeGenerator.mjs +4 -4
- package/lib/es6/src/generators/ThinWrapperGenerator.mjs +2 -2
- package/lib/es6/src/generators/TypeScriptDtsGenerator.mjs +7 -7
- package/lib/es6/src/generators/TypeScriptWrapperGenerator.mjs +7 -7
- package/package.json +7 -4
- package/src/core/CodegenUtils.res +2 -2
- package/src/core/FileSystem.res +2 -2
- package/src/core/SpecDiffer.res +6 -6
package/lib/es6/src/Codegen.mjs
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
import * as Config from "./types/Config.mjs";
|
|
4
4
|
import * as Pipeline from "./core/Pipeline.mjs";
|
|
5
|
-
import * as Text from "@std/text";
|
|
6
5
|
import * as Belt_Array from "@rescript/runtime/lib/es6/Belt_Array.js";
|
|
7
6
|
import * as FileSystem from "./core/FileSystem.mjs";
|
|
8
7
|
import * as SpecDiffer from "./core/SpecDiffer.mjs";
|
|
@@ -14,6 +13,7 @@ import * as OpenAPIParser from "./core/OpenAPIParser.mjs";
|
|
|
14
13
|
import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.js";
|
|
15
14
|
import * as Stdlib_Result from "@rescript/runtime/lib/es6/Stdlib_Result.js";
|
|
16
15
|
import * as ModuleGenerator from "./generators/ModuleGenerator.mjs";
|
|
16
|
+
import * as JsConvertCase from "js-convert-case";
|
|
17
17
|
import * as SchemaRefResolver from "./core/SchemaRefResolver.mjs";
|
|
18
18
|
import * as DiffReportGenerator from "./generators/DiffReportGenerator.mjs";
|
|
19
19
|
import * as Primitive_exceptions from "@rescript/runtime/lib/es6/Primitive_exceptions.js";
|
|
@@ -32,7 +32,7 @@ function generateSingleSpecPure(spec, config) {
|
|
|
32
32
|
ComponentSchemaGenerator.generate(spec, config.outputDir),
|
|
33
33
|
config.modulePerTag ? ModuleGenerator.generateTagModuleFiles(endpoints, config.outputDir, undefined, config.docOverrideDir) : ModuleGenerator.generateFlatModuleFile("API", endpoints, config.outputDir, config.docOverrideDir)
|
|
34
34
|
]) : Pipeline.empty;
|
|
35
|
-
let wrapperOutput = targets.rescriptWrapper ? ThinWrapperGenerator.generateWrapper(spec, endpoints, undefined, config.outputDir,
|
|
35
|
+
let wrapperOutput = targets.rescriptWrapper ? ThinWrapperGenerator.generateWrapper(spec, endpoints, undefined, config.outputDir, JsConvertCase.toPascalCase(spec.info.title) + "Wrapper", "", undefined) : Pipeline.empty;
|
|
36
36
|
let dtsOutput = targets.typescriptDts ? TypeScriptDtsGenerator.generate(spec, endpoints, Stdlib_Option.getOr(config.dtsOutputDir, config.outputDir)) : Pipeline.empty;
|
|
37
37
|
let tsWrapperOutput = targets.typescriptWrapper ? TypeScriptWrapperGenerator.generate(endpoints, Stdlib_Option.getOr(config.wrapperOutputDir, config.outputDir), "../generated") : Pipeline.empty;
|
|
38
38
|
return {
|
|
@@ -136,11 +136,11 @@ function processForkPure(baseSpec, baseEndpoints, fork, config) {
|
|
|
136
136
|
if (match$1 === "Separate") {
|
|
137
137
|
codeOutput = Pipeline.fromFile({
|
|
138
138
|
path: FileSystem.makePath(config.outputDir, fork.name + `.res`),
|
|
139
|
-
content: ModuleGenerator.generateFlatModuleCode(
|
|
139
|
+
content: ModuleGenerator.generateFlatModuleCode(JsConvertCase.toPascalCase(fork.name), forkEndpoints, config.docOverrideDir)
|
|
140
140
|
});
|
|
141
141
|
} else {
|
|
142
142
|
let baseName = Stdlib_Option.getOrThrow(config.baseInstanceName, "baseInstanceName required");
|
|
143
|
-
let basePrefix = Stdlib_Option.getOr(config.baseModulePrefix,
|
|
143
|
+
let basePrefix = Stdlib_Option.getOr(config.baseModulePrefix, JsConvertCase.toPascalCase(baseName));
|
|
144
144
|
codeOutput = ModuleGenerator.generateSeparatePerTagModules(baseName, basePrefix, fork.name, undefined, sharedEndpoints, extensionEndpoints, Stdlib_Option.flatMap(sharedSpec.components, c => c.schemas), Stdlib_Option.flatMap(fork.spec.components, c => c.schemas), config.outputDir, config.docOverrideDir);
|
|
145
145
|
}
|
|
146
146
|
let targets = Stdlib_Option.getOr(config.targets, {
|
|
@@ -160,12 +160,12 @@ function processForkPure(baseSpec, baseEndpoints, fork, config) {
|
|
|
160
160
|
sharedSpec,
|
|
161
161
|
sharedEndpoints,
|
|
162
162
|
extensionEndpoints,
|
|
163
|
-
Stdlib_Option.getOr(config.baseModulePrefix, Stdlib_Option.getOr(Stdlib_Option.map(config.baseInstanceName, prim =>
|
|
163
|
+
Stdlib_Option.getOr(config.baseModulePrefix, Stdlib_Option.getOr(Stdlib_Option.map(config.baseInstanceName, prim => JsConvertCase.toPascalCase(prim)), ""))
|
|
164
164
|
];
|
|
165
165
|
let wExt = match$3[2];
|
|
166
166
|
let wShared = match$3[1];
|
|
167
167
|
let wSpec = match$3[0];
|
|
168
|
-
let wrapperOutput = targets.rescriptWrapper ? ThinWrapperGenerator.generateWrapper(wSpec, wShared, wExt, FileSystem.makePath(config.outputDir, fork.name),
|
|
168
|
+
let wrapperOutput = targets.rescriptWrapper ? ThinWrapperGenerator.generateWrapper(wSpec, wShared, wExt, FileSystem.makePath(config.outputDir, fork.name), JsConvertCase.toPascalCase(fork.name) + "Wrapper", JsConvertCase.toPascalCase(fork.name), match$3[3]) : Pipeline.empty;
|
|
169
169
|
let allWEndpoints = wShared.concat(wExt);
|
|
170
170
|
let dtsOutput = targets.typescriptDts ? TypeScriptDtsGenerator.generate(wSpec, allWEndpoints, FileSystem.makePath(Stdlib_Option.getOr(config.dtsOutputDir, config.outputDir), fork.name)) : Pipeline.empty;
|
|
171
171
|
let tsWrapperOutput = targets.typescriptWrapper ? TypeScriptWrapperGenerator.generate(allWEndpoints, FileSystem.makePath(Stdlib_Option.getOr(config.wrapperOutputDir, config.outputDir), fork.name), `../../generated/` + fork.name) : Pipeline.empty;
|
|
@@ -232,7 +232,7 @@ function generateMultiSpecPure(baseSpec, forkSpecs, config) {
|
|
|
232
232
|
});
|
|
233
233
|
let targets = Stdlib_Option.getOr(config.targets, Config.defaultTargets());
|
|
234
234
|
let baseName = Stdlib_Option.getOrThrow(config.baseInstanceName, "baseInstanceName required");
|
|
235
|
-
let basePrefix = Stdlib_Option.getOr(config.baseModulePrefix,
|
|
235
|
+
let basePrefix = Stdlib_Option.getOr(config.baseModulePrefix, JsConvertCase.toPascalCase(baseName));
|
|
236
236
|
let baseOutputDir = FileSystem.makePath(config.outputDir, baseName);
|
|
237
237
|
let baseWrappers = Pipeline.combine([
|
|
238
238
|
targets.rescriptWrapper ? ThinWrapperGenerator.generateWrapper(baseSpec, baseEndpoints, undefined, baseOutputDir, basePrefix + "Wrapper", basePrefix, undefined) : Pipeline.empty,
|
|
@@ -420,4 +420,4 @@ export {
|
|
|
420
420
|
generateFromUrl,
|
|
421
421
|
generateFromFile,
|
|
422
422
|
}
|
|
423
|
-
/*
|
|
423
|
+
/* FileSystem Not a pure module */
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
2
|
|
|
3
|
-
import * as Text from "@std/text";
|
|
4
3
|
import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.js";
|
|
4
|
+
import * as JsConvertCase from "js-convert-case";
|
|
5
5
|
|
|
6
6
|
function sanitizeIdentifier(str) {
|
|
7
7
|
return str.replaceAll("{", "").replaceAll("}", "").replaceAll("[", "").replaceAll("]", "").replaceAll(".", "_").replaceAll("-", "_").replaceAll("/", "_").replaceAll(" ", "_");
|
|
@@ -9,13 +9,13 @@ function sanitizeIdentifier(str) {
|
|
|
9
9
|
|
|
10
10
|
function generateTypeName(prefixOpt, path, suffix) {
|
|
11
11
|
let prefix = prefixOpt !== undefined ? prefixOpt : "";
|
|
12
|
-
let cleaned = sanitizeIdentifier(path.replaceAll("/", "_")).split("_").filter(part => part !== "").map(prim =>
|
|
12
|
+
let cleaned = sanitizeIdentifier(path.replaceAll("/", "_")).split("_").filter(part => part !== "").map(prim => JsConvertCase.toPascalCase(prim)).join("");
|
|
13
13
|
return prefix + cleaned + suffix;
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
function generateOperationName(operationId, path, method) {
|
|
17
17
|
if (operationId !== undefined) {
|
|
18
|
-
return
|
|
18
|
+
return JsConvertCase.toCamelCase(sanitizeIdentifier(operationId));
|
|
19
19
|
} else {
|
|
20
20
|
return method.toLowerCase() + path.split("/").filter(part => {
|
|
21
21
|
if (part !== "") {
|
|
@@ -23,7 +23,7 @@ function generateOperationName(operationId, path, method) {
|
|
|
23
23
|
} else {
|
|
24
24
|
return false;
|
|
25
25
|
}
|
|
26
|
-
}).map(prim =>
|
|
26
|
+
}).map(prim => JsConvertCase.toCamelCase(prim)).join("");
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
29
|
|
|
@@ -183,4 +183,4 @@ export {
|
|
|
183
183
|
generateDocString,
|
|
184
184
|
fetchTypeSignature,
|
|
185
185
|
}
|
|
186
|
-
/*
|
|
186
|
+
/* js-convert-case Not a pure module */
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
2
|
|
|
3
3
|
import * as Fs from "fs";
|
|
4
|
-
import * as Text from "@std/text";
|
|
5
4
|
import * as Js_string from "@rescript/runtime/lib/es6/Js_string.js";
|
|
6
5
|
import * as FileSystem from "./FileSystem.mjs";
|
|
7
6
|
import * as CodegenUtils from "./CodegenUtils.mjs";
|
|
8
7
|
import * as Stdlib_Array from "@rescript/runtime/lib/es6/Stdlib_Array.js";
|
|
9
8
|
import * as Stdlib_JsExn from "@rescript/runtime/lib/es6/Stdlib_JsExn.js";
|
|
10
9
|
import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.js";
|
|
10
|
+
import * as JsConvertCase from "js-convert-case";
|
|
11
11
|
import * as Primitive_exceptions from "@rescript/runtime/lib/es6/Primitive_exceptions.js";
|
|
12
12
|
|
|
13
13
|
function generateEndpointHash(endpoint) {
|
|
@@ -264,7 +264,7 @@ function generateOverrideFiles(spec, endpoints, outputDir, host, groupByTagOpt,
|
|
|
264
264
|
moduleName = "API";
|
|
265
265
|
}
|
|
266
266
|
let functionName = CodegenUtils.generateOperationName(endpoint.operationId, endpoint.path, endpoint.method);
|
|
267
|
-
let modulePath = FileSystem.makePath(outputDir,
|
|
267
|
+
let modulePath = FileSystem.makePath(outputDir, JsConvertCase.toPascalCase(moduleName));
|
|
268
268
|
let filePath = FileSystem.makePath(modulePath, functionName + ".md");
|
|
269
269
|
if (isFileCustomized(filePath)) {
|
|
270
270
|
console.log(`ℹ️ Skipping ` + moduleName + `/` + functionName + ` - file already customized`);
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
2
|
|
|
3
3
|
import * as Fs from "fs";
|
|
4
|
-
import * as
|
|
4
|
+
import * as Pathe from "pathe";
|
|
5
5
|
import * as Stdlib_JsExn from "@rescript/runtime/lib/es6/Stdlib_JsExn.js";
|
|
6
6
|
import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.js";
|
|
7
7
|
import * as Primitive_exceptions from "@rescript/runtime/lib/es6/Primitive_exceptions.js";
|
|
8
8
|
|
|
9
9
|
function ensureDir(path) {
|
|
10
10
|
try {
|
|
11
|
-
Fs.mkdirSync(
|
|
11
|
+
Fs.mkdirSync(Pathe.dirname(path), {
|
|
12
12
|
recursive: true
|
|
13
13
|
});
|
|
14
14
|
return;
|
|
@@ -66,7 +66,7 @@ function writeFiles(files) {
|
|
|
66
66
|
}
|
|
67
67
|
|
|
68
68
|
function makePath(baseDir, filename) {
|
|
69
|
-
return
|
|
69
|
+
return Pathe.join(baseDir, filename);
|
|
70
70
|
}
|
|
71
71
|
|
|
72
72
|
export {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
2
|
|
|
3
|
-
import * as
|
|
3
|
+
import * as JsConvertCase from "js-convert-case";
|
|
4
4
|
|
|
5
5
|
function refToTypePath(insideComponentSchemasOpt, modulePrefixOpt, ref) {
|
|
6
6
|
let insideComponentSchemas = insideComponentSchemasOpt !== undefined ? insideComponentSchemasOpt : false;
|
|
@@ -10,7 +10,7 @@ function refToTypePath(insideComponentSchemasOpt, modulePrefixOpt, ref) {
|
|
|
10
10
|
if (schemaName === undefined) {
|
|
11
11
|
return;
|
|
12
12
|
}
|
|
13
|
-
let moduleName =
|
|
13
|
+
let moduleName = JsConvertCase.toPascalCase(schemaName);
|
|
14
14
|
if (insideComponentSchemas) {
|
|
15
15
|
return moduleName + `.t`;
|
|
16
16
|
} else {
|
|
@@ -26,7 +26,7 @@ function refToSchemaPath(insideComponentSchemasOpt, modulePrefixOpt, ref) {
|
|
|
26
26
|
if (schemaName === undefined) {
|
|
27
27
|
return;
|
|
28
28
|
}
|
|
29
|
-
let moduleName =
|
|
29
|
+
let moduleName = JsConvertCase.toPascalCase(schemaName);
|
|
30
30
|
if (insideComponentSchemas) {
|
|
31
31
|
return moduleName + `.schema`;
|
|
32
32
|
} else {
|
|
@@ -38,4 +38,4 @@ export {
|
|
|
38
38
|
refToTypePath,
|
|
39
39
|
refToSchemaPath,
|
|
40
40
|
}
|
|
41
|
-
/*
|
|
41
|
+
/* js-convert-case Not a pure module */
|
|
@@ -150,9 +150,9 @@ function compareEndpointLists(baseEndpoints, forkEndpoints) {
|
|
|
150
150
|
});
|
|
151
151
|
let baseKeys = new Set(Object.keys(baseMap));
|
|
152
152
|
let forkKeys = new Set(Object.keys(forkMap));
|
|
153
|
-
let added = Stdlib_Array.filterMap(Array.from(forkKeys.
|
|
154
|
-
let removed = Stdlib_Array.filterMap(Array.from(baseKeys.
|
|
155
|
-
let modified = Stdlib_Array.filterMap(Array.from(baseKeys.
|
|
153
|
+
let added = Stdlib_Array.filterMap(Array.from(forkKeys).filter(key => !baseKeys.has(key)), key => forkMap[key]);
|
|
154
|
+
let removed = Stdlib_Array.filterMap(Array.from(baseKeys).filter(key => !forkKeys.has(key)), key => baseMap[key]);
|
|
155
|
+
let modified = Stdlib_Array.filterMap(Array.from(baseKeys).filter(key => forkKeys.has(key)), key => {
|
|
156
156
|
let match = baseMap[key];
|
|
157
157
|
let match$1 = forkMap[key];
|
|
158
158
|
if (match !== undefined && match$1 !== undefined) {
|
|
@@ -191,9 +191,9 @@ function compareComponentSchemas(baseSchemas, forkSchemas) {
|
|
|
191
191
|
}
|
|
192
192
|
let baseKeys = new Set(Object.keys(baseSchemas));
|
|
193
193
|
let forkKeys = new Set(Object.keys(forkSchemas));
|
|
194
|
-
let added = Array.from(forkKeys.
|
|
195
|
-
let removed = Array.from(baseKeys.
|
|
196
|
-
let modified = Stdlib_Array.filterMap(Array.from(baseKeys.
|
|
194
|
+
let added = Array.from(forkKeys).filter(key => !baseKeys.has(key));
|
|
195
|
+
let removed = Array.from(baseKeys).filter(key => !forkKeys.has(key));
|
|
196
|
+
let modified = Stdlib_Array.filterMap(Array.from(baseKeys).filter(key => forkKeys.has(key)), name => {
|
|
197
197
|
let match = baseSchemas[name];
|
|
198
198
|
let match$1 = forkSchemas[name];
|
|
199
199
|
if (match !== undefined && match$1 !== undefined && !schemasEqual(match, match$1)) {
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
2
|
|
|
3
3
|
import * as Pipeline from "../core/Pipeline.mjs";
|
|
4
|
-
import * as Text from "@std/text";
|
|
5
4
|
import * as FileSystem from "../core/FileSystem.mjs";
|
|
6
5
|
import * as Stdlib_Dict from "@rescript/runtime/lib/es6/Stdlib_Dict.js";
|
|
7
6
|
import * as CodegenUtils from "../core/CodegenUtils.mjs";
|
|
8
7
|
import * as Stdlib_Array from "@rescript/runtime/lib/es6/Stdlib_Array.js";
|
|
9
8
|
import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.js";
|
|
10
9
|
import * as SchemaIRParser from "../core/SchemaIRParser.mjs";
|
|
10
|
+
import * as JsConvertCase from "js-convert-case";
|
|
11
11
|
import * as Primitive_string from "@rescript/runtime/lib/es6/Primitive_string.js";
|
|
12
12
|
import * as GenerationContext from "../types/GenerationContext.mjs";
|
|
13
13
|
import * as IRToSuryGenerator from "./IRToSuryGenerator.mjs";
|
|
@@ -105,7 +105,7 @@ function generate(spec, outputDir) {
|
|
|
105
105
|
warnings.push(...typeCtx.warnings);
|
|
106
106
|
warnings.push(...schemaCtx.warnings);
|
|
107
107
|
let docComment = Stdlib_Option.mapOr(schema.description, "", d => CodegenUtils.generateDocString(undefined, d, undefined));
|
|
108
|
-
return docComment + `module ` +
|
|
108
|
+
return docComment + `module ` + JsConvertCase.toPascalCase(schema.name) + ` = {
|
|
109
109
|
type t = ` + typeCode + `
|
|
110
110
|
let schema = ` + schemaCode + `
|
|
111
111
|
}`;
|
|
@@ -122,4 +122,4 @@ export {
|
|
|
122
122
|
extractReferencedSchemaNames,
|
|
123
123
|
generate,
|
|
124
124
|
}
|
|
125
|
-
/*
|
|
125
|
+
/* FileSystem Not a pure module */
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
2
|
|
|
3
|
-
import * as Text from "@std/text";
|
|
4
3
|
import * as DocOverride from "../core/DocOverride.mjs";
|
|
5
4
|
import * as CodegenUtils from "../core/CodegenUtils.mjs";
|
|
6
5
|
import * as Stdlib_Array from "@rescript/runtime/lib/es6/Stdlib_Array.js";
|
|
7
6
|
import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.js";
|
|
8
7
|
import * as SchemaIRParser from "../core/SchemaIRParser.mjs";
|
|
8
|
+
import * as JsConvertCase from "js-convert-case";
|
|
9
9
|
import * as IRToSuryGenerator from "./IRToSuryGenerator.mjs";
|
|
10
10
|
import * as IRToTypeGenerator from "./IRToTypeGenerator.mjs";
|
|
11
11
|
|
|
@@ -134,7 +134,7 @@ function generateEndpointModule(endpoint, modulePrefixOpt) {
|
|
|
134
134
|
return CodegenUtils.trimMargin(`
|
|
135
135
|
|` + header.trimEnd() + `
|
|
136
136
|
|
|
|
137
|
-
|module ` +
|
|
137
|
+
|module ` + JsConvertCase.toPascalCase(functionName) + ` = {
|
|
138
138
|
|` + CodegenUtils.indent(generateEndpointCode(endpoint, undefined, undefined, modulePrefix), 2) + `
|
|
139
139
|
|}
|
|
140
140
|
|`, undefined);
|
|
@@ -169,4 +169,4 @@ export {
|
|
|
169
169
|
generateEndpointsModule,
|
|
170
170
|
generateEndpointSignature,
|
|
171
171
|
}
|
|
172
|
-
/*
|
|
172
|
+
/* DocOverride Not a pure module */
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
2
|
|
|
3
3
|
import * as SchemaIR from "../core/SchemaIR.mjs";
|
|
4
|
-
import * as Text from "@std/text";
|
|
5
4
|
import * as CodegenUtils from "../core/CodegenUtils.mjs";
|
|
6
5
|
import * as Stdlib_Array from "@rescript/runtime/lib/es6/Stdlib_Array.js";
|
|
7
6
|
import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.js";
|
|
7
|
+
import * as JsConvertCase from "js-convert-case";
|
|
8
8
|
import * as Primitive_option from "@rescript/runtime/lib/es6/Primitive_option.js";
|
|
9
9
|
import * as Primitive_string from "@rescript/runtime/lib/es6/Primitive_string.js";
|
|
10
10
|
import * as GenerationContext from "../types/GenerationContext.mjs";
|
|
@@ -72,7 +72,7 @@ function generateSchemaWithContext(ctx, depthOpt, irType) {
|
|
|
72
72
|
let fields = properties.map(param => {
|
|
73
73
|
let name = param[0];
|
|
74
74
|
let schemaCode = recurse(param[1]);
|
|
75
|
-
let camelName = CodegenUtils.escapeKeyword(
|
|
75
|
+
let camelName = CodegenUtils.escapeKeyword(JsConvertCase.toCamelCase(name));
|
|
76
76
|
if (param[2]) {
|
|
77
77
|
return ` ` + camelName + `: s.field("` + name + `", ` + schemaCode + `),`;
|
|
78
78
|
} else {
|
|
@@ -161,7 +161,7 @@ function generateSchemaWithContext(ctx, depthOpt, irType) {
|
|
|
161
161
|
let schemaPath;
|
|
162
162
|
if (available !== undefined) {
|
|
163
163
|
let name = Stdlib_Option.getOr(ref.split("/")[ref.split("/").length - 1 | 0], "");
|
|
164
|
-
schemaPath = available.includes(name) ?
|
|
164
|
+
schemaPath = available.includes(name) ? JsConvertCase.toPascalCase(name) + `.schema` : `ComponentSchemas.` + JsConvertCase.toPascalCase(name) + `.schema`;
|
|
165
165
|
} else {
|
|
166
166
|
schemaPath = Stdlib_Option.getOr(ReferenceResolver.refToSchemaPath(ctx.insideComponentSchemas, ctx.modulePrefix, ref), "S.json");
|
|
167
167
|
}
|
|
@@ -230,4 +230,4 @@ export {
|
|
|
230
230
|
generateNamedSchema,
|
|
231
231
|
generateAllSchemas,
|
|
232
232
|
}
|
|
233
|
-
/*
|
|
233
|
+
/* CodegenUtils Not a pure module */
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
2
|
|
|
3
3
|
import * as SchemaIR from "../core/SchemaIR.mjs";
|
|
4
|
-
import * as Text from "@std/text";
|
|
5
4
|
import * as CodegenUtils from "../core/CodegenUtils.mjs";
|
|
6
5
|
import * as Stdlib_Array from "@rescript/runtime/lib/es6/Stdlib_Array.js";
|
|
7
6
|
import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.js";
|
|
7
|
+
import * as JsConvertCase from "js-convert-case";
|
|
8
8
|
import * as Primitive_string from "@rescript/runtime/lib/es6/Primitive_string.js";
|
|
9
9
|
import * as GenerationContext from "../types/GenerationContext.mjs";
|
|
10
10
|
import * as IRToSuryGenerator from "./IRToSuryGenerator.mjs";
|
|
@@ -54,7 +54,7 @@ function generateTypeWithContext(ctx, depthOpt, irType) {
|
|
|
54
54
|
let name = param[0];
|
|
55
55
|
let typeCode = recurse(param[1]);
|
|
56
56
|
let finalType = param[2] ? typeCode : `option<` + typeCode + `>`;
|
|
57
|
-
let camelName =
|
|
57
|
+
let camelName = JsConvertCase.toCamelCase(name);
|
|
58
58
|
let escapedName = CodegenUtils.escapeKeyword(camelName);
|
|
59
59
|
let aliasAnnotation = escapedName !== name ? `@as("` + name + `") ` : "";
|
|
60
60
|
return ` ` + aliasAnnotation + escapedName + `: ` + finalType + `,`;
|
|
@@ -128,7 +128,7 @@ function generateTypeWithContext(ctx, depthOpt, irType) {
|
|
|
128
128
|
if (typeof s !== "object" || s.TAG !== "StringLiteral") {
|
|
129
129
|
return "#Unknown";
|
|
130
130
|
} else {
|
|
131
|
-
return `#` +
|
|
131
|
+
return `#` + JsConvertCase.toPascalCase(s._0);
|
|
132
132
|
}
|
|
133
133
|
}).join(" | ");
|
|
134
134
|
return `[` + variants + `]`;
|
|
@@ -157,7 +157,7 @@ function generateTypeWithContext(ctx, depthOpt, irType) {
|
|
|
157
157
|
let typePath;
|
|
158
158
|
if (available !== undefined) {
|
|
159
159
|
let name = Stdlib_Option.getOr(ref.split("/")[ref.split("/").length - 1 | 0], "");
|
|
160
|
-
typePath = available.includes(name) ?
|
|
160
|
+
typePath = available.includes(name) ? JsConvertCase.toPascalCase(name) + `.t` : `ComponentSchemas.` + JsConvertCase.toPascalCase(name) + `.t`;
|
|
161
161
|
} else {
|
|
162
162
|
typePath = Stdlib_Option.getOr(ReferenceResolver.refToTypePath(ctx.insideComponentSchemas, ctx.modulePrefix, ref), "JSON.t");
|
|
163
163
|
}
|
|
@@ -238,4 +238,4 @@ export {
|
|
|
238
238
|
generateAllTypes,
|
|
239
239
|
generateTypeAndSchema,
|
|
240
240
|
}
|
|
241
|
-
/*
|
|
241
|
+
/* CodegenUtils Not a pure module */
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
2
|
|
|
3
|
-
import * as Text from "@std/text";
|
|
4
3
|
import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.js";
|
|
5
4
|
import * as SchemaIRParser from "../core/SchemaIRParser.mjs";
|
|
5
|
+
import * as JsConvertCase from "js-convert-case";
|
|
6
6
|
|
|
7
7
|
function generateType(_irType, _isOptionalOpt) {
|
|
8
8
|
while (true) {
|
|
@@ -129,7 +129,7 @@ function generateNamedType(namedSchema) {
|
|
|
129
129
|
function generateParameterType(name, schema) {
|
|
130
130
|
let match = SchemaIRParser.parseJsonSchema(undefined, schema);
|
|
131
131
|
return [
|
|
132
|
-
|
|
132
|
+
JsConvertCase.toCamelCase(name),
|
|
133
133
|
generateType(match[0], undefined)
|
|
134
134
|
];
|
|
135
135
|
}
|
|
@@ -140,4 +140,4 @@ export {
|
|
|
140
140
|
generateNamedType,
|
|
141
141
|
generateParameterType,
|
|
142
142
|
}
|
|
143
|
-
/*
|
|
143
|
+
/* js-convert-case Not a pure module */
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
2
|
|
|
3
3
|
import * as Pipeline from "../core/Pipeline.mjs";
|
|
4
|
-
import * as Text from "@std/text";
|
|
5
4
|
import * as Belt_Array from "@rescript/runtime/lib/es6/Belt_Array.js";
|
|
6
5
|
import * as FileSystem from "../core/FileSystem.mjs";
|
|
7
6
|
import * as CodegenUtils from "../core/CodegenUtils.mjs";
|
|
@@ -9,6 +8,7 @@ import * as Stdlib_Array from "@rescript/runtime/lib/es6/Stdlib_Array.js";
|
|
|
9
8
|
import * as OpenAPIParser from "../core/OpenAPIParser.mjs";
|
|
10
9
|
import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.js";
|
|
11
10
|
import * as SchemaIRParser from "../core/SchemaIRParser.mjs";
|
|
11
|
+
import * as JsConvertCase from "js-convert-case";
|
|
12
12
|
import * as Primitive_option from "@rescript/runtime/lib/es6/Primitive_option.js";
|
|
13
13
|
import * as Primitive_string from "@rescript/runtime/lib/es6/Primitive_string.js";
|
|
14
14
|
import * as EndpointGenerator from "./EndpointGenerator.mjs";
|
|
@@ -45,7 +45,7 @@ function generateTagModulesCode(endpoints, overrideDir, indentOpt) {
|
|
|
45
45
|
let groupedByTag = OpenAPIParser.groupByTag(endpoints);
|
|
46
46
|
let indentStr = " ".repeat(indent);
|
|
47
47
|
return Stdlib_Array.filterMap(Object.keys(groupedByTag).toSorted(Primitive_string.compare), tag => Stdlib_Option.map(groupedByTag[tag], tagEndpoints => {
|
|
48
|
-
let moduleName =
|
|
48
|
+
let moduleName = JsConvertCase.toPascalCase(tag);
|
|
49
49
|
let endpointLines = tagEndpoints.flatMap(endpoint => [
|
|
50
50
|
CodegenUtils.indent(EndpointGenerator.generateEndpointCode(endpoint, overrideDir, moduleName, undefined), indent + 2 | 0),
|
|
51
51
|
""
|
|
@@ -62,7 +62,7 @@ function generateTagModuleFile(tag, endpoints, $staropt$star, $staropt$star$1, o
|
|
|
62
62
|
true;
|
|
63
63
|
}
|
|
64
64
|
let wrapInModule = $staropt$star$1 !== undefined ? $staropt$star$1 : false;
|
|
65
|
-
let moduleName =
|
|
65
|
+
let moduleName = JsConvertCase.toPascalCase(tag);
|
|
66
66
|
let header = CodegenUtils.generateFileHeader(`API endpoints for ` + tag);
|
|
67
67
|
let body = endpoints.map(endpoint => EndpointGenerator.generateEndpointCode(endpoint, overrideDir, moduleName, undefined)).join("\n\n");
|
|
68
68
|
if (wrapInModule) {
|
|
@@ -99,7 +99,7 @@ function generateIndexModule(tags, moduleNameOpt) {
|
|
|
99
99
|
let moduleName = moduleNameOpt !== undefined ? moduleNameOpt : "API";
|
|
100
100
|
let header = CodegenUtils.generateFileHeader("Main API module index");
|
|
101
101
|
let modules = tags.toSorted(Primitive_string.compare).map(tag => {
|
|
102
|
-
let m =
|
|
102
|
+
let m = JsConvertCase.toPascalCase(tag);
|
|
103
103
|
return ` module ` + m + ` = ` + m;
|
|
104
104
|
}).join("\n");
|
|
105
105
|
return CodegenUtils.trimMargin(`
|
|
@@ -162,7 +162,7 @@ function generateSharedModule(endpoints, schemas, overrideDir, includeHeaderOpt)
|
|
|
162
162
|
|
|
163
163
|
function generateExtensionModule(forkName, endpoints, schemas, overrideDir, includeHeaderOpt) {
|
|
164
164
|
let includeHeader = includeHeaderOpt !== undefined ? includeHeaderOpt : true;
|
|
165
|
-
return internalGenerateIntegratedModule(
|
|
165
|
+
return internalGenerateIntegratedModule(JsConvertCase.toPascalCase(forkName) + `Extensions`, forkName + ` extensions`, endpoints, schemas, overrideDir, true, includeHeader);
|
|
166
166
|
}
|
|
167
167
|
|
|
168
168
|
function generateCombinedModule(forkName, sharedEndpoints, extensionEndpoints, sharedSchemas, extensionSchemas, overrideDir) {
|
|
@@ -181,7 +181,7 @@ function generateCombinedModule(forkName, sharedEndpoints, extensionEndpoints, s
|
|
|
181
181
|
function generateTagModuleFiles(endpoints, outputDir, wrapInModuleOpt, overrideDir) {
|
|
182
182
|
let wrapInModule = wrapInModuleOpt !== undefined ? wrapInModuleOpt : false;
|
|
183
183
|
let files = generateAllTagModules(endpoints, true, wrapInModule, overrideDir).map(param => {
|
|
184
|
-
let path = FileSystem.makePath(outputDir,
|
|
184
|
+
let path = FileSystem.makePath(outputDir, JsConvertCase.toPascalCase(param[0]) + `.res`);
|
|
185
185
|
return {
|
|
186
186
|
path: path,
|
|
187
187
|
content: param[1]
|
|
@@ -231,7 +231,7 @@ function generateInstanceTagModules(instanceName, modulePrefix, endpoints, schem
|
|
|
231
231
|
let groupedByTag = OpenAPIParser.groupByTag(endpoints);
|
|
232
232
|
let endpointFiles = Stdlib_Array.filterMap(Object.entries(groupedByTag).toSorted((param, param$1) => Primitive_string.compare(param[0], param$1[0])), param => {
|
|
233
233
|
let tag = param[0];
|
|
234
|
-
let moduleName = modulePrefix +
|
|
234
|
+
let moduleName = modulePrefix + JsConvertCase.toPascalCase(tag);
|
|
235
235
|
let endpointCodes = param[1].flatMap(endpoint => [
|
|
236
236
|
EndpointGenerator.generateEndpointCode(endpoint, overrideDir, moduleName, modulePrefix),
|
|
237
237
|
""
|
|
@@ -260,7 +260,7 @@ function generateSeparatePerTagModules(baseName, basePrefix, forkName, forkPrefi
|
|
|
260
260
|
let forkPrefix = forkPrefixOpt !== undefined ? Primitive_option.valFromOption(forkPrefixOpt) : undefined;
|
|
261
261
|
return Pipeline.combine([
|
|
262
262
|
generateBaseTagModules(baseName, basePrefix, sharedEndpoints, sharedSchemas, outputDir, overrideDir),
|
|
263
|
-
generateForkTagModules(forkName, Stdlib_Option.getOr(forkPrefix,
|
|
263
|
+
generateForkTagModules(forkName, Stdlib_Option.getOr(forkPrefix, JsConvertCase.toPascalCase(forkName)), extensionEndpoints, extensionSchemas, outputDir, overrideDir)
|
|
264
264
|
]);
|
|
265
265
|
}
|
|
266
266
|
|
|
@@ -282,4 +282,4 @@ export {
|
|
|
282
282
|
generateForkTagModules,
|
|
283
283
|
generateSeparatePerTagModules,
|
|
284
284
|
}
|
|
285
|
-
/*
|
|
285
|
+
/* FileSystem Not a pure module */
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
2
|
|
|
3
|
-
import * as Text from "@std/text";
|
|
4
3
|
import * as CodegenUtils from "../core/CodegenUtils.mjs";
|
|
5
4
|
import * as OpenAPIParser from "../core/OpenAPIParser.mjs";
|
|
6
5
|
import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.js";
|
|
7
6
|
import * as SchemaIRParser from "../core/SchemaIRParser.mjs";
|
|
7
|
+
import * as JsConvertCase from "js-convert-case";
|
|
8
8
|
import * as IRToSuryGenerator from "./IRToSuryGenerator.mjs";
|
|
9
9
|
import * as IRToTypeGenerator from "./IRToTypeGenerator.mjs";
|
|
10
10
|
|
|
@@ -34,7 +34,7 @@ function generateComponentSchemas(components) {
|
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
function generateOperationSchemas(operationId, operation) {
|
|
37
|
-
let generatePart = (suffix, schemaOpt) => Stdlib_Option.mapOr(schemaOpt, "", schema => generateTypeCodeAndSchemaCode(
|
|
37
|
+
let generatePart = (suffix, schemaOpt) => Stdlib_Option.mapOr(schemaOpt, "", schema => generateTypeCodeAndSchemaCode(JsConvertCase.toPascalCase(operationId) + suffix, schema));
|
|
38
38
|
let requestBodySchema = Stdlib_Option.flatMap(Stdlib_Option.flatMap(operation.requestBody, body => body.content["application/json"]), mediaType => mediaType.schema);
|
|
39
39
|
let responses = operation.responses;
|
|
40
40
|
let successResponseSchema = Stdlib_Option.flatMap(Stdlib_Option.flatMap(Stdlib_Option.flatMap(Stdlib_Option.orElse(responses["200"], responses["201"]), response => response.content), content => content["application/json"]), mediaType => mediaType.schema);
|
|
@@ -59,7 +59,7 @@ function generateEndpointModule(path, method, operation) {
|
|
|
59
59
|
)
|
|
60
60
|
);
|
|
61
61
|
let schemasCode = generateOperationSchemas(operationId, operation);
|
|
62
|
-
return docComment + `module ` +
|
|
62
|
+
return docComment + `module ` + JsConvertCase.toPascalCase(operationId) + ` = {
|
|
63
63
|
` + CodegenUtils.indent(schemasCode, 2) + `
|
|
64
64
|
|
|
65
65
|
let endpoint = "` + path + `"
|
|
@@ -74,4 +74,4 @@ export {
|
|
|
74
74
|
generateOperationSchemas,
|
|
75
75
|
generateEndpointModule,
|
|
76
76
|
}
|
|
77
|
-
/*
|
|
77
|
+
/* CodegenUtils Not a pure module */
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
2
|
|
|
3
3
|
import * as Pipeline from "../core/Pipeline.mjs";
|
|
4
|
-
import * as Text from "@std/text";
|
|
5
4
|
import * as FileSystem from "../core/FileSystem.mjs";
|
|
6
5
|
import * as CodegenUtils from "../core/CodegenUtils.mjs";
|
|
7
6
|
import * as Stdlib_Array from "@rescript/runtime/lib/es6/Stdlib_Array.js";
|
|
8
7
|
import * as OpenAPIParser from "../core/OpenAPIParser.mjs";
|
|
9
8
|
import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.js";
|
|
9
|
+
import * as JsConvertCase from "js-convert-case";
|
|
10
10
|
|
|
11
11
|
let clientTypeCode = CodegenUtils.trimMargin(`
|
|
12
12
|
|type client = {
|
|
@@ -65,7 +65,7 @@ function generateWrapper(spec, endpoints, extensionEndpointsOpt, outputDir, wrap
|
|
|
65
65
|
).concat(extensionEndpoints);
|
|
66
66
|
let endpointsByTag = OpenAPIParser.groupByTag(allEndpoints);
|
|
67
67
|
let modulesCode = Object.keys(endpointsByTag).map(tag => {
|
|
68
|
-
let moduleName =
|
|
68
|
+
let moduleName = JsConvertCase.toPascalCase(tag);
|
|
69
69
|
let wrapperFunctions = Stdlib_Option.getOr(endpointsByTag[tag], []).map(endpoint => {
|
|
70
70
|
let operationName = CodegenUtils.generateOperationName(endpoint.operationId, endpoint.path, endpoint.method);
|
|
71
71
|
let isExtension = hasExtensions && operationName in extensionOperationIds;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
2
|
|
|
3
|
-
import * as Text from "@std/text";
|
|
4
3
|
import * as FileSystem from "../core/FileSystem.mjs";
|
|
5
4
|
import * as CodegenUtils from "../core/CodegenUtils.mjs";
|
|
6
5
|
import * as Stdlib_Array from "@rescript/runtime/lib/es6/Stdlib_Array.js";
|
|
7
6
|
import * as OpenAPIParser from "../core/OpenAPIParser.mjs";
|
|
8
7
|
import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.js";
|
|
9
8
|
import * as SchemaIRParser from "../core/SchemaIRParser.mjs";
|
|
9
|
+
import * as JsConvertCase from "js-convert-case";
|
|
10
10
|
import * as IRToTypeScriptGenerator from "./IRToTypeScriptGenerator.mjs";
|
|
11
11
|
|
|
12
12
|
function getFirstJsonSchema(contentDict) {
|
|
@@ -23,12 +23,12 @@ function generateTypeScriptType(name, description, schema) {
|
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
function generateRequestInterface(endpoint, functionName) {
|
|
26
|
-
let requestTypeName =
|
|
26
|
+
let requestTypeName = JsConvertCase.toPascalCase(functionName) + `Request`;
|
|
27
27
|
return Stdlib_Option.flatMap(endpoint.requestBody, body => Stdlib_Option.map(getFirstJsonSchema(body.content), schema => generateTypeScriptType(requestTypeName, body.description, schema)));
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
function generateResponseInterface(endpoint, functionName) {
|
|
31
|
-
let responseTypeName =
|
|
31
|
+
let responseTypeName = JsConvertCase.toPascalCase(functionName) + `Response`;
|
|
32
32
|
let successCodes = [
|
|
33
33
|
"200",
|
|
34
34
|
"201",
|
|
@@ -40,7 +40,7 @@ function generateResponseInterface(endpoint, functionName) {
|
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
function generateMethodSignature(endpoint, functionName) {
|
|
43
|
-
let params = Stdlib_Option.isSome(endpoint.requestBody) ? `client: MisskeyClient, request: ` +
|
|
43
|
+
let params = Stdlib_Option.isSome(endpoint.requestBody) ? `client: MisskeyClient, request: ` + JsConvertCase.toPascalCase(functionName) + `Request` : "client: MisskeyClient";
|
|
44
44
|
let docLines = Stdlib_Option.mapOr(endpoint.summary, [], summary => {
|
|
45
45
|
let lines = [
|
|
46
46
|
" /**",
|
|
@@ -57,7 +57,7 @@ function generateMethodSignature(endpoint, functionName) {
|
|
|
57
57
|
});
|
|
58
58
|
let code = `
|
|
59
59
|
|` + docLines.join("\n") + `
|
|
60
|
-
| ` + functionName + `(` + params + `): Promise<` +
|
|
60
|
+
| ` + functionName + `(` + params + `): Promise<` + JsConvertCase.toPascalCase(functionName) + `Response>;`;
|
|
61
61
|
return CodegenUtils.trimMargin(code, undefined);
|
|
62
62
|
}
|
|
63
63
|
|
|
@@ -135,7 +135,7 @@ function generate(spec, endpoints, outputDir) {
|
|
|
135
135
|
if (tagEndpoints.length === 0) {
|
|
136
136
|
return;
|
|
137
137
|
}
|
|
138
|
-
let name =
|
|
138
|
+
let name = JsConvertCase.toPascalCase(param[0]);
|
|
139
139
|
moduleNames.push(name);
|
|
140
140
|
return {
|
|
141
141
|
path: FileSystem.makePath(outputDir, `types/` + name + `.d.ts`),
|
|
@@ -169,4 +169,4 @@ export {
|
|
|
169
169
|
generateIndexDts,
|
|
170
170
|
generate,
|
|
171
171
|
}
|
|
172
|
-
/*
|
|
172
|
+
/* FileSystem Not a pure module */
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
2
|
|
|
3
3
|
import * as Pipeline from "../core/Pipeline.mjs";
|
|
4
|
-
import * as Text from "@std/text";
|
|
5
4
|
import * as FileSystem from "../core/FileSystem.mjs";
|
|
6
5
|
import * as CodegenUtils from "../core/CodegenUtils.mjs";
|
|
7
6
|
import * as OpenAPIParser from "../core/OpenAPIParser.mjs";
|
|
8
7
|
import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.js";
|
|
8
|
+
import * as JsConvertCase from "js-convert-case";
|
|
9
9
|
|
|
10
10
|
let misskeyClientJsCode = CodegenUtils.trimMargin(`
|
|
11
11
|
|export class MisskeyClient {
|
|
@@ -32,11 +32,11 @@ function generateWrapperMjs(endpoints, generatedModulePath) {
|
|
|
32
32
|
let endpointsByTag = OpenAPIParser.groupByTag(endpoints);
|
|
33
33
|
let tags = Object.keys(endpointsByTag);
|
|
34
34
|
let imports = tags.map(tag => {
|
|
35
|
-
let moduleName =
|
|
35
|
+
let moduleName = JsConvertCase.toPascalCase(tag);
|
|
36
36
|
return `import * as ` + moduleName + ` from '` + generatedModulePath + `/` + moduleName + `.mjs';`;
|
|
37
37
|
}).join("\n");
|
|
38
38
|
let wrappers = tags.map(tag => {
|
|
39
|
-
let moduleName =
|
|
39
|
+
let moduleName = JsConvertCase.toPascalCase(tag);
|
|
40
40
|
let methods = Stdlib_Option.getOr(endpointsByTag[tag], []).map(endpoint => {
|
|
41
41
|
let functionName = CodegenUtils.generateOperationName(endpoint.operationId, endpoint.path, endpoint.method);
|
|
42
42
|
let hasRequestBody = Stdlib_Option.isSome(endpoint.requestBody);
|
|
@@ -69,9 +69,9 @@ function generateWrapperDts(endpoints) {
|
|
|
69
69
|
let endpointsByTag = OpenAPIParser.groupByTag(endpoints);
|
|
70
70
|
let tags = Object.keys(endpointsByTag);
|
|
71
71
|
let imports = tags.map(tag => {
|
|
72
|
-
let moduleName =
|
|
72
|
+
let moduleName = JsConvertCase.toPascalCase(tag);
|
|
73
73
|
let typesToImport = Stdlib_Option.getOr(endpointsByTag[tag], []).flatMap(endpoint => {
|
|
74
|
-
let pascalName =
|
|
74
|
+
let pascalName = JsConvertCase.toPascalCase(CodegenUtils.generateOperationName(endpoint.operationId, endpoint.path, endpoint.method));
|
|
75
75
|
if (Stdlib_Option.isSome(endpoint.requestBody)) {
|
|
76
76
|
return [
|
|
77
77
|
` ` + pascalName + `Request,`,
|
|
@@ -86,10 +86,10 @@ function generateWrapperDts(endpoints) {
|
|
|
86
86
|
} from '../types/` + moduleName + `.d.ts';`;
|
|
87
87
|
}).join("\n");
|
|
88
88
|
let namespaces = tags.map(tag => {
|
|
89
|
-
let moduleName =
|
|
89
|
+
let moduleName = JsConvertCase.toPascalCase(tag);
|
|
90
90
|
let functions = Stdlib_Option.getOr(endpointsByTag[tag], []).map(endpoint => {
|
|
91
91
|
let functionName = CodegenUtils.generateOperationName(endpoint.operationId, endpoint.path, endpoint.method);
|
|
92
|
-
let pascalName =
|
|
92
|
+
let pascalName = JsConvertCase.toPascalCase(functionName);
|
|
93
93
|
let docComment = Stdlib_Option.mapOr(endpoint.summary, "", summary => {
|
|
94
94
|
let descriptionPart = Stdlib_Option.mapOr(endpoint.description, "", description => {
|
|
95
95
|
if (description === summary) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@f3liz/rescript-autogen-openapi",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.6",
|
|
4
4
|
"description": "Generate ReScript code with Sury schemas from OpenAPI 3.1 specs. Supports multiple forks with diff/merge capabilities.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"rescript",
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"api",
|
|
13
13
|
"generator"
|
|
14
14
|
],
|
|
15
|
-
"author": "",
|
|
15
|
+
"author": "NyanRus",
|
|
16
16
|
"license": "MPL-2.0",
|
|
17
17
|
"files": [
|
|
18
18
|
"src/**/*.res",
|
|
@@ -21,6 +21,9 @@
|
|
|
21
21
|
"README.md",
|
|
22
22
|
"LICENSE"
|
|
23
23
|
],
|
|
24
|
+
"repository": {
|
|
25
|
+
"url": "https://github.com/f3liz-dev/rescript-autogen-openapi"
|
|
26
|
+
},
|
|
24
27
|
"scripts": {
|
|
25
28
|
"build": "rescript",
|
|
26
29
|
"clean": "rescript clean",
|
|
@@ -31,8 +34,8 @@
|
|
|
31
34
|
"type": "module",
|
|
32
35
|
"dependencies": {
|
|
33
36
|
"@readme/openapi-parser": "^5.5.0",
|
|
34
|
-
"
|
|
35
|
-
"
|
|
37
|
+
"js-convert-case": "^4.2.0",
|
|
38
|
+
"pathe": "^2.0.3",
|
|
36
39
|
"sury": "11.0.0-alpha.4"
|
|
37
40
|
},
|
|
38
41
|
"devDependencies": {
|
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
// CodegenUtils.res - Utility functions for code generation
|
|
4
4
|
|
|
5
5
|
// Convert a string to PascalCase
|
|
6
|
-
@module("
|
|
6
|
+
@module("js-convert-case") external toPascalCase: string => string = "toPascalCase"
|
|
7
7
|
|
|
8
8
|
// Convert a string to camelCase
|
|
9
|
-
@module("
|
|
9
|
+
@module("js-convert-case") external toCamelCase: string => string = "toCamelCase"
|
|
10
10
|
|
|
11
11
|
// Sanitize identifier (remove special characters, ensure valid ReScript identifier)
|
|
12
12
|
let sanitizeIdentifier = (str: string): string =>
|
package/src/core/FileSystem.res
CHANGED
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
|
|
5
5
|
@module("fs") external mkdirSync: (string, {"recursive": bool}) => unit = "mkdirSync"
|
|
6
6
|
@module("fs") external writeFileSync: (string, string, string) => unit = "writeFileSync"
|
|
7
|
-
@module("
|
|
8
|
-
@module("
|
|
7
|
+
@module("pathe") external join: (string, string) => string = "join"
|
|
8
|
+
@module("pathe") external dirname: string => string = "dirname"
|
|
9
9
|
|
|
10
10
|
// Represents a file to be written
|
|
11
11
|
type fileToWrite = {
|
package/src/core/SpecDiffer.res
CHANGED
|
@@ -151,20 +151,20 @@ let compareEndpointLists = (
|
|
|
151
151
|
|
|
152
152
|
// Find added endpoints (in fork but not in base)
|
|
153
153
|
let added = forkKeys
|
|
154
|
-
->Set.difference(baseKeys)
|
|
155
154
|
->Set.toArray
|
|
155
|
+
->Array.filter(key => !(baseKeys->Set.has(key)))
|
|
156
156
|
->Array.filterMap(key => Dict.get(forkMap, key))
|
|
157
157
|
|
|
158
158
|
// Find removed endpoints (in base but not in fork)
|
|
159
159
|
let removed = baseKeys
|
|
160
|
-
->Set.difference(forkKeys)
|
|
161
160
|
->Set.toArray
|
|
161
|
+
->Array.filter(key => !(forkKeys->Set.has(key)))
|
|
162
162
|
->Array.filterMap(key => Dict.get(baseMap, key))
|
|
163
163
|
|
|
164
164
|
// Find modified endpoints (in both but different)
|
|
165
165
|
let modified = baseKeys
|
|
166
|
-
->Set.intersection(forkKeys)
|
|
167
166
|
->Set.toArray
|
|
167
|
+
->Array.filter(key => forkKeys->Set.has(key))
|
|
168
168
|
->Array.filterMap(key => {
|
|
169
169
|
switch (Dict.get(baseMap, key), Dict.get(forkMap, key)) {
|
|
170
170
|
| (Some(baseEp), Some(forkEp)) => compareEndpoints(baseEp, forkEp)
|
|
@@ -190,18 +190,18 @@ let compareComponentSchemas = (
|
|
|
190
190
|
|
|
191
191
|
// Added schemas
|
|
192
192
|
let added = forkKeys
|
|
193
|
-
->Set.difference(baseKeys)
|
|
194
193
|
->Set.toArray
|
|
194
|
+
->Array.filter(key => !(baseKeys->Set.has(key)))
|
|
195
195
|
|
|
196
196
|
// Removed schemas
|
|
197
197
|
let removed = baseKeys
|
|
198
|
-
->Set.difference(forkKeys)
|
|
199
198
|
->Set.toArray
|
|
199
|
+
->Array.filter(key => !(forkKeys->Set.has(key)))
|
|
200
200
|
|
|
201
201
|
// Modified schemas
|
|
202
202
|
let modified = baseKeys
|
|
203
|
-
->Set.intersection(forkKeys)
|
|
204
203
|
->Set.toArray
|
|
204
|
+
->Array.filter(key => forkKeys->Set.has(key))
|
|
205
205
|
->Array.filterMap(name => {
|
|
206
206
|
switch (Dict.get(base, name), Dict.get(fork, name)) {
|
|
207
207
|
| (Some(baseSchema), Some(forkSchema)) =>
|