@mittwald/api-code-generator 0.0.0-development-f25b020-20260331 → 3.1.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/README.md +0 -72
- package/bin/cli.js +0 -0
- package/dist/{types/commands → commands}/generate/index.d.ts +1 -1
- package/dist/{esm/commands → commands}/generate/index.js +4 -8
- package/dist/generation/format.d.ts +1 -0
- package/dist/{esm/generation → generation}/format.js +2 -2
- package/dist/{esm/generation → generation}/model/CodeGenerationModel.js +0 -9
- package/dist/{esm/generation/refs → generation/model}/assertNoRefs.js +2 -3
- package/dist/{types/generation → generation}/model/components/Components.d.ts +0 -6
- package/dist/{esm/generation → generation}/model/components/Components.js +0 -19
- package/dist/{types/generation → generation}/model/components/Parameters.d.ts +5 -3
- package/dist/{esm/generation → generation}/model/components/Parameters.js +4 -9
- package/dist/{esm/generation → generation}/model/components/Responses.js +1 -1
- package/dist/{esm/generation → generation}/model/components/Schemas.js +1 -4
- package/dist/{types/generation → generation}/model/components/SecurityScheme.d.ts +1 -2
- package/dist/{esm/generation → generation}/model/components/SecurityScheme.js +3 -4
- package/dist/{esm/generation → generation}/model/components/SecuritySchemes.js +2 -2
- package/dist/{types/generation → generation}/model/paths/Paths.d.ts +2 -8
- package/dist/generation/model/paths/Paths.js +100 -0
- package/dist/{types/generation → generation}/model/paths/operation/Operation.d.ts +1 -4
- package/dist/{esm/generation → generation}/model/paths/operation/Operation.js +8 -37
- package/dist/{esm/generation → generation}/model/paths/operation/RequestParameters.js +11 -17
- package/dist/{types/generation → generation}/prepareTypeScriptOutput.d.ts +1 -1
- package/dist/{esm/generation → generation}/prepareTypeScriptOutput.js +2 -2
- package/dist/{types/openapi → openapi}/OpenApiSpec.d.ts +0 -1
- package/dist/{esm/openapi → openapi}/OpenApiSpec.js +0 -16
- package/package.json +35 -60
- package/LICENSE +0 -21
- package/dist/esm/generation/model/paths/Paths.js +0 -192
- package/dist/esm/generation/populateNullableTypes.js +0 -26
- package/dist/esm/generation/refs/extractComponentRefName.js +0 -8
- package/dist/esm/generation/refs/isRef.js +0 -3
- package/dist/esm/index.js +0 -7
- package/dist/esm/lib/writeIfChangedAsync.js +0 -8
- package/dist/types/generation/format.d.ts +0 -1
- package/dist/types/generation/populateNullableTypes.d.ts +0 -2
- package/dist/types/generation/refs/extractComponentRefName.d.ts +0 -2
- package/dist/types/generation/refs/isRef.d.ts +0 -2
- package/dist/types/index.d.ts +0 -7
- package/dist/types/lib/writeIfChangedAsync.d.ts +0 -1
- /package/dist/{types/commands → commands}/validate/index.d.ts +0 -0
- /package/dist/{esm/commands → commands}/validate/index.js +0 -0
- /package/dist/{types/generation → generation}/asyncStringJoin.d.ts +0 -0
- /package/dist/{esm/generation → generation}/asyncStringJoin.js +0 -0
- /package/dist/{types/generation → generation}/asyncStringJoin.test.d.ts +0 -0
- /package/dist/{esm/generation → generation}/asyncStringJoin.test.js +0 -0
- /package/dist/{types/generation → generation}/compileJsonSchema.d.ts +0 -0
- /package/dist/{esm/generation → generation}/compileJsonSchema.js +0 -0
- /package/dist/{types/generation → generation}/model/CodeGenerationModel.d.ts +0 -0
- /package/dist/{types/generation/refs → generation/model}/assertNoRefs.d.ts +0 -0
- /package/dist/{types/generation → generation}/model/components/RequestBodies.d.ts +0 -0
- /package/dist/{esm/generation → generation}/model/components/RequestBodies.js +0 -0
- /package/dist/{types/generation → generation}/model/components/Response.d.ts +0 -0
- /package/dist/{esm/generation → generation}/model/components/Response.js +0 -0
- /package/dist/{types/generation → generation}/model/components/ResponseContent.d.ts +0 -0
- /package/dist/{esm/generation → generation}/model/components/ResponseContent.js +0 -0
- /package/dist/{types/generation → generation}/model/components/Responses.d.ts +0 -0
- /package/dist/{types/generation → generation}/model/components/Schemas.d.ts +0 -0
- /package/dist/{types/generation → generation}/model/components/SecuritySchemes.d.ts +0 -0
- /package/dist/{types/generation → generation}/model/global/JSONSchema.d.ts +0 -0
- /package/dist/{esm/generation → generation}/model/global/JSONSchema.js +0 -0
- /package/dist/{types/generation → generation}/model/global/Name.d.ts +0 -0
- /package/dist/{esm/generation → generation}/model/global/Name.js +0 -0
- /package/dist/{types/generation → generation}/model/global/Name.test.d.ts +0 -0
- /package/dist/{esm/generation → generation}/model/global/Name.test.js +0 -0
- /package/dist/{types/generation → generation}/model/paths/Path.d.ts +0 -0
- /package/dist/{esm/generation → generation}/model/paths/Path.js +0 -0
- /package/dist/{types/generation → generation}/model/paths/operation/RequestParameters.d.ts +0 -0
- /package/dist/{types/generation → generation}/model/paths/operation/responses/Response.d.ts +0 -0
- /package/dist/{esm/generation → generation}/model/paths/operation/responses/Response.js +0 -0
- /package/dist/{types/generation → generation}/model/paths/operation/responses/ResponseContent.d.ts +0 -0
- /package/dist/{esm/generation → generation}/model/paths/operation/responses/ResponseContent.js +0 -0
- /package/dist/{types/generation → generation}/model/paths/operation/responses/ResponseContentTypes.d.ts +0 -0
- /package/dist/{esm/generation → generation}/model/paths/operation/responses/ResponseContentTypes.js +0 -0
- /package/dist/{types/generation → generation}/model/paths/operation/responses/Responses.d.ts +0 -0
- /package/dist/{esm/generation → generation}/model/paths/operation/responses/Responses.js +0 -0
- /package/dist/{types/generation → generation}/model/tags/Tag.d.ts +0 -0
- /package/dist/{esm/generation → generation}/model/tags/Tag.js +0 -0
- /package/dist/{types/generation → generation}/refs/componentRefsToCustomTypes.d.ts +0 -0
- /package/dist/{esm/generation → generation}/refs/componentRefsToCustomTypes.js +0 -0
- /package/dist/{types/generation → generation}/refs/componentRefsToCustomTypes.test.d.ts +0 -0
- /package/dist/{esm/generation → generation}/refs/componentRefsToCustomTypes.test.js +0 -0
- /package/dist/{types/generation → generation}/refs/refNameToTSName.d.ts +0 -0
- /package/dist/{esm/generation → generation}/refs/refNameToTSName.js +0 -0
- /package/dist/{types/generation → generation}/refs/refNameToTSName.test.d.ts +0 -0
- /package/dist/{esm/generation → generation}/refs/refNameToTSName.test.js +0 -0
- /package/dist/{types/generation → generation}/refs/splitRefNamespaces.d.ts +0 -0
- /package/dist/{esm/generation → generation}/refs/splitRefNamespaces.js +0 -0
- /package/dist/{types/generation → generation}/refs/splitRefNamespaces.test.d.ts +0 -0
- /package/dist/{esm/generation → generation}/refs/splitRefNamespaces.test.js +0 -0
- /package/dist/{types/generation → generation}/tsNamespaceName.d.ts +0 -0
- /package/dist/{esm/generation → generation}/tsNamespaceName.js +0 -0
- /package/dist/{types/generation → generation}/tsTypeName.d.ts +0 -0
- /package/dist/{esm/generation → generation}/tsTypeName.js +0 -0
- /package/dist/{types/generation → generation}/tsTypeName.test.d.ts +0 -0
- /package/dist/{esm/generation → generation}/tsTypeName.test.js +0 -0
- /package/dist/{types/lib → lib}/makeError.d.ts +0 -0
- /package/dist/{esm/lib → lib}/makeError.js +0 -0
- /package/dist/{types/lib → lib}/relativePath.d.ts +0 -0
- /package/dist/{esm/lib → lib}/relativePath.js +0 -0
- /package/dist/{types/loading → loading}/UniversalContentLoader.d.ts +0 -0
- /package/dist/{esm/loading → loading}/UniversalContentLoader.js +0 -0
- /package/dist/{types/loading → loading}/UniversalContentLoader.test.d.ts +0 -0
- /package/dist/{esm/loading → loading}/UniversalContentLoader.test.js +0 -0
- /package/dist/{types/loading → loading}/UniversalFileLoader.d.ts +0 -0
- /package/dist/{esm/loading → loading}/UniversalFileLoader.js +0 -0
- /package/dist/{types/loading → loading}/types.d.ts +0 -0
- /package/dist/{esm/loading → loading}/types.js +0 -0
- /package/dist/{types/openapi → openapi}/OpenAPISchemaValidationError.d.ts +0 -0
- /package/dist/{esm/openapi → openapi}/OpenAPISchemaValidationError.js +0 -0
|
@@ -2,8 +2,6 @@ import { OpenAPISchemaValidationError } from "./OpenAPISchemaValidationError.js"
|
|
|
2
2
|
import VError from "verror";
|
|
3
3
|
import { makeError } from "../lib/makeError.js";
|
|
4
4
|
import OpenAPISchemaValidator from "openapi-schema-validator";
|
|
5
|
-
import { convert } from "swagger2openapi";
|
|
6
|
-
import { ux } from "@oclif/core";
|
|
7
5
|
const validator = new OpenAPISchemaValidator.default({
|
|
8
6
|
version: 3,
|
|
9
7
|
});
|
|
@@ -12,25 +10,11 @@ export class OpenApiSpec {
|
|
|
12
10
|
constructor(document) {
|
|
13
11
|
this.document = document;
|
|
14
12
|
}
|
|
15
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
16
|
-
static async convertToOpenApi(doc) {
|
|
17
|
-
const version = doc.openapi ?? doc.swagger;
|
|
18
|
-
if (version.startsWith("3")) {
|
|
19
|
-
return doc;
|
|
20
|
-
}
|
|
21
|
-
ux.action.start("Converting doc to OpenAPI v3");
|
|
22
|
-
const spec = await convert(doc, {
|
|
23
|
-
patch: true,
|
|
24
|
-
});
|
|
25
|
-
ux.action.stop();
|
|
26
|
-
return spec.openapi;
|
|
27
|
-
}
|
|
28
13
|
static async parse(
|
|
29
14
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
30
15
|
doc, opts = {}) {
|
|
31
16
|
try {
|
|
32
17
|
const { skipValidation = false } = opts;
|
|
33
|
-
doc = await OpenApiSpec.convertToOpenApi(doc);
|
|
34
18
|
const validationResult = await validator.validate(doc);
|
|
35
19
|
if (validationResult.errors.length > 0 && !skipValidation) {
|
|
36
20
|
throw new OpenAPISchemaValidationError(validationResult.errors);
|
package/package.json
CHANGED
|
@@ -1,88 +1,63 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mittwald/api-code-generator",
|
|
3
|
-
"version": "
|
|
4
|
-
"type": "module",
|
|
5
|
-
"repository": "https://github.com/mittwald/api-client-js.git",
|
|
3
|
+
"version": "3.1.1",
|
|
6
4
|
"license": "MIT",
|
|
7
|
-
"
|
|
8
|
-
".": "./bin/cli.js",
|
|
9
|
-
"./js": {
|
|
10
|
-
"types": "./dist/types/index.d.ts",
|
|
11
|
-
"default": "./dist/esm/index.js"
|
|
12
|
-
}
|
|
13
|
-
},
|
|
5
|
+
"repository": "https://github.com/mittwald/api-client-js.git",
|
|
14
6
|
"bin": {
|
|
15
7
|
"acg": "./bin/cli.js"
|
|
16
8
|
},
|
|
17
|
-
"
|
|
18
|
-
"dist"
|
|
19
|
-
],
|
|
9
|
+
"type": "module",
|
|
20
10
|
"scripts": {
|
|
21
|
-
"
|
|
22
|
-
"build:clean": "run rimraf dist",
|
|
23
|
-
"format": "run prettier --write '**/*.{ts,tsx,yaml,yml,json,md,mdx,js}'",
|
|
24
|
-
"lint": "run eslint .",
|
|
25
|
-
"test": "",
|
|
26
|
-
"test:compile": "run tsc --noEmit",
|
|
27
|
-
"test:unit": "node --experimental-vm-modules $(yarn bin jest)"
|
|
11
|
+
"test": "node --experimental-vm-modules $(yarn bin jest)"
|
|
28
12
|
},
|
|
13
|
+
"files": [
|
|
14
|
+
"dist/**/*.{js,d.ts}",
|
|
15
|
+
"resources/**/*.*"
|
|
16
|
+
],
|
|
29
17
|
"dependencies": {
|
|
30
|
-
"@oclif/core": "^
|
|
31
|
-
"@oclif/plugin-help": "^
|
|
32
|
-
"@oclif/plugin-plugins": "^
|
|
33
|
-
"@sindresorhus/is": "^
|
|
34
|
-
"@types/clone-deep": "^4.0.
|
|
35
|
-
"@types/invariant": "^2.2.
|
|
36
|
-
"@types/js-yaml": "^4.0.
|
|
37
|
-
"@types/prettier": "^
|
|
38
|
-
"@types/verror": "^1.10.
|
|
39
|
-
"@types/yieldable-json": "^2.0.
|
|
40
|
-
"axios": "^1.
|
|
41
|
-
"camelcase": "^
|
|
18
|
+
"@oclif/core": "^2.8.11",
|
|
19
|
+
"@oclif/plugin-help": "^5.2.11",
|
|
20
|
+
"@oclif/plugin-plugins": "^3.1.6",
|
|
21
|
+
"@sindresorhus/is": "^5.4.1",
|
|
22
|
+
"@types/clone-deep": "^4.0.1",
|
|
23
|
+
"@types/invariant": "^2.2.35",
|
|
24
|
+
"@types/js-yaml": "^4.0.5",
|
|
25
|
+
"@types/prettier": "^2.7.3",
|
|
26
|
+
"@types/verror": "^1.10.6",
|
|
27
|
+
"@types/yieldable-json": "^2.0.0",
|
|
28
|
+
"axios": "^1.4.0",
|
|
29
|
+
"camelcase": "^7.0.1",
|
|
42
30
|
"clone-deep": "^4.0.1",
|
|
43
|
-
"dot-prop": "^8.0.
|
|
31
|
+
"dot-prop": "^8.0.1",
|
|
44
32
|
"fs-jetpack": "^5.1.0",
|
|
45
33
|
"get-stdin": "^9.0.0",
|
|
46
34
|
"invariant": "^2.2.4",
|
|
47
35
|
"js-yaml": "^4.1.0",
|
|
48
|
-
"json-schema-to-typescript": "^
|
|
36
|
+
"json-schema-to-typescript": "^13.0.2",
|
|
37
|
+
"jsonata": "^2.0.3",
|
|
49
38
|
"openapi-schema-validator": "^12.1.3",
|
|
50
39
|
"openapi-types": "^12.1.3",
|
|
51
|
-
"prettier": "^
|
|
52
|
-
"
|
|
53
|
-
"type-fest": "^4.30.0",
|
|
40
|
+
"prettier": "^2.8.8",
|
|
41
|
+
"type-fest": "^3.12.0",
|
|
54
42
|
"verror": "^1.10.1",
|
|
55
|
-
"yieldable-json": "^2.1
|
|
56
|
-
"zod": "^3.
|
|
57
|
-
"zod-validation-error": "^3.
|
|
43
|
+
"yieldable-json": "^2.0.1",
|
|
44
|
+
"zod": "^3.21.4",
|
|
45
|
+
"zod-validation-error": "^1.3.1"
|
|
58
46
|
},
|
|
59
47
|
"devDependencies": {
|
|
60
|
-
"@jest/globals": "^29.
|
|
61
|
-
"@types/jest": "^29.5.
|
|
62
|
-
"
|
|
63
|
-
"
|
|
64
|
-
"@typescript-eslint/parser": "^7.18.0",
|
|
65
|
-
"eslint": "^8.57.1",
|
|
66
|
-
"eslint-config-prettier": "^9.1.2",
|
|
67
|
-
"eslint-plugin-json": "^3.1.0",
|
|
68
|
-
"eslint-plugin-prettier": "^5.5.4",
|
|
69
|
-
"jest": "^29.7.0",
|
|
70
|
-
"prettier": "^3.6.2",
|
|
71
|
-
"prettier-plugin-jsdoc": "^1.3.3",
|
|
72
|
-
"prettier-plugin-pkgsort": "^0.2.1",
|
|
73
|
-
"prettier-plugin-sort-json": "^3.1.0",
|
|
74
|
-
"rimraf": "^5.0.10",
|
|
75
|
-
"ts-jest": "^29.2.5",
|
|
76
|
-
"typescript": "^5.7.2"
|
|
48
|
+
"@jest/globals": "^29.6.0",
|
|
49
|
+
"@types/jest": "^29.5.2",
|
|
50
|
+
"jest": "^29.6.0",
|
|
51
|
+
"ts-jest": "^29.1.1"
|
|
77
52
|
},
|
|
53
|
+
"types": "./dist/index.d.ts",
|
|
78
54
|
"oclif": {
|
|
79
55
|
"bin": "acg",
|
|
80
56
|
"dirname": "acg",
|
|
81
|
-
"commands": "./dist/
|
|
57
|
+
"commands": "./dist/commands",
|
|
82
58
|
"plugins": [
|
|
83
59
|
"@oclif/plugin-help",
|
|
84
60
|
"@oclif/plugin-plugins"
|
|
85
61
|
]
|
|
86
|
-
}
|
|
87
|
-
"gitHead": "0d6c44b5d7f417a4f396ec545fdb36ed083f27c7"
|
|
62
|
+
}
|
|
88
63
|
}
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2023 Mittwald CM Service GmbH & Co. KG and contributors
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
@@ -1,192 +0,0 @@
|
|
|
1
|
-
import { Name } from "../global/Name.js";
|
|
2
|
-
import { Path } from "./Path.js";
|
|
3
|
-
import { asyncStringJoin } from "../../asyncStringJoin.js";
|
|
4
|
-
import camelcase from "camelcase";
|
|
5
|
-
export class Paths {
|
|
6
|
-
static ns = "Paths";
|
|
7
|
-
paths;
|
|
8
|
-
model;
|
|
9
|
-
name;
|
|
10
|
-
constructor(model, paths) {
|
|
11
|
-
this.model = model;
|
|
12
|
-
this.name = new Name(Paths.ns, model.rootNamespace);
|
|
13
|
-
this.paths = Object.entries(paths ?? {})
|
|
14
|
-
.map(([name, pathDoc]) => {
|
|
15
|
-
if (pathDoc) {
|
|
16
|
-
return Path.fromDoc(this, name, pathDoc);
|
|
17
|
-
}
|
|
18
|
-
})
|
|
19
|
-
.filter((p) => !!p);
|
|
20
|
-
}
|
|
21
|
-
async compileTypes(opts) {
|
|
22
|
-
const t = {
|
|
23
|
-
ns: Paths.ns,
|
|
24
|
-
types: await asyncStringJoin(this.paths, (path) => path.compileTypes(opts)),
|
|
25
|
-
};
|
|
26
|
-
return `\
|
|
27
|
-
namespace ${t.ns} {
|
|
28
|
-
${t.types}
|
|
29
|
-
}
|
|
30
|
-
`;
|
|
31
|
-
}
|
|
32
|
-
async compileOperationTypes() {
|
|
33
|
-
const t = {
|
|
34
|
-
types: this.getFlattenedOperations()
|
|
35
|
-
.map((operation) => operation.compileRequestResponseTypes())
|
|
36
|
-
.join("\r\n"),
|
|
37
|
-
};
|
|
38
|
-
return `
|
|
39
|
-
namespace Operations {
|
|
40
|
-
${t.types}
|
|
41
|
-
}
|
|
42
|
-
`;
|
|
43
|
-
}
|
|
44
|
-
compileDescriptors() {
|
|
45
|
-
const t = {
|
|
46
|
-
ns: this.model.rootNamespace.tsType,
|
|
47
|
-
descriptors: this.getFlattenedOperations()
|
|
48
|
-
.map((operation) => operation.compileDescriptor())
|
|
49
|
-
.join("\r\n"),
|
|
50
|
-
};
|
|
51
|
-
return `\
|
|
52
|
-
import { Simplify } from "@mittwald/api-client-commons";
|
|
53
|
-
import { RequestType } from "@mittwald/api-client-commons";
|
|
54
|
-
import { Response } from "@mittwald/api-client-commons";
|
|
55
|
-
import { OpenAPIOperation } from "@mittwald/api-client-commons";
|
|
56
|
-
import { ${t.ns} } from "./types.js";
|
|
57
|
-
|
|
58
|
-
${t.descriptors}
|
|
59
|
-
`;
|
|
60
|
-
}
|
|
61
|
-
getFlattenedOperations(httpMethod) {
|
|
62
|
-
return this.paths
|
|
63
|
-
.flatMap((p) => p.operations)
|
|
64
|
-
.filter((p) => httpMethod === undefined ||
|
|
65
|
-
p.httpMethod.raw.toLowerCase() === httpMethod.toLowerCase());
|
|
66
|
-
}
|
|
67
|
-
getGroupedOperationsByTag(httpMethod) {
|
|
68
|
-
const result = new Map();
|
|
69
|
-
for (const operation of this.getFlattenedOperations(httpMethod)) {
|
|
70
|
-
for (const tag of operation.tags) {
|
|
71
|
-
const operationsOfTag = result.get(tag);
|
|
72
|
-
if (operationsOfTag) {
|
|
73
|
-
operationsOfTag.push(operation);
|
|
74
|
-
}
|
|
75
|
-
else {
|
|
76
|
-
result.set(tag, [operation]);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
return Array.from(result.entries());
|
|
81
|
-
}
|
|
82
|
-
compileClientMethodsOfTag(tag, operations) {
|
|
83
|
-
const t = {
|
|
84
|
-
tag: tag.name.tsVar,
|
|
85
|
-
comment: tag.description,
|
|
86
|
-
methods: operations
|
|
87
|
-
.map((op) => op.compileClientMethod(tag))
|
|
88
|
-
.join(",\r\n"),
|
|
89
|
-
};
|
|
90
|
-
return `\
|
|
91
|
-
/** ${t.comment} */
|
|
92
|
-
public readonly ${t.tag} = {
|
|
93
|
-
${t.methods}
|
|
94
|
-
}
|
|
95
|
-
`;
|
|
96
|
-
}
|
|
97
|
-
compileClient() {
|
|
98
|
-
const t = {
|
|
99
|
-
clientClassName: `${this.model.rootNamespace.tsType}Client`,
|
|
100
|
-
methods: this.getGroupedOperationsByTag()
|
|
101
|
-
.map(([tag, operations]) => this.compileClientMethodsOfTag(tag, operations))
|
|
102
|
-
.join("\r\n"),
|
|
103
|
-
};
|
|
104
|
-
return `\
|
|
105
|
-
import * as descriptors from "./descriptors.js";
|
|
106
|
-
import { ApiClientBase } from "@mittwald/api-client-commons";
|
|
107
|
-
|
|
108
|
-
export class ${t.clientClassName} extends ApiClientBase {
|
|
109
|
-
${t.methods}
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
export default ${t.clientClassName}
|
|
113
|
-
`;
|
|
114
|
-
}
|
|
115
|
-
compileReactClientApiName(tag) {
|
|
116
|
-
return `build${camelcase(tag.name.tsVar, {
|
|
117
|
-
pascalCase: true,
|
|
118
|
-
})}Api`;
|
|
119
|
-
}
|
|
120
|
-
compileReactClientApiBuilderOfTag(baseClientClassName, tag, operations) {
|
|
121
|
-
const t = {
|
|
122
|
-
apiName: this.compileReactClientApiName(tag),
|
|
123
|
-
methods: operations
|
|
124
|
-
.map((op) => op.compileReactClientMethod(tag))
|
|
125
|
-
.join(",\r\n"),
|
|
126
|
-
baseClientClassName,
|
|
127
|
-
};
|
|
128
|
-
return `\
|
|
129
|
-
const ${t.apiName} = (baseClient: ${t.baseClientClassName}) => ({
|
|
130
|
-
${t.methods}
|
|
131
|
-
})
|
|
132
|
-
`;
|
|
133
|
-
}
|
|
134
|
-
compileReactClientPropertyInitializer(tag) {
|
|
135
|
-
const tagName = tag.name.tsVar;
|
|
136
|
-
const t = {
|
|
137
|
-
apiName: this.compileReactClientApiName(tag),
|
|
138
|
-
comment: tag.description,
|
|
139
|
-
};
|
|
140
|
-
return `\
|
|
141
|
-
this.${tagName} = ${t.apiName}(baseClient);
|
|
142
|
-
`;
|
|
143
|
-
}
|
|
144
|
-
compileReactClientProperties(tag) {
|
|
145
|
-
const tagName = tag.name.tsVar;
|
|
146
|
-
const t = {
|
|
147
|
-
apiName: this.compileReactClientApiName(tag),
|
|
148
|
-
comment: tag.description,
|
|
149
|
-
};
|
|
150
|
-
return `\
|
|
151
|
-
/** ${t.comment} */
|
|
152
|
-
public readonly ${tagName}: ReturnType<typeof ${t.apiName}>;
|
|
153
|
-
`;
|
|
154
|
-
}
|
|
155
|
-
compileReactClient() {
|
|
156
|
-
const baseClientClassName = `${this.model.rootNamespace.tsType}Client`;
|
|
157
|
-
const clientClassName = `${this.model.rootNamespace.tsType}ClientReact`;
|
|
158
|
-
const t = {
|
|
159
|
-
baseClientClassName,
|
|
160
|
-
clientClassName,
|
|
161
|
-
apiBuilder: this.getGroupedOperationsByTag("GET")
|
|
162
|
-
.map(([tag, operations]) => this.compileReactClientApiBuilderOfTag(baseClientClassName, tag, operations))
|
|
163
|
-
.join("\r\n"),
|
|
164
|
-
clientProperties: this.getGroupedOperationsByTag("GET")
|
|
165
|
-
.map(([tag]) => this.compileReactClientProperties(tag))
|
|
166
|
-
.join("\r\n"),
|
|
167
|
-
clientPropertyInitializers: this.getGroupedOperationsByTag("GET")
|
|
168
|
-
.map(([tag]) => this.compileReactClientPropertyInitializer(tag))
|
|
169
|
-
.join("\r\n"),
|
|
170
|
-
};
|
|
171
|
-
return `\
|
|
172
|
-
import ${t.baseClientClassName} from "./client.js";
|
|
173
|
-
import { ApiCallAsyncResourceFactory } from "@mittwald/api-client-commons/react";
|
|
174
|
-
import * as descriptors from "./descriptors.js";
|
|
175
|
-
export * from "@mittwald/react-use-promise";
|
|
176
|
-
|
|
177
|
-
${t.apiBuilder}
|
|
178
|
-
|
|
179
|
-
export class ${t.clientClassName} {
|
|
180
|
-
${t.clientProperties}
|
|
181
|
-
|
|
182
|
-
private constructor(baseClient: ${t.baseClientClassName}) {
|
|
183
|
-
${t.clientPropertyInitializers}
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
public static fromBaseClient(baseClient: ${t.baseClientClassName}): ${t.clientClassName} {
|
|
187
|
-
return new ${t.clientClassName}(baseClient);
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
`;
|
|
191
|
-
}
|
|
192
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
export function populateNullableTypes(schema) {
|
|
2
|
-
if (!schema || "$ref" in schema) {
|
|
3
|
-
return schema;
|
|
4
|
-
}
|
|
5
|
-
if (schema.properties) {
|
|
6
|
-
for (const key in schema.properties) {
|
|
7
|
-
schema.properties[key] = populateNullableTypes(schema.properties[key]);
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
if ("items" in schema && schema.items) {
|
|
11
|
-
schema.items = populateNullableTypes(schema.items);
|
|
12
|
-
}
|
|
13
|
-
const compositionKeys = ["allOf", "anyOf", "oneOf"];
|
|
14
|
-
compositionKeys.forEach((key) => {
|
|
15
|
-
const entries = schema[key];
|
|
16
|
-
if (Array.isArray(entries)) {
|
|
17
|
-
schema[key] = entries.map(populateNullableTypes);
|
|
18
|
-
}
|
|
19
|
-
});
|
|
20
|
-
if (schema.nullable) {
|
|
21
|
-
return {
|
|
22
|
-
anyOf: [schema, { type: "null" }],
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
return schema;
|
|
26
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { splitRefNamespaces } from "./splitRefNamespaces.js";
|
|
2
|
-
export const extractComponentRefName = (ref, component) => {
|
|
3
|
-
const parts = splitRefNamespaces(ref);
|
|
4
|
-
if (parts[parts.length - 2] === component) {
|
|
5
|
-
return parts[parts.length - 1];
|
|
6
|
-
}
|
|
7
|
-
throw new Error(`Could not extract ref name (component: ${component}, ref: ${ref})`);
|
|
8
|
-
};
|
package/dist/esm/index.js
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export * from "./loading/UniversalContentLoader.js";
|
|
2
|
-
export * from "./loading/UniversalFileLoader.js";
|
|
3
|
-
export * from "./openapi/OpenApiSpec.js";
|
|
4
|
-
export * from "./generation/model/CodeGenerationModel.js";
|
|
5
|
-
export * from "./generation/prepareTypeScriptOutput.js";
|
|
6
|
-
export * from "./loading/UniversalFileLoader.js";
|
|
7
|
-
export * from "./lib/writeIfChangedAsync.js";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const format: (ts: string) => Promise<string>;
|
package/dist/types/index.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export * from "./loading/UniversalContentLoader.js";
|
|
2
|
-
export * from "./loading/UniversalFileLoader.js";
|
|
3
|
-
export * from "./openapi/OpenApiSpec.js";
|
|
4
|
-
export * from "./generation/model/CodeGenerationModel.js";
|
|
5
|
-
export * from "./generation/prepareTypeScriptOutput.js";
|
|
6
|
-
export * from "./loading/UniversalFileLoader.js";
|
|
7
|
-
export * from "./lib/writeIfChangedAsync.js";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const writeIfChangedAsync: (filename: string, content: string) => Promise<void>;
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
/package/dist/{types/generation → generation}/model/paths/operation/responses/ResponseContent.d.ts
RENAMED
|
File without changes
|
/package/dist/{esm/generation → generation}/model/paths/operation/responses/ResponseContent.js
RENAMED
|
File without changes
|
|
File without changes
|
/package/dist/{esm/generation → generation}/model/paths/operation/responses/ResponseContentTypes.js
RENAMED
|
File without changes
|
/package/dist/{types/generation → generation}/model/paths/operation/responses/Responses.d.ts
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|