You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
English | <ahref="https://github.com/openapi-ui/openapi-ts-request/blob/master/README.md">简体中文</a>
8
+
9
+
Generate TS interfaces, request client, request mock service, enum, type field label, JSON Schemas based on [Swagger2/OpenAPI3](https://swagger.io/blog/news/whats-new-in-openapi-3-0/) specification
10
+
11
+
## Features
12
+
13
+
* support Swagger2.0/OpenAPI 3.0,3.1 specification
14
+
* generate TypeScript interface, reuquest client, request mock service, enum, type field label, JSON Schemas
15
+
* support custom request function, Fetch、Axios、UniApp-request、Node.js、XHR client available
16
+
* support filter generate result by tags
17
+
* support JSON specification
18
+
19
+
## Usage
20
+
21
+
```bash
22
+
npm i openapi-ts-request --save-dev
23
+
24
+
pnpm i openapi-ts-request -D
25
+
```
26
+
27
+
### CosmiConfig
28
+
29
+
create ```openapi-ts-request.config.ts``` file in the project root directory
30
+
> the config file also supports ***.openapi-ts-request.ts***, ***openapi-ts-request.config.cjs*** format, reference [cosmiconfig](https://github.com/cosmiconfig/cosmiconfig?tab=readme-ov-file#cosmiconfig)
| customFunctionName | (data: APIDataType) => string | custom request client function name |
127
+
| customTypeName | (data: APIDataType) => string | custom type name |
128
+
| customClassName | (tagName: string) => string | custom tag name |
129
+
| customType | (<br>schemaObject: SchemaObject \| ReferenceObject,<br>namespace: string,<br>originGetType:(schemaObject: SchemaObject \| ReferenceObject, namespace: string) => string,<br>) => string | custom type <br> *returning a non-string will use the default method to get the type*|
130
+
| customFileNames | (<br>operationObject: OperationObject,<br>apiPath: string,<br>apiMethod: string,<br>) => string[]| custom generate request client controller file name, can return multiple: generate multiple files. <br> *if the return value is empty, the default getFileNames is used*|
131
+
132
+
## JSON Schemas
133
+
134
+
- default generate JSON Schemas based on [components.schemas](https://spec.openapis.org/oas/latest.html#components-object), JSON Schemas corresponding to [paths](https://spec.openapis.org/oas/latest.html#paths-object) currently need to be parsed by yourself
135
+
- provide a schema parsing function to fill the references of `$ref` and `$allOf` into `current schema`
currently using [mockjs](http://mockjs.com) to generate mock data, the mocks file startup needs to rely on [@umijs/server](https://umijs.org/docs/guides/mock), we will look for other solutions later to achieve a better mock experience
0 commit comments