Skip to content

Commit 131225d

Browse files
authored
release 1.4.0 (#20)
* test(internal): speed improve validate generated ts api modules * BREAKING_CHANGE: default typescript api file name (api.ts -> Api.ts) * feat: improve response body type definitions * chore(docs): add gtihub funding * [Bugfix] Response type does not de-reference $refs (#19) * chore: add common test schemas * refactor: encapsulate nodejs.fs module usage; feat: dereference components responses + improve types * chore: add specific comments for calling src/index.js on unix like machines via nodejs * chore: update gitignore (add hidden test cli file) * fix: JSDOC comments * [Features] - response declarations, "default" status codes as success response types (#17) * feat: add @returns keywords into each request comments description (request responses) * feat: prettify descriptions * feat: add response declarations in request description; feat: typed bad responses * feat: -d, --default-as-success option (ability to use "default" success response status code) * chore: add common test schemas * fix: description of defaultResponseAsSuccess option * chore: rename setConfig to addToConfig * chore: add specific comments for calling src/index.js on unix like machines via nodejs * feat: move responses declarations into flag '-r, --responses'; chore(test): add manual test for new option; docs: update CHANGELOG + README * fix: format description (end \n character) * bump: up version to 1.4.0
1 parent 36524ef commit 131225d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+10136
-8360
lines changed

.github/FUNDING.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
open_collective: acacode
2+
ko_fi: acacode

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
node_modules
22
.vscode
3-
swagger-test-cli.ts
3+
swagger-test-cli.*

.vscode/launch.json

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,22 @@
55
"version": "0.2.0",
66
"configurations": [
77
{
8-
"name": "Launch via npm",
8+
"name": "Debug generate",
99
"type": "node",
1010
"request": "launch",
1111
"cwd": "${workspaceFolder}",
1212
"runtimeExecutable": "npm",
1313
"runtimeArgs": ["run-script", "generate:debug"],
1414
"port": 9229
15+
},
16+
{
17+
"name": "Debug CLI",
18+
"type": "node",
19+
"request": "launch",
20+
"cwd": "${workspaceFolder}",
21+
"runtimeExecutable": "npm",
22+
"runtimeArgs": ["run-script", "cli:debug"],
23+
"port": 9229
1524
}
1625
]
1726
}

CHANGELOG.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
# 1.4.0
2+
Breaking Changes:
3+
- Rename default typescript output api file name (prev `api.ts`, now `Api.ts`)
4+
Features:
5+
- `-d, --default-as-success` option. Allows to use "default" status codes as success response type
6+
- `-r, --responses` option. Response declarations in request rescription
7+
This option adds comments of the possible responses from request
8+
![responses comments](./assets/changelog_assets/responses-comments.jpg)
9+
Also typings for `.catch()` callback
10+
![responses catch types](./assets/changelog_assets/responses-catch-types.jpg)
11+
- Improve response body type definitions
12+
- Types for bad responses
13+
Changes:
14+
- \[minor\] fix jsdoc comments space
15+
![right comments space](./assets/changelog_assets/right-comments-space.jpg)
16+
117
# 1.3.0
218
Features:
319
- Api module description from schema info

README.md

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,23 @@ All examples you can find [**here**](https://github.com/acacode/swagger-typescri
2525

2626
## 📄 Usage
2727

28-
```cool
28+
```muse
2929
Usage: sta [options]
3030
Usage: swagger-typescript-api [options]
3131
3232
Options:
33-
-v, --version output the current version
34-
-p, --path <path> path/url to swagger scheme
35-
-o, --output <output> output path of typescript api file (default: "./")
36-
-n, --name <name> name of output typescript api file (default: "api.ts")
37-
--route-types generate type definitions for API routes (default: false)
38-
--no-client do not generate an API class
39-
-h, --help output usage information
33+
-v, --version output the current version
34+
-p, --path <path> path/url to swagger scheme
35+
-o, --output <output> output path of typescript api file (default: "./")
36+
-n, --name <name> name of output typescript api file (default: "Api.ts")
37+
-d, --default-as-success use "default" response status code as success response too.
38+
some swagger schemas use "default" response status code
39+
as success response type by default. (default: false)
40+
-r, --responses generate additional information about request responses
41+
also add typings for bad responses
42+
--route-types generate type definitions for API routes (default: false)
43+
--no-client do not generate an API class
44+
-h, --help output usage information
4045
```
4146

4247
Also you can use `npx`:
Loading
Loading
40.2 KB
Loading

index.d.ts

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11

2-
interface BaseGenerateApiParams {
2+
interface GenerateApiParams {
3+
4+
/**
5+
* path to swagger schema
6+
*/
7+
input: string;
8+
9+
/**
10+
* url to swagger schema
11+
*/
12+
url: string;
313

414
/**
515
* default 'api.ts'
@@ -10,23 +20,29 @@ interface BaseGenerateApiParams {
1020
* path to folder where will been located the created api module
1121
*/
1222
output?: string;
13-
}
14-
15-
interface LocalFileGenerateApiParams extends BaseGenerateApiParams {
23+
24+
/**
25+
* generate type definitions for API routes (default: false)
26+
*/
27+
generateRouteTypes?: boolean;
1628

1729
/**
18-
* path to swagger schema
30+
* do not generate an API class
1931
*/
20-
input: string;
21-
}
32+
generateClient?: boolean;
2233

23-
interface UrlGenerateApiParams extends BaseGenerateApiParams {
34+
/**
35+
* use "default" response status code as success response too.
36+
* some swagger schemas use "default" response status code as success response type by default.
37+
*/
38+
defaultResponseAsSuccess?: boolean;
2439

2540
/**
26-
* url to swagger schema
41+
* generate additional information about request responses
42+
* also add typings for bad responses
2743
*/
28-
url: string;
44+
generateResponses?: boolean;
2945
}
3046

31-
export declare function generateApi(params: LocalFileGenerateApiParams): Promise<string>
32-
export declare function generateApi(params: UrlGenerateApiParams): Promise<string>
47+
export declare function generateApi(params: Omit<GenerateApiParams, "url">): Promise<string>
48+
export declare function generateApi(params: Omit<GenerateApiParams, "input">): Promise<string>

index.js

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,41 @@ program
1616
.description("Generate api via swagger scheme.\nSupports OA 3.0, 2.0, JSON, yaml.")
1717
.requiredOption('-p, --path <path>', 'path/url to swagger scheme')
1818
.option('-o, --output <output>', 'output path of typescript api file', './')
19-
.option('-n, --name <name>', 'name of output typescript api file', 'api.ts')
19+
.option('-n, --name <name>', 'name of output typescript api file', 'Api.ts')
20+
.option(
21+
'-d, --default-as-success',
22+
'use "default" response status code as success response too.\n' +
23+
'some swagger schemas use "default" response status code as success response type by default.',
24+
false
25+
)
26+
.option(
27+
'-r, --responses',
28+
'generate additional information about request responses\n' +
29+
'also add typings for bad responses',
30+
false,
31+
)
2032
.option('--route-types', 'generate type definitions for API routes', false)
2133
.option('--no-client', 'do not generate an API class', false);
2234

2335
program.parse(process.argv);
2436

25-
const { path, output, name, routeTypes, client } = program;
37+
const {
38+
path,
39+
output,
40+
name,
41+
routeTypes,
42+
client,
43+
defaultAsSuccess,
44+
responses,
45+
} = program;
2646

2747
generateApi({
2848
name,
2949
url: path,
3050
generateRouteTypes: routeTypes,
3151
generateClient: client,
52+
defaultResponseAsSuccess: defaultAsSuccess,
53+
generateResponses: responses,
3254
input: resolve(process.cwd(), path),
3355
output: resolve(process.cwd(), output || '.')
3456
})

0 commit comments

Comments
 (0)