Skip to content

Commit 5c980a5

Browse files
authored
Merge pull request #55 from cloudcome/feat/v0.x
Feat/v0.x
2 parents 40f3691 + 8ca712d commit 5c980a5

File tree

5 files changed

+21
-24
lines changed

5 files changed

+21
-24
lines changed

.github/workflows/code-review.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: code-review
1+
name: code review
22

33
on:
44
push:

.github/workflows/release-please.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: release-please
1+
name: release please
22

33
on:
44
push:

README.md

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
---
44

5-
[![code-review][code-review-badge]][code-review-link] [![code-quality][code-quality-badge]][code-quality-link] ![version][version-badge] ![license][license-badge]
5+
[![][code-review-badge]][code-review-link] [![][code-quality-badge]][code-quality-link] [![][code-coverage-badge]][code-coverage-link] ![][version-badge] ![][license-badge]
66

77
OpenAPI Specification ➡️ TypeScript
88

@@ -28,16 +28,13 @@ yarn add --dev oas-gen-ts
2828

2929
## CLI
3030

31-
Create oas.config.js or oas.json in the root directory of the project, and refer to [cosmiconfig](https://www.npmjs.com/package/cosmiconfig) for the file name specification.
32-
33-
The search order for configuration files is `oas.config.cjs`, `oas.config.js`, `oas.json`.
31+
Create oas.config.js or oas.json in the root directory of the project. The search order for configuration files is `oas.config.cjs`, `oas.config.js`, `oas.json`.
3432

3533
```js
3634
// oas.config.cjs
3735
const { defineConfig } = require('oas-gen-ts');
3836

3937
module.exports = defineConfig({
40-
axiosImport: `import { axios } from '@/util/axios';`,
4138
list: [
4239
{
4340
name: 'swagger/pet',
@@ -59,8 +56,6 @@ The generated file will be exported as one function and one operation, like this
5956
```ts
6057
// src/apis/swagger/pet.ts
6158

62-
import { axios } from '@/util/axios';
63-
6459
// ...
6560

6661
export interface Pet {
@@ -116,21 +111,21 @@ export async function findPetsByStatus(
116111
import { generate } from 'oas-gen-ts';
117112

118113
generate({
119-
// ...
114+
// ...config
120115
});
121116
```
122117

123118
# Config
124119

125-
| Name | Type | Required | Description | Default |
126-
| -------------------- | --------- | -------- | ------------------------------------------ | ----------------------------------------------- |
127-
| `cwd` | `string` | `false` | current working directory | `process.cwd()` |
128-
| `dest` | `string` | `false` | Destination directory for generated files | `src/apis` |
129-
| `axiosImport` | `string` | `false` | axios import string | Import from the official and create an instance |
130-
| `unwrapResponseData` | `boolean` | `false` | unwrap the data item from the response | `false` |
131-
| `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 | `[]` |
132127

133-
`Oas`:
128+
`OasItem`:
134129

135130
| Name | Type | Required | Description | Default |
136131
| ------------- | -------- | -------- | ----------------------------------------------- | ----------------------------------------------- |
@@ -145,5 +140,7 @@ generate({
145140
[code-review-link]: https://github.com/cloudcome/oas-gen-ts/actions/workflows/code-review.yml
146141
[code-quality-badge]: https://app.codacy.com/project/badge/Grade/e788387e5e27472ba3b5003bf19aeea7
147142
[code-quality-link]: https://www.codacy.com/gh/cloudcome/oas-gen-ts/dashboard?utm_source=github.com&utm_medium=referral&utm_content=cloudcome/oas-gen-ts&utm_campaign=Badge_Grade
143+
[code-coverage-badge]: https://app.codacy.com/project/badge/Coverage/e788387e5e27472ba3b5003bf19aeea7
144+
[code-coverage-link]: https://www.codacy.com/gh/cloudcome/oas-gen-ts/dashboard?utm_source=github.com&utm_medium=referral&utm_content=cloudcome/oas-gen-ts&utm_campaign=Badge_Coverage
148145
[version-badge]: https://img.shields.io/npm/v/oas-gen-ts
149146
[license-badge]: https://img.shields.io/github/license/cloudcome/oas-gen-ts

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)