@mittwald/api-code-generator 0.0.0-development-04b7288-20240610
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/LICENSE +21 -0
- package/README.md +73 -0
- package/bin/cli.js +8 -0
- package/package.json +86 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
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.
|
package/README.md
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
Common code base used by `@mittwald/api-client-*` package.
|
|
2
|
+
|
|
3
|
+
## CLI
|
|
4
|
+
|
|
5
|
+
Use the CLI commands provided by this package to build your API client and
|
|
6
|
+
validate the OpenAPI-Spec:
|
|
7
|
+
|
|
8
|
+
```shell
|
|
9
|
+
acg validate spec/openapi.json
|
|
10
|
+
acg generate --name MittwaldAPIV2 spec/openapi.json src/generated --optionalHeader x-access-token
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## TypeScript API
|
|
14
|
+
|
|
15
|
+
If you need to generate the client in code, you can use the TypeScript API
|
|
16
|
+
demonstrated in this template:
|
|
17
|
+
|
|
18
|
+
```typescript
|
|
19
|
+
import * as path from "path";
|
|
20
|
+
import { UniversalContentLoader } from "@mittwald/api-code-generator/js";
|
|
21
|
+
import { UniversalFileLoader } from "@mittwald/api-code-generator/js";
|
|
22
|
+
import { OpenApiSpec } from "@mittwald/api-code-generator/js";
|
|
23
|
+
import { CodeGenerationModel } from "@mittwald/api-code-generator/js";
|
|
24
|
+
import { prepareTypeScriptOutput } from "@mittwald/api-code-generator/js";
|
|
25
|
+
import { writeIfChangedAsync } from "@mittwald/api-code-generator/js";
|
|
26
|
+
|
|
27
|
+
const name = "MittwaldAPIV2";
|
|
28
|
+
const inout = `${process.cwd()}/spec/openapi.json`;
|
|
29
|
+
const output = `${process.cwd()}/src/generated`;
|
|
30
|
+
|
|
31
|
+
// Loading OpenAPI spec
|
|
32
|
+
const loader = new UniversalContentLoader(new UniversalFileLoader(input));
|
|
33
|
+
const openApiDoc = await loader.load();
|
|
34
|
+
|
|
35
|
+
// Parsing OpenAPI spec
|
|
36
|
+
const spec = await OpenApiSpec.parse(openApiDoc, {
|
|
37
|
+
skipValidation: flags.skipValidation,
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
// Building transformation model
|
|
41
|
+
const model = CodeGenerationModel.fromDoc(name, spec.document);
|
|
42
|
+
|
|
43
|
+
// Generating descriptors
|
|
44
|
+
const descriptorsFileContent = model.paths.compileDescriptors();
|
|
45
|
+
await writeIfChangedAsync(
|
|
46
|
+
path.join(output, "descriptors.ts"),
|
|
47
|
+
await prepareTypeScriptOutput(descriptorsFileContent),
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
// Generating types
|
|
51
|
+
const typesFileContent = await model.compileTypes({
|
|
52
|
+
rootNamespace: flags.name,
|
|
53
|
+
optionalHeaders: ["x-access-token"],
|
|
54
|
+
});
|
|
55
|
+
await writeIfChangedAsync(
|
|
56
|
+
path.join(output, "types.ts"),
|
|
57
|
+
await prepareTypeScriptOutput(typesFileContent),
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
// Generating client
|
|
61
|
+
const clientFileContent = model.paths.compileClient();
|
|
62
|
+
await writeIfChangedAsync(
|
|
63
|
+
path.join(output, "client.ts"),
|
|
64
|
+
await prepareTypeScriptOutput(clientFileContent),
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
// if needed: Generating React client
|
|
68
|
+
const reactClientFileContent = model.paths.compileReactClient();
|
|
69
|
+
await writeIfChangedAsync(
|
|
70
|
+
path.join(output, "client-react.ts"),
|
|
71
|
+
await prepareTypeScriptOutput(reactClientFileContent),
|
|
72
|
+
);
|
|
73
|
+
```
|
package/bin/cli.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@mittwald/api-code-generator",
|
|
3
|
+
"version": "0.0.0-development-04b7288-20240610",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"repository": "https://github.com/mittwald/api-client-js.git",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": "./bin/cli.js",
|
|
9
|
+
"./js": {
|
|
10
|
+
"types": "./dist/types/index.d.ts",
|
|
11
|
+
"default": "./dist/esm/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"bin": {
|
|
15
|
+
"acg": "./bin/cli.js"
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"dist"
|
|
19
|
+
],
|
|
20
|
+
"scripts": {
|
|
21
|
+
"build": "run build:clean && yarn tsc",
|
|
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": "node --experimental-vm-modules $(yarn bin jest)"
|
|
26
|
+
},
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"@oclif/core": "^3.23.0",
|
|
29
|
+
"@oclif/plugin-help": "^6.0.18",
|
|
30
|
+
"@oclif/plugin-plugins": "^4.3.3",
|
|
31
|
+
"@sindresorhus/is": "^6.2.0",
|
|
32
|
+
"@types/clone-deep": "^4.0.4",
|
|
33
|
+
"@types/invariant": "^2.2.37",
|
|
34
|
+
"@types/js-yaml": "^4.0.9",
|
|
35
|
+
"@types/prettier": "^3.0.0",
|
|
36
|
+
"@types/verror": "^1.10.10",
|
|
37
|
+
"@types/yieldable-json": "^2.0.2",
|
|
38
|
+
"axios": "^1.6.7",
|
|
39
|
+
"camelcase": "^8.0.0",
|
|
40
|
+
"clone-deep": "^4.0.1",
|
|
41
|
+
"dot-prop": "^8.0.2",
|
|
42
|
+
"fs-jetpack": "^5.1.0",
|
|
43
|
+
"get-stdin": "^9.0.0",
|
|
44
|
+
"invariant": "^2.2.4",
|
|
45
|
+
"js-yaml": "^4.1.0",
|
|
46
|
+
"json-schema-to-typescript": "^13.1.2",
|
|
47
|
+
"openapi-schema-validator": "^12.1.3",
|
|
48
|
+
"openapi-types": "^12.1.3",
|
|
49
|
+
"prettier": "^3.2.5",
|
|
50
|
+
"swagger2openapi": "^7.0.8",
|
|
51
|
+
"type-fest": "^4.12.0",
|
|
52
|
+
"verror": "^1.10.1",
|
|
53
|
+
"yieldable-json": "^2.0.1",
|
|
54
|
+
"zod": "^3.22.4",
|
|
55
|
+
"zod-validation-error": "^3.0.3"
|
|
56
|
+
},
|
|
57
|
+
"devDependencies": {
|
|
58
|
+
"@jest/globals": "^29.7.0",
|
|
59
|
+
"@types/jest": "^29.5.12",
|
|
60
|
+
"@types/swagger2openapi": "^7.0.4",
|
|
61
|
+
"@typescript-eslint/eslint-plugin": "^7.1.1",
|
|
62
|
+
"@typescript-eslint/parser": "^7.1.1",
|
|
63
|
+
"eslint": "^8.57.0",
|
|
64
|
+
"eslint-config-prettier": "^9.1.0",
|
|
65
|
+
"eslint-plugin-json": "^3.1.0",
|
|
66
|
+
"eslint-plugin-prettier": "^5.1.3",
|
|
67
|
+
"jest": "^29.7.0",
|
|
68
|
+
"prettier": "^3.2.5",
|
|
69
|
+
"prettier-plugin-jsdoc": "^1.3.0",
|
|
70
|
+
"prettier-plugin-pkgsort": "^0.2.1",
|
|
71
|
+
"prettier-plugin-sort-json": "^3.1.0",
|
|
72
|
+
"rimraf": "^5.0.5",
|
|
73
|
+
"ts-jest": "^29.1.2",
|
|
74
|
+
"typescript": "^5.4.2"
|
|
75
|
+
},
|
|
76
|
+
"oclif": {
|
|
77
|
+
"bin": "acg",
|
|
78
|
+
"dirname": "acg",
|
|
79
|
+
"commands": "./dist/esm/commands",
|
|
80
|
+
"plugins": [
|
|
81
|
+
"@oclif/plugin-help",
|
|
82
|
+
"@oclif/plugin-plugins"
|
|
83
|
+
]
|
|
84
|
+
},
|
|
85
|
+
"gitHead": "97660b1fee614cc23b778573ba3e8ae75a961517"
|
|
86
|
+
}
|