@0kmpo/openapi-clean-arch-generator 1.3.10
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/.gitea/workflows/lint.yaml +41 -0
- package/.gitea/workflows/publish.yml +105 -0
- package/.openapi-generator-ignore +33 -0
- package/.prettierrc +7 -0
- package/LICENSE +21 -0
- package/README.md +333 -0
- package/dist/main.js +180 -0
- package/eslint.config.js +33 -0
- package/example-swagger.yaml +150 -0
- package/generation-config.json +24 -0
- package/main.ts +233 -0
- package/openapitools.json +23 -0
- package/package.json +70 -0
- package/src/generators/clean-arch.generator.ts +537 -0
- package/src/generators/dto.generator.ts +126 -0
- package/src/generators/lint.generator.ts +124 -0
- package/src/generators/report.generator.ts +80 -0
- package/src/swagger/analyzer.ts +32 -0
- package/src/types/cli.types.ts +36 -0
- package/src/types/generation.types.ts +50 -0
- package/src/types/index.ts +8 -0
- package/src/types/openapi.types.ts +126 -0
- package/src/types/swagger.types.ts +9 -0
- package/src/utils/config.ts +118 -0
- package/src/utils/environment-finder.ts +53 -0
- package/src/utils/filesystem.ts +31 -0
- package/src/utils/logger.ts +60 -0
- package/src/utils/mock-value-resolver.ts +70 -0
- package/src/utils/name-formatter.ts +12 -0
- package/src/utils/openapi-generator.ts +24 -0
- package/src/utils/prompt.ts +183 -0
- package/src/utils/type-mapper.ts +14 -0
- package/templates/api.repository.contract.mustache +34 -0
- package/templates/api.repository.impl.mock.mustache +21 -0
- package/templates/api.repository.impl.mustache +58 -0
- package/templates/api.repository.impl.spec.mustache +97 -0
- package/templates/api.use-cases.contract.mustache +34 -0
- package/templates/api.use-cases.impl.mustache +32 -0
- package/templates/api.use-cases.impl.spec.mustache +94 -0
- package/templates/api.use-cases.mock.mustache +21 -0
- package/templates/dto.mock.mustache +16 -0
- package/templates/mapper.mustache +28 -0
- package/templates/mapper.spec.mustache +39 -0
- package/templates/model-entity.mustache +24 -0
- package/templates/model-entity.spec.mustache +34 -0
- package/templates/model.mock.mustache +14 -0
- package/templates/model.mustache +20 -0
- package/templates/repository.provider.mock.mustache +20 -0
- package/templates/repository.provider.mustache +26 -0
- package/templates/use-cases.provider.mock.mustache +20 -0
- package/templates/use-cases.provider.mustache +26 -0
- package/tsconfig.json +17 -0
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
name: Lint
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
pull_request:
|
|
5
|
+
branches:
|
|
6
|
+
- '**'
|
|
7
|
+
|
|
8
|
+
jobs:
|
|
9
|
+
lint:
|
|
10
|
+
runs-on: ubuntu-latest
|
|
11
|
+
steps:
|
|
12
|
+
- name: Checkout
|
|
13
|
+
uses: actions/checkout@v4
|
|
14
|
+
|
|
15
|
+
- name: Cache Bun binary
|
|
16
|
+
uses: actions/cache@v4
|
|
17
|
+
with:
|
|
18
|
+
path: ~/.bun
|
|
19
|
+
key: bun-v1.3.3-${{ runner.os }}
|
|
20
|
+
|
|
21
|
+
- name: Setup Bun
|
|
22
|
+
run: |
|
|
23
|
+
if ! [ -f "$HOME/.bun/bin/bun" ]; then
|
|
24
|
+
curl -fsSL https://bun.sh/install | bash -s "bun-v1.3.3"
|
|
25
|
+
fi
|
|
26
|
+
echo "$HOME/.bun/bin" >> $GITHUB_PATH
|
|
27
|
+
|
|
28
|
+
- name: Cache dependencies
|
|
29
|
+
uses: actions/cache@v4
|
|
30
|
+
with:
|
|
31
|
+
path: ~/.bun/install/cache
|
|
32
|
+
key: ${{ runner.os }}-bun-deps-${{ hashFiles('bun.lock') }}
|
|
33
|
+
restore-keys: |
|
|
34
|
+
${{ runner.os }}-bun-deps-
|
|
35
|
+
|
|
36
|
+
- name: Install dependencies
|
|
37
|
+
run: bun install --frozen-lockfile
|
|
38
|
+
|
|
39
|
+
- name: Run lint
|
|
40
|
+
run: bun run lint
|
|
41
|
+
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
name: Publish
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
tags:
|
|
6
|
+
- 'v*'
|
|
7
|
+
|
|
8
|
+
jobs:
|
|
9
|
+
publish:
|
|
10
|
+
runs-on: ubuntu-latest
|
|
11
|
+
steps:
|
|
12
|
+
- name: Checkout
|
|
13
|
+
uses: actions/checkout@v4
|
|
14
|
+
|
|
15
|
+
- name: Cache Bun binary
|
|
16
|
+
uses: actions/cache@v4
|
|
17
|
+
with:
|
|
18
|
+
path: ~/.bun
|
|
19
|
+
key: bun-v1.3.3-${{ runner.os }}
|
|
20
|
+
|
|
21
|
+
- name: Setup Bun
|
|
22
|
+
run: |
|
|
23
|
+
if ! [ -f "$HOME/.bun/bin/bun" ]; then
|
|
24
|
+
curl -fsSL https://bun.sh/install | bash -s "bun-v1.3.3"
|
|
25
|
+
fi
|
|
26
|
+
echo "$HOME/.bun/bin" >> $GITHUB_PATH
|
|
27
|
+
|
|
28
|
+
- name: Set version from tag
|
|
29
|
+
run: |
|
|
30
|
+
VERSION=${GITHUB_REF_NAME#v}
|
|
31
|
+
echo "Setting package version to $VERSION"
|
|
32
|
+
bun -e "const fs=require('fs'); const pkg=JSON.parse(fs.readFileSync('package.json','utf8')); pkg.version='${VERSION}'; fs.writeFileSync('package.json',JSON.stringify(pkg,null,2)+'\n');"
|
|
33
|
+
SHA=$(curl -s -H "Authorization: token ${GITEA_TOKEN}" \
|
|
34
|
+
"https://git.blassanto.me/api/v1/repos/blas/openapi-clean-arch-gen/contents/package.json?ref=main" \
|
|
35
|
+
| bun -e "let d='';process.stdin.on('data',c=>d+=c).on('end',()=>console.log(JSON.parse(d).sha))")
|
|
36
|
+
CONTENT=$(base64 -w 0 package.json)
|
|
37
|
+
curl -s -X PUT \
|
|
38
|
+
-H "Authorization: token ${GITEA_TOKEN}" \
|
|
39
|
+
-H "Content-Type: application/json" \
|
|
40
|
+
"https://git.blassanto.me/api/v1/repos/blas/openapi-clean-arch-gen/contents/package.json" \
|
|
41
|
+
-d "{\"message\":\"chore: bump to version v${VERSION}\",\"content\":\"${CONTENT}\",\"sha\":\"${SHA}\",\"branch\":\"main\"}"
|
|
42
|
+
env:
|
|
43
|
+
GITEA_TOKEN: ${{ secrets.TOKEN }}
|
|
44
|
+
|
|
45
|
+
- name: Cache dependencies
|
|
46
|
+
uses: actions/cache@v4
|
|
47
|
+
with:
|
|
48
|
+
path: ~/.bun/install/cache
|
|
49
|
+
key: ${{ runner.os }}-bun-deps-${{ hashFiles('bun.lock') }}
|
|
50
|
+
restore-keys: |
|
|
51
|
+
${{ runner.os }}-bun-deps-
|
|
52
|
+
|
|
53
|
+
- name: Install dependencies
|
|
54
|
+
run: bun install --frozen-lockfile
|
|
55
|
+
|
|
56
|
+
- name: Lint
|
|
57
|
+
run: bun run lint
|
|
58
|
+
|
|
59
|
+
- name: Build
|
|
60
|
+
run: bun run build
|
|
61
|
+
|
|
62
|
+
- name: Build binaries
|
|
63
|
+
run: bun run binaries
|
|
64
|
+
|
|
65
|
+
- name: Configure npm registry auth
|
|
66
|
+
run: |
|
|
67
|
+
echo "registry=https://registry.npmjs.org" >> ~/.npmrc
|
|
68
|
+
echo "//registry.npmjs.org/:_authToken=${NODE_AUTH_TOKEN}" >> ~/.npmrc
|
|
69
|
+
env:
|
|
70
|
+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
|
71
|
+
|
|
72
|
+
- name: Publish to npm registry
|
|
73
|
+
run: bun publish --access public
|
|
74
|
+
env:
|
|
75
|
+
BUN_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
|
76
|
+
|
|
77
|
+
- name: Create Gitea release and upload binaries
|
|
78
|
+
run: |
|
|
79
|
+
VERSION=${GITHUB_REF_NAME#v}
|
|
80
|
+
|
|
81
|
+
RELEASE_ID=$(curl -s -X POST \
|
|
82
|
+
-H "Authorization: token ${GITEA_TOKEN}" \
|
|
83
|
+
-H "Content-Type: application/json" \
|
|
84
|
+
"https://git.blassanto.me/api/v1/repos/blas/openapi-clean-arch-gen/releases" \
|
|
85
|
+
-d "{
|
|
86
|
+
\"tag_name\": \"${GITHUB_REF_NAME}\",
|
|
87
|
+
\"name\": \"v${VERSION}\",
|
|
88
|
+
\"body\": \"## Installation\n\nDownload the binary for your platform or install via the npm registry:\n\n\`\`\`bash\nbun add -g @0kmpo/openapi-clean-arch-generator\n\`\`\`\",
|
|
89
|
+
\"draft\": false,
|
|
90
|
+
\"prerelease\": false
|
|
91
|
+
}" | bun -e "let d='';process.stdin.on('data',c=>d+=c).on('end',()=>console.log(JSON.parse(d).id))")
|
|
92
|
+
|
|
93
|
+
echo "Created release ID: $RELEASE_ID"
|
|
94
|
+
|
|
95
|
+
for BINARY in dist/bin/*; do
|
|
96
|
+
FILENAME=$(basename "$BINARY")
|
|
97
|
+
echo "Uploading $FILENAME..."
|
|
98
|
+
curl -s -X POST \
|
|
99
|
+
-H "Authorization: token ${GITEA_TOKEN}" \
|
|
100
|
+
-F "attachment=@${BINARY};filename=${FILENAME}" \
|
|
101
|
+
"https://git.blassanto.me/api/v1/repos/blas/openapi-clean-arch-gen/releases/${RELEASE_ID}/assets"
|
|
102
|
+
done
|
|
103
|
+
env:
|
|
104
|
+
GITEA_TOKEN: ${{ secrets.TOKEN }}
|
|
105
|
+
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# OpenAPI Generator Ignore File
|
|
2
|
+
# Archivos que no queremos generar
|
|
3
|
+
|
|
4
|
+
# DocumentaciΓ³n
|
|
5
|
+
README.md
|
|
6
|
+
.gitignore
|
|
7
|
+
git_push.sh
|
|
8
|
+
|
|
9
|
+
# NPM
|
|
10
|
+
.npmignore
|
|
11
|
+
package.json
|
|
12
|
+
package-lock.json
|
|
13
|
+
|
|
14
|
+
# TypeScript config
|
|
15
|
+
tsconfig.json
|
|
16
|
+
tsconfig.spec.json
|
|
17
|
+
|
|
18
|
+
# Angular specific
|
|
19
|
+
angular.json
|
|
20
|
+
karma.conf.js
|
|
21
|
+
|
|
22
|
+
# Tests que no usamos
|
|
23
|
+
*.spec.ts
|
|
24
|
+
|
|
25
|
+
# Variables de entorno
|
|
26
|
+
variables.ts
|
|
27
|
+
configuration.ts
|
|
28
|
+
|
|
29
|
+
# Encoder
|
|
30
|
+
encoder.ts
|
|
31
|
+
|
|
32
|
+
# API base que usamos nuestra propia implementaciΓ³n
|
|
33
|
+
api.ts
|
package/.prettierrc
ADDED
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Blas SantomΓ© Ocampo
|
|
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,333 @@
|
|
|
1
|
+
# OpenAPI Clean Architecture Generator
|
|
2
|
+
|
|
3
|
+
Angular code generator that creates clean architecture boilerplate from OpenAPI/Swagger specifications. Automates the creation of DTOs, repositories, mappers, use cases and dependency injection providers.
|
|
4
|
+
|
|
5
|
+
## π¦ Requirements
|
|
6
|
+
|
|
7
|
+
- [Bun](https://bun.sh) >= 1.0.0
|
|
8
|
+
- [Java](https://www.java.com) (required by `openapi-generator-cli`)
|
|
9
|
+
|
|
10
|
+
## π Installation
|
|
11
|
+
|
|
12
|
+
### Option 0: Prebuilt binary (no dependencies)
|
|
13
|
+
|
|
14
|
+
Download the binary for your platform from the releases page and run it directly β no Node, Bun or Java required:
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
# macOS (Apple Silicon)
|
|
18
|
+
curl -L https://git.blassanto.me/blas/openapi-clean-arch-gen/releases/latest/download/generate-clean-arch-macos-arm64 -o generate-clean-arch
|
|
19
|
+
chmod +x generate-clean-arch && ./generate-clean-arch -i swagger.yaml
|
|
20
|
+
|
|
21
|
+
# macOS (Intel)
|
|
22
|
+
curl -L https://git.blassanto.me/blas/openapi-clean-arch-gen/releases/latest/download/generate-clean-arch-macos-x64 -o generate-clean-arch
|
|
23
|
+
chmod +x generate-clean-arch && ./generate-clean-arch -i swagger.yaml
|
|
24
|
+
|
|
25
|
+
# Linux x64
|
|
26
|
+
curl -L https://git.blassanto.me/blas/openapi-clean-arch-gen/releases/latest/download/generate-clean-arch-linux-x64 -o generate-clean-arch
|
|
27
|
+
chmod +x generate-clean-arch && ./generate-clean-arch -i swagger.yaml
|
|
28
|
+
|
|
29
|
+
# Windows (PowerShell)
|
|
30
|
+
curl -L https://git.blassanto.me/blas/openapi-clean-arch-gen/releases/latest/download/generate-clean-arch-windows-x64.exe -o generate-clean-arch.exe
|
|
31
|
+
.\generate-clean-arch.exe -i swagger.yaml
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
### Option 1: Install as a global CLI from npm
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
bun add -g @0kmpo/openapi-clean-arch-generator
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Then run:
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
generate-clean-arch -i swagger.yaml
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### Option 2: Clone and use locally
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
git clone <repo>
|
|
50
|
+
cd openapi-clean-arch-generator
|
|
51
|
+
bun install
|
|
52
|
+
bun run setup # installs openapi-generator-cli globally
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## π Usage
|
|
56
|
+
|
|
57
|
+
### Basic command
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
# Installed globally
|
|
61
|
+
generate-clean-arch -i swagger.yaml
|
|
62
|
+
|
|
63
|
+
# From the repository (compiled)
|
|
64
|
+
bun run generate -- -i swagger.yaml
|
|
65
|
+
|
|
66
|
+
# From the repository (development, no compilation needed)
|
|
67
|
+
bun run generate:dev -- -i swagger.yaml
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### Available options
|
|
71
|
+
|
|
72
|
+
```
|
|
73
|
+
Options:
|
|
74
|
+
-V, --version Show version
|
|
75
|
+
-i, --input <file> OpenAPI/Swagger file (yaml or json) [default: swagger.yaml]
|
|
76
|
+
-o, --output <dir> Output directory [default: ./src/app]
|
|
77
|
+
-t, --templates <dir> Custom templates directory [default: ./templates]
|
|
78
|
+
-s, --select-endpoints Interactively select tags and endpoints to generate
|
|
79
|
+
--skip-install Skip dependency installation
|
|
80
|
+
--dry-run Simulate without writing files
|
|
81
|
+
-h, --help Show help
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### Examples
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
# Generate from swagger.yaml into src/app
|
|
88
|
+
generate-clean-arch -i swagger.yaml -o ./src/app
|
|
89
|
+
|
|
90
|
+
# Interactively select tags/endpoints
|
|
91
|
+
generate-clean-arch -i api.yaml -s
|
|
92
|
+
|
|
93
|
+
# Use custom templates
|
|
94
|
+
generate-clean-arch -i api.yaml -t ./my-templates
|
|
95
|
+
|
|
96
|
+
# Dry run (no files written)
|
|
97
|
+
generate-clean-arch -i swagger.yaml --dry-run
|
|
98
|
+
|
|
99
|
+
# Full example with all options
|
|
100
|
+
generate-clean-arch -i ./docs/api.yaml -o ./frontend/src/app -t ./custom-templates
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
## π Generated Structure
|
|
104
|
+
|
|
105
|
+
The generator creates the following structure following Clean Architecture:
|
|
106
|
+
|
|
107
|
+
```
|
|
108
|
+
src/app/
|
|
109
|
+
βββ data/ # Data layer
|
|
110
|
+
β βββ dtos/ # Data Transfer Objects
|
|
111
|
+
β β βββ node/
|
|
112
|
+
β β β βββ node.dto.ts
|
|
113
|
+
β β β βββ node.dto.mock.ts
|
|
114
|
+
β β βββ order-type/
|
|
115
|
+
β β β βββ order-type.dto.ts
|
|
116
|
+
β β β βββ order-type.dto.mock.ts
|
|
117
|
+
β β βββ supply-mode/
|
|
118
|
+
β β βββ supply-mode.dto.ts
|
|
119
|
+
β β βββ supply-mode.dto.mock.ts
|
|
120
|
+
β βββ repositories/ # Repository implementations
|
|
121
|
+
β β βββ node.repository.impl.ts
|
|
122
|
+
β β βββ node.repository.impl.mock.ts
|
|
123
|
+
β β βββ node.repository.impl.spec.ts
|
|
124
|
+
β β βββ order-type.repository.impl.ts
|
|
125
|
+
β β βββ order-type.repository.impl.mock.ts
|
|
126
|
+
β β βββ order-type.repository.impl.spec.ts
|
|
127
|
+
β β βββ ...
|
|
128
|
+
β βββ mappers/ # DTO β Entity transformers
|
|
129
|
+
β βββ node.mapper.ts
|
|
130
|
+
β βββ node.mapper.spec.ts
|
|
131
|
+
β βββ order-type.mapper.ts
|
|
132
|
+
β βββ order-type.mapper.spec.ts
|
|
133
|
+
β βββ ...
|
|
134
|
+
βββ domain/ # Domain layer
|
|
135
|
+
β βββ repositories/ # Repository contracts
|
|
136
|
+
β β βββ node.repository.contract.ts
|
|
137
|
+
β β βββ ...
|
|
138
|
+
β βββ use-cases/ # Use cases
|
|
139
|
+
β βββ node/
|
|
140
|
+
β β βββ node.use-cases.contract.ts
|
|
141
|
+
β β βββ node.use-cases.impl.ts
|
|
142
|
+
β β βββ node.use-cases.mock.ts
|
|
143
|
+
β β βββ node.use-cases.impl.spec.ts
|
|
144
|
+
β βββ ...
|
|
145
|
+
βββ di/ # Dependency injection
|
|
146
|
+
β βββ repositories/ # Repository providers
|
|
147
|
+
β β βββ node.repository.provider.ts
|
|
148
|
+
β β βββ node.repository.provider.mock.ts
|
|
149
|
+
β β βββ ...
|
|
150
|
+
β βββ use-cases/ # Use case providers
|
|
151
|
+
β βββ node.use-cases.provider.ts
|
|
152
|
+
β βββ node.use-cases.provider.mock.ts
|
|
153
|
+
β βββ ...
|
|
154
|
+
βββ entities/ # Domain entities
|
|
155
|
+
βββ models/
|
|
156
|
+
βββ node.model.ts
|
|
157
|
+
βββ node.model.mock.ts
|
|
158
|
+
βββ node.model.spec.ts
|
|
159
|
+
βββ ...
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
## π§ Template Customization
|
|
163
|
+
|
|
164
|
+
Templates live in `templates/` and use [Mustache](https://mustache.github.io/) syntax. Override them by passing your own directory with `-t`.
|
|
165
|
+
|
|
166
|
+
| Template | Generates |
|
|
167
|
+
|---|---|
|
|
168
|
+
| `model.mustache` | DTOs |
|
|
169
|
+
| `model.mock.mustache` | DTO mocks |
|
|
170
|
+
| `dto.mock.mustache` | DTO mocks (alternative) |
|
|
171
|
+
| `model-entity.mustache` | Domain entity models |
|
|
172
|
+
| `model-entity.spec.mustache` | Entity model specs |
|
|
173
|
+
| `mapper.mustache` | DTO β Entity mappers |
|
|
174
|
+
| `mapper.spec.mustache` | Mapper specs |
|
|
175
|
+
| `api.repository.contract.mustache` | Repository contracts |
|
|
176
|
+
| `api.repository.impl.mustache` | Repository implementations |
|
|
177
|
+
| `api.repository.impl.mock.mustache` | Repository mocks |
|
|
178
|
+
| `api.repository.impl.spec.mustache` | Repository specs |
|
|
179
|
+
| `api.use-cases.contract.mustache` | Use case contracts |
|
|
180
|
+
| `api.use-cases.impl.mustache` | Use case implementations |
|
|
181
|
+
| `api.use-cases.mock.mustache` | Use case mocks |
|
|
182
|
+
| `api.use-cases.impl.spec.mustache` | Use case specs |
|
|
183
|
+
| `repository.provider.mustache` | Repository DI providers |
|
|
184
|
+
| `repository.provider.mock.mustache` | Repository provider mocks |
|
|
185
|
+
| `use-cases.provider.mustache` | Use case DI providers |
|
|
186
|
+
| `use-cases.provider.mock.mustache` | Use case provider mocks |
|
|
187
|
+
|
|
188
|
+
### Available Mustache variables
|
|
189
|
+
|
|
190
|
+
```mustache
|
|
191
|
+
{{classname}} - Class name (e.g. "OrderType")
|
|
192
|
+
{{classVarName}} - camelCase name (e.g. "orderType")
|
|
193
|
+
{{classFilename}} - File name (e.g. "order-type")
|
|
194
|
+
{{constantName}} - UPPER_SNAKE_CASE constant (e.g. "ORDER_TYPE")
|
|
195
|
+
{{description}} - Schema description
|
|
196
|
+
{{httpMethod}} - HTTP method (get, post, put, deleteβ¦)
|
|
197
|
+
{{path}} - Endpoint path
|
|
198
|
+
{{nickname}} - Method name
|
|
199
|
+
{{allParams}} - All endpoint parameters
|
|
200
|
+
{{returnType}} - Return type
|
|
201
|
+
{{vars}} - Model variables
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
## π Generation Report
|
|
205
|
+
|
|
206
|
+
After each run a `generation-report.json` file is created:
|
|
207
|
+
|
|
208
|
+
```json
|
|
209
|
+
{
|
|
210
|
+
"timestamp": "2025-01-15T10:30:00.000Z",
|
|
211
|
+
"tags": 3,
|
|
212
|
+
"endpoints": 8,
|
|
213
|
+
"tagDetails": [
|
|
214
|
+
{ "name": "User", "description": "User operations", "endpoints": 3 },
|
|
215
|
+
{ "name": "Product", "description": "Product operations", "endpoints": 2 }
|
|
216
|
+
],
|
|
217
|
+
"outputDirectory": "./src/app",
|
|
218
|
+
"linting": {
|
|
219
|
+
"prettier": { "ran": true, "filesFormatted": 42 },
|
|
220
|
+
"eslint": { "ran": true, "filesFixed": 42 }
|
|
221
|
+
},
|
|
222
|
+
"structure": {
|
|
223
|
+
"dtos": 15,
|
|
224
|
+
"repositories": 9,
|
|
225
|
+
"mappers": 5,
|
|
226
|
+
"useCases": 6,
|
|
227
|
+
"providers": 12,
|
|
228
|
+
"mocks": 18,
|
|
229
|
+
"specs": 14
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
## π― Angular Integration Example
|
|
235
|
+
|
|
236
|
+
### 1. Generate code
|
|
237
|
+
|
|
238
|
+
```bash
|
|
239
|
+
generate-clean-arch -i ./docs/api.yaml -o ./src/app
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
### 2. Register providers
|
|
243
|
+
|
|
244
|
+
In your `app.config.ts` (Angular 17+ standalone):
|
|
245
|
+
|
|
246
|
+
```typescript
|
|
247
|
+
import { ApplicationConfig } from '@angular/core';
|
|
248
|
+
import { NodeRepositoryProvider } from './di/repositories/node.repository.provider';
|
|
249
|
+
import { NodeUseCasesProvider } from './di/use-cases/node.use-cases.provider';
|
|
250
|
+
|
|
251
|
+
export const appConfig: ApplicationConfig = {
|
|
252
|
+
providers: [
|
|
253
|
+
NodeRepositoryProvider,
|
|
254
|
+
NodeUseCasesProvider,
|
|
255
|
+
// ... rest of generated providers
|
|
256
|
+
]
|
|
257
|
+
};
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
### 3. Use in components
|
|
261
|
+
|
|
262
|
+
```typescript
|
|
263
|
+
import { Component, inject } from '@angular/core';
|
|
264
|
+
import { NODE_USE_CASES } from './domain/use-cases/node/node.use-cases.contract';
|
|
265
|
+
|
|
266
|
+
@Component({
|
|
267
|
+
selector: 'app-nodes',
|
|
268
|
+
template: `...`
|
|
269
|
+
})
|
|
270
|
+
export class NodesComponent {
|
|
271
|
+
readonly #nodeUseCases = inject(NODE_USE_CASES);
|
|
272
|
+
|
|
273
|
+
loadNodes(): void {
|
|
274
|
+
this.#nodeUseCases.getNodes().subscribe((nodes) => {
|
|
275
|
+
console.log(nodes);
|
|
276
|
+
});
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
## π Troubleshooting
|
|
282
|
+
|
|
283
|
+
### `openapi-generator-cli` not found
|
|
284
|
+
|
|
285
|
+
```bash
|
|
286
|
+
bun run setup
|
|
287
|
+
# or manually:
|
|
288
|
+
bun add -g @openapitools/openapi-generator-cli
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
### swagger.yaml file not found
|
|
292
|
+
|
|
293
|
+
Specify the correct path with `-i`:
|
|
294
|
+
|
|
295
|
+
```bash
|
|
296
|
+
generate-clean-arch -i ./path/to/your/api.yaml
|
|
297
|
+
```
|
|
298
|
+
|
|
299
|
+
### Path aliases `@/` not resolving
|
|
300
|
+
|
|
301
|
+
Configure the aliases in your Angular project's `tsconfig.json`:
|
|
302
|
+
|
|
303
|
+
```json
|
|
304
|
+
{
|
|
305
|
+
"compilerOptions": {
|
|
306
|
+
"paths": {
|
|
307
|
+
"@/*": ["src/app/*"]
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
```
|
|
312
|
+
|
|
313
|
+
### Templates not generating expected code
|
|
314
|
+
|
|
315
|
+
1. Make sure your templates are in `./templates/` or pass the path with `-t`
|
|
316
|
+
2. Check the Mustache syntax
|
|
317
|
+
3. Use `--dry-run` to simulate without writing files
|
|
318
|
+
|
|
319
|
+
## π Notes
|
|
320
|
+
|
|
321
|
+
- The generator produces ready-to-use `.ts` files, it does not compile them
|
|
322
|
+
- Providers must be registered manually in your Angular module or config
|
|
323
|
+
- Requires Angular 17+ (uses the `inject()` function)
|
|
324
|
+
- Compatible with both standalone and module-based projects
|
|
325
|
+
|
|
326
|
+
## π€ Contributing
|
|
327
|
+
|
|
328
|
+
Found a bug or have an improvement? Open an issue or PR in the repository.
|
|
329
|
+
|
|
330
|
+
## π License
|
|
331
|
+
|
|
332
|
+
MIT
|
|
333
|
+
|