Skip to content

Commit eb2ccfe

Browse files
committed
docs: add docs for swagger codegen
1 parent 95e7a4f commit eb2ccfe

File tree

1 file changed

+85
-2
lines changed

1 file changed

+85
-2
lines changed

docs/other/swagger-codegen.md

Lines changed: 85 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,86 @@
1-
# Swagger Codegen
1+
# Swagger Codegen
22

3-
**WIP**
3+
4+
## `mobx-tanstack-query-api`
5+
6+
This project is based on [`swagger-typescript-api`](https://github.com/acacode/swagger-typescript-api)
7+
8+
Github: https://github.com/js2me/mobx-tanstack-query-api
9+
NPM: http://npmjs.org/package/mobx-tanstack-query-api
10+
11+
::: warning
12+
Currently `mobx-tanstack-query-api` is a WIP project.
13+
This is not production ready.
14+
:::
15+
16+
### Steps to use
17+
18+
#### Install
19+
20+
::: code-group
21+
22+
```bash [npm]
23+
npm install mobx-tanstack-query-api
24+
```
25+
26+
```bash [yarn]
27+
yarn add mobx-tanstack-query-api
28+
```
29+
30+
```bash [pnpm]
31+
pnpm add mobx-tanstack-query-api
32+
```
33+
34+
:::
35+
36+
37+
#### Create configuration file
38+
39+
Create a codegen configuration file with file name `api-codegen.config.(js|mjs)` at root of your project.
40+
Add configuration using `defineConfig`
41+
42+
```ts
43+
import { defineConfig } from "mobx-tanstack-query-api/cli";
44+
import path from "path";
45+
46+
const __filename = fileURLToPath(import.meta.url);
47+
const __dirname = path.dirname(__filename);
48+
49+
export default defineConfig({
50+
// input: path.resolve(__dirname, './openapi.yaml'),
51+
input: "http://yourapi.com/url/openapi.yaml",
52+
output: path.resolve(__dirname, 'src/shared/api/__generated__'),
53+
httpClient: 'builtin',
54+
queryClient: 'builtin',
55+
endpoint: 'builtin',
56+
// namespace: 'collectedName',
57+
groupBy: 'tag',
58+
// groupBy: 'tag-1',
59+
// groupBy: 'path-segment',
60+
// groupBy: 'path-segment-1',
61+
filterRoutes: () => true,
62+
// groupBy: route => {
63+
// const api = apis.find(api => api.urls.some(url => route.raw.route.startsWith(url)))
64+
// return api?.name ?? 'other'
65+
// },
66+
formatExportGroupName: (groupName) => `${groupName}Api`,
67+
})
68+
```
69+
70+
#### Add script to `package.json`
71+
72+
```json
73+
...
74+
"scripts": {
75+
...
76+
"api-codegen": "mobx-tanstack-query-api"
77+
...
78+
}
79+
...
80+
```
81+
82+
#### Run
83+
84+
```bash
85+
npm run api-codegen
86+
```

0 commit comments

Comments
 (0)