Skip to content

Commit 8ca712d

Browse files
committed
fix: 类型优化
1 parent eda7a6e commit 8ca712d

File tree

3 files changed

+15
-18
lines changed

3 files changed

+15
-18
lines changed

README.md

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ Create oas.config.js or oas.json in the root directory of the project. The searc
3535
const { defineConfig } = require('oas-gen-ts');
3636

3737
module.exports = defineConfig({
38-
axiosImport: `import { axios } from '@/util/axios';`,
3938
list: [
4039
{
4140
name: 'swagger/pet',
@@ -57,8 +56,6 @@ The generated file will be exported as one function and one operation, like this
5756
```ts
5857
// src/apis/swagger/pet.ts
5958

60-
import { axios } from '@/util/axios';
61-
6259
// ...
6360

6461
export interface Pet {
@@ -114,21 +111,21 @@ export async function findPetsByStatus(
114111
import { generate } from 'oas-gen-ts';
115112

116113
generate({
117-
// ...
114+
// ...config
118115
});
119116
```
120117

121118
# Config
122119

123-
| Name | Type | Required | Description | Default |
124-
| -------------------- | --------- | -------- | ------------------------------------------ | ----------------------------------------------- |
125-
| `cwd` | `string` | `false` | current working directory | `process.cwd()` |
126-
| `dest` | `string` | `false` | Destination directory for generated files | `src/apis` |
127-
| `axiosImport` | `string` | `false` | axios import string | Import from the official and create an instance |
128-
| `unwrapResponseData` | `boolean` | `false` | unwrap the data item from the response | `false` |
129-
| `list` | `OAS[]` | `false` | List of OpenAPI Specification declarations | `[]` |
120+
| Name | Type | Required | Description | Default |
121+
| -------------------- | ----------- | -------- | ------------------------------------------ | ----------------------------------------------- |
122+
| `cwd` | `string` | `false` | current working directory | `process.cwd()` |
123+
| `dest` | `string` | `false` | Destination directory for generated files | `src/apis` |
124+
| `axiosImport` | `string` | `false` | axios import string | Import from the official and create an instance |
125+
| `unwrapResponseData` | `boolean` | `false` | unwrap the data item from the response | `false` |
126+
| `list` | `OasItem[]` | `false` | List of OpenAPI Specification declarations | `[]` |
130127

131-
`Oas`:
128+
`OasItem`:
132129

133130
| Name | Type | Required | Description | Default |
134131
| ------------- | -------- | -------- | ----------------------------------------------- | ----------------------------------------------- |

src/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ export interface OasItemAsUrl extends OasItemBase {
1414
url: string;
1515
}
1616

17-
export type Oas = import('swagger-schema-official').Spec;
17+
export type Spec = import('swagger-schema-official').Spec;
1818

1919
export interface OasItemAsSpec extends OasItemBase {
20-
spec: Oas;
20+
spec: Spec;
2121
}
2222

2323
export type OasItem = OasItemAsUrl | OasItemAsSpec;

test/generator.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { random } from 'lodash-es';
22
import path from 'path';
33
import { cleanDir, isFile } from 'src/utils';
44
import { afterEach, beforeAll, beforeEach, describe, expect, test, vi } from 'vitest';
5-
import { generate, Generated, GenerateInfo, generateItem, Oas } from '../src';
5+
import { generate, Generated, GenerateInfo, generateItem, Spec } from '../src';
66
import petstore3 from './petstore3.json';
77

88
describe('generate-item', () => {
@@ -42,7 +42,7 @@ describe('generate-item', () => {
4242
const generated = await generateItem(
4343
{
4444
name,
45-
spec: petstore3 as unknown as Oas,
45+
spec: petstore3 as unknown as Spec,
4646
},
4747
config
4848
);
@@ -63,11 +63,11 @@ test('generate', async () => {
6363
list: [
6464
{
6565
name: random(1, 1000).toString(),
66-
spec: petstore3 as unknown as Oas,
66+
spec: petstore3 as unknown as Spec,
6767
},
6868
{
6969
name: random(1, 1000).toString(),
70-
spec: petstore3 as unknown as Oas,
70+
spec: petstore3 as unknown as Spec,
7171
},
7272
],
7373
unwrapResponseData: false,

0 commit comments

Comments
 (0)