Skip to content

Commit

Permalink
fix: 类型优化
Browse files Browse the repository at this point in the history
  • Loading branch information
cloudcome committed Mar 16, 2023
1 parent eda7a6e commit 8ca712d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 18 deletions.
21 changes: 9 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ Create oas.config.js or oas.json in the root directory of the project. The searc
const { defineConfig } = require('oas-gen-ts');

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

import { axios } from '@/util/axios';

// ...

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

generate({
// ...
// ...config
});
```

# Config

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

`Oas`:
`OasItem`:

| Name | Type | Required | Description | Default |
| ------------- | -------- | -------- | ----------------------------------------------- | ----------------------------------------------- |
Expand Down
4 changes: 2 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ export interface OasItemAsUrl extends OasItemBase {
url: string;
}

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

export interface OasItemAsSpec extends OasItemBase {
spec: Oas;
spec: Spec;
}

export type OasItem = OasItemAsUrl | OasItemAsSpec;
Expand Down
8 changes: 4 additions & 4 deletions test/generator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { random } from 'lodash-es';
import path from 'path';
import { cleanDir, isFile } from 'src/utils';
import { afterEach, beforeAll, beforeEach, describe, expect, test, vi } from 'vitest';
import { generate, Generated, GenerateInfo, generateItem, Oas } from '../src';
import { generate, Generated, GenerateInfo, generateItem, Spec } from '../src';
import petstore3 from './petstore3.json';

describe('generate-item', () => {
Expand Down Expand Up @@ -42,7 +42,7 @@ describe('generate-item', () => {
const generated = await generateItem(
{
name,
spec: petstore3 as unknown as Oas,
spec: petstore3 as unknown as Spec,
},
config
);
Expand All @@ -63,11 +63,11 @@ test('generate', async () => {
list: [
{
name: random(1, 1000).toString(),
spec: petstore3 as unknown as Oas,
spec: petstore3 as unknown as Spec,
},
{
name: random(1, 1000).toString(),
spec: petstore3 as unknown as Oas,
spec: petstore3 as unknown as Spec,
},
],
unwrapResponseData: false,
Expand Down

0 comments on commit 8ca712d

Please sign in to comment.