Skip to content

Commit fb901bc

Browse files
committed
feat(nx-plugin): add nx plugin to generate and update client code
1 parent eda1829 commit fb901bc

34 files changed

+3719
-6
lines changed

Diff for: packages/nx-plugin/LICENSE.md

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) Hey API
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.

Diff for: packages/nx-plugin/README.md

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# @hey-api/nx-plugin
2+
3+
This plugin provides a generator and executor for generating and updating OpenAPI clients using the `@hey-api/openapi-ts` library. This can be tied in to automation and CI workflows to ensure your API clients are always up to date.
4+
5+
## Installation
6+
7+
```bash
8+
npm install -D @hey-api/plugin-nx
9+
```
10+
11+
## Usage
12+
13+
### Generators
14+
15+
#### openapi-client
16+
17+
[Docs](src/generators/openapi-client/README.md)
18+
19+
This plugin provides a generator for generating OpenAPI clients using the `@hey-api/openapi-ts` library.
20+
21+
Run in interactive mode `nx g @hey-api/nx-plugin:openapi-client`
22+
23+
##### Options
24+
25+
- `name`: The name of the project. [ string ] (required)
26+
- `scope`: The scope of the project. [ string ] (required)
27+
- `spec`: The path to the OpenAPI spec file. [ URI or string ] (required)
28+
- `directory`: The directory to create the project in. [ string ] (optional) (default: `libs`)
29+
- `client`: The type of client to generate. [ string ] (optional) (default: `@hey-api/client-fetch`)
30+
To specify a specific version of the client you can use `@hey-api/[email protected]`.
31+
- `tags`: The tags to add to the project. [ string[] ] (optional) (default: `api,openapi`)
32+
The defaults tags will not be added to the project if you specify this option.
33+
- `plugins`: Additional plugins to provide to the client api. [ string[] ] (optional)
34+
- `test`: The type of tests to setup. [ 'none' | 'vitest' ] (optional) (default: `none`)
35+
36+
##### Example
37+
38+
```bash
39+
nx g @hey-api/nx-plugin:openapi-client --name=my-api --client=@hey-api/client-fetch --scope=@my-app --directory=libs --spec=./spec.yaml --tags=api,openapi
40+
```
41+
42+
### Executors
43+
44+
#### update-api
45+
46+
This executor updates the OpenAPI spec file and generates a new client.
47+
The options for the executor will be populated from the generator.
48+
49+
Run `nx run @my-org/my-generated-package:updateApi`
50+
51+
##### Options
52+
53+
- `spec`: The path to the OpenAPI spec file. [ URI or string ] (required)
54+
- `name`: The name of the project. [ string ] (required)
55+
- `scope`: The scope of the project. [ string ] (required)
56+
- `client`: The type of client to generate. [ string ] (optional) (default: `@hey-api/client-fetch`)
57+
- `directory`: The directory to create the project in. [ string ] (optional) (default: `libs`)
58+
- `plugins`: Additional plugins to provide to the client api. [ string[] ] (optional) (default:[])

Diff for: packages/nx-plugin/executors.json

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"executors": {
3+
"update-api": {
4+
"implementation": "./dist/executors/update-api/index.js",
5+
"schema": "./dist/executors/update-api/schema.json",
6+
"description": "Updates the OpenAPI spec file and generates new client code if needed."
7+
}
8+
}
9+
}

Diff for: packages/nx-plugin/generators.json

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"name": "openapi-generator",
3+
"version": "0.0.1",
4+
"generators": {
5+
"openapi-client": {
6+
"factory": "./dist/generators/openapi-client/index.js",
7+
"schema": "./dist/generators/openapi-client/schema.json",
8+
"description": "Generate an OpenAPI client library from an OpenAPI spec file."
9+
}
10+
}
11+
}

Diff for: packages/nx-plugin/package.json

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
{
2+
"name": "@hey-api/nx-plugin",
3+
"version": "0.0.1",
4+
"description": "🚀 Nx plugin for `@hey-api/openapi-ts` codegen.",
5+
"homepage": "https://heyapi.dev/",
6+
"repository": {
7+
"type": "git",
8+
"url": "git+https://github.com/hey-api/openapi-ts.git",
9+
"directory": "packages/nx-plugin"
10+
},
11+
"bugs": {
12+
"url": "https://github.com/hey-api/openapi-ts/issues"
13+
},
14+
"license": "MIT",
15+
"author": {
16+
"email": "[email protected]",
17+
"name": "Hey API",
18+
"url": "https://heyapi.dev"
19+
},
20+
"funding": "https://github.com/sponsors/hey-api",
21+
"keywords": [
22+
"codegen",
23+
"openapi",
24+
"plugin",
25+
"nx",
26+
"swagger"
27+
],
28+
"type": "commonjs",
29+
"main": "./dist/index.js",
30+
"module": "./dist/index.js",
31+
"types": "./dist/index.d.ts",
32+
"scripts": {
33+
"build": "tsup && pnpm check-exports",
34+
"check-exports": "attw --pack .",
35+
"test:watch": "vitest watch --config vitest.config.ts",
36+
"test": "vitest run --config vitest.config.ts",
37+
"typecheck": "tsc --noEmit",
38+
"prepublishOnly": "pnpm build"
39+
},
40+
"exports": {
41+
"./package.json": "./package.json",
42+
".": {
43+
"development": "./src/index.ts",
44+
"types": "./dist/index.d.ts",
45+
"import": "./dist/index.js",
46+
"default": "./dist/index.js"
47+
}
48+
},
49+
"executors": "./executors.json",
50+
"generators": "./generators.json",
51+
"dependencies": {
52+
"@hey-api/json-schema-ref-parser": "1.0.4",
53+
"@hey-api/openapi-ts": "workspace:*",
54+
"@nx/devkit": "20.7.2",
55+
"latest-version": "9.0.0",
56+
"openapi-diff": "0.23.7",
57+
"tslib": "2.8.1",
58+
"xcurl": "2.1.2"
59+
},
60+
"devDependencies": {
61+
"@config/vite-base": "workspace:*",
62+
"typescript": "5.8.3",
63+
"vitest": "3.1.1"
64+
},
65+
"files": [
66+
"dist",
67+
"LICENSE.md",
68+
"generators.json",
69+
"executors.json"
70+
]
71+
}

0 commit comments

Comments
 (0)