Skip to content

Commit 62766d3

Browse files
committed
docs: update
1 parent 31ba4c2 commit 62766d3

File tree

10 files changed

+6445
-1
lines changed

10 files changed

+6445
-1
lines changed

README.md

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,134 @@
1616
<a href="https://github.com/hunghg255/swagger-typescript-api-es/blob/main/LICENSE" target="_blank" rel="noopener noreferrer"><img src="https://badgen.net/github/license/hunghg255/swagger-typescript-api-es" alt="License" /></a>
1717
</p>
1818

19+
## API
20+
21+
```bash
22+
npx swagger-typescript-api-es@latest --help
23+
```
24+
25+
## CLI
26+
27+
```bash
28+
npx swagger-typescript-api-es@latest -u https://petstore.swagger.io/v2/swagger.json -o ./src/api
29+
```
30+
31+
## Install
32+
33+
```bash
34+
npm i swagger-typescript-api-es@latest --save-dev
35+
```
36+
37+
- Create a file `swagger-typescript-api.config.config.ts` in the root of the project
38+
39+
```ts
40+
import { defaultConfig } from 'swagger-typescript-api-es';
41+
42+
export default defaultConfig({
43+
name: 'api-axios.ts',
44+
output: './src/apis/axios-gentype',
45+
url: 'http://localhost:5002/api-json',
46+
httpClientType: 'axios',
47+
});
48+
49+
// Options
50+
interface IOptions {
51+
/**
52+
* name of output typescript api file (default: "Api.ts")
53+
*/
54+
name: string;
55+
/**
56+
* output path of typescript api file (default: "./")
57+
*/
58+
output: string;
59+
/**
60+
* path/url to swagger scheme
61+
*/
62+
url: string;
63+
input?: string;
64+
spec?: {
65+
swagger?: '2.0' | '3.0';
66+
info?: {
67+
version?: string;
68+
title?: string;
69+
};
70+
};
71+
templates?: string;
72+
httpClientType?: 'axios' | 'fetch';
73+
defaultResponseAsSuccess?: boolean;
74+
generateClient?: boolean;
75+
generateRouteTypes?: boolean;
76+
generateResponses?: boolean;
77+
toJS?: boolean;
78+
extractRequestParams?: boolean;
79+
extractRequestBody?: boolean;
80+
extractEnums?: boolean;
81+
unwrapResponseData?: boolean;
82+
/**
83+
* By default prettier config is load from your project
84+
*/
85+
prettier?: {
86+
printWidth?: number;
87+
tabWidth?: number;
88+
trailingComma?: 'all' | string;
89+
parser?: 'typescript' | string;
90+
};
91+
singleHttpClient?: boolean;
92+
cleanOutput?: boolean;
93+
enumNamesAsValues?: boolean;
94+
moduleNameFirstTag?: boolean;
95+
generateUnionEnums?: boolean;
96+
typePrefix?: string;
97+
typeSuffix?: string;
98+
enumKeyPrefix?: string;
99+
enumKeySuffix?: string;
100+
addReadonly?: boolean;
101+
sortTypes?: boolean;
102+
sortRouters?: boolean;
103+
extractingOptions?: {
104+
requestBodySuffix?: string[];
105+
requestParamsSuffix?: string[];
106+
responseBodySuffix?: string[];
107+
responseErrorSuffix?: string[];
108+
};
109+
/** allow to generate extra files based with this extra templates, see more below */
110+
extraTemplates?: [];
111+
anotherArrayType?: boolean;
112+
fixInvalidTypeNamePrefix?: string;
113+
fixInvalidEnumKeyPrefix?: string;
114+
prettierOptions?: Record<string, any>;
115+
constants?: Record<string, any>;
116+
templateInfos?: any;
117+
codeGenConstructs?: (constructs: any) => Record<string, any>;
118+
primitiveTypeConstructs?: (constructs: any) => Record<string, any>;
119+
hooks?: {
120+
onCreateComponent?: (component: any) => void;
121+
onCreateRequestParams?: (rawType: any) => void;
122+
onCreateRoute?: (routeData: any) => void;
123+
onCreateRouteName?: (routeNameInfo: any, rawRouteInfo: any) => void;
124+
onFormatRouteName?: (routeInfo: any, templateRouteName: any) => void;
125+
onFormatTypeName?: (typeName: any, rawTypeName: any, schemaType: any) => void;
126+
onInit?: (configuration: any) => void;
127+
onPreParseSchema?: (originalSchema: any, typeName: any, schemaType: any) => void;
128+
onParseSchema?: (originalSchema: any, parsedSchema: any) => void;
129+
onPrepareConfig?: (currentConfiguration: any) => void;
130+
};
131+
}
132+
```
133+
134+
- Config (file package.json)
135+
136+
```json
137+
{
138+
...
139+
"scripts": {
140+
...
141+
"gen-api-types": "swagger-typescript-api-es"
142+
},
143+
...
144+
}
145+
```
146+
19147
## 📝 License
20148

21149
Licensed under the [MIT License](https://github.com/hunghg255/swagger-typescript-api-es/blob/master/LICENSE).

docs/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

docs/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Tiny docs template for markdown

docs/index.html

Lines changed: 715 additions & 0 deletions
Large diffs are not rendered by default.

docs/index.md

Lines changed: 201 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,201 @@
1+
<p align="center">
2+
<a href="https://www.npmjs.com/package/swagger-typescript-api-es" target="_blank" rel="noopener noreferrer">
3+
<img src="https://api.iconify.design/devicon-plain:swagger-wordmark.svg?color=%2365fb92" alt="logo" style="width:150px;"/></a>
4+
</p>
5+
6+
<p align="center">
7+
ESM and TypeScript rewrite of Acacode's
8+
<a href="https://github.com/acacode/swagger-typescript-api">swagger-typescript-api</a>
9+
</p>
10+
11+
<p align="center">
12+
<a href="https://www.npmjs.com/package/swagger-typescript-api-es" target="_blank" rel="noopener noreferrer"><img src="https://badge.fury.io/js/swagger-typescript-api-es.svg" alt="NPM Version" /></a>
13+
<a href="https://www.npmjs.com/package/swagger-typescript-api-es" target="_blank" rel="noopener noreferrer"><img src="https://img.shields.io/npm/dt/swagger-typescript-api-es.svg?logo=npm" alt="NPM Downloads" /></a>
14+
<a href="https://bundlephobia.com/result?p=swagger-typescript-api-es" target="_blank" rel="noopener noreferrer"><img src="https://img.shields.io/bundlephobia/minzip/swagger-typescript-api-es" alt="Minizip" /></a>
15+
<a href="https://github.com/hunghg255/swagger-typescript-api-es/graphs/contributors" target="_blank" rel="noopener noreferrer"><img src="https://img.shields.io/badge/all_contributors-1-orange.svg" alt="Contributors" /></a>
16+
<a href="https://github.com/hunghg255/swagger-typescript-api-es/blob/main/LICENSE" target="_blank" rel="noopener noreferrer"><img src="https://badgen.net/github/license/hunghg255/swagger-typescript-api-es" alt="License" /></a>
17+
</p>
18+
19+
## API
20+
21+
:::code-group-open
22+
23+
```bash [npm]
24+
npx swagger-typescript-api-es@latest --help
25+
```
26+
27+
```bash [yarn]
28+
yarn dlx swagger-typescript-api-es@latest --help
29+
```
30+
31+
```bash [pnpm]
32+
pnpx swagger-typescript-api-es@latest --help
33+
```
34+
35+
```bash [bun]
36+
bunx swagger-typescript-api-es@latest --help
37+
```
38+
39+
:::code-group-close
40+
41+
## CLI
42+
43+
```bash
44+
npx swagger-typescript-api-es@latest -u https://petstore.swagger.io/v2/swagger.json -o ./src/api
45+
```
46+
47+
:::code-group-open
48+
49+
```bash [npm]
50+
npx swagger-typescript-api-es@latest -u https://petstore.swagger.io/v2/swagger.json -o ./src/api
51+
```
52+
53+
```bash [yarn]
54+
yarn dlx swagger-typescript-api-es@latest -u https://petstore.swagger.io/v2/swagger.json -o ./src/api
55+
```
56+
57+
```bash [pnpm]
58+
pnpx swagger-typescript-api-es@latest -u https://petstore.swagger.io/v2/swagger.json -o ./src/api
59+
```
60+
61+
```bash [bun]
62+
bunx swagger-typescript-api-es@latest -u https://petstore.swagger.io/v2/swagger.json -o ./src/api
63+
```
64+
65+
:::code-group-close
66+
67+
## Install
68+
69+
:::code-group-open
70+
71+
```bash [npm]
72+
npm i swagger-typescript-api-es@latest --save-dev
73+
```
74+
75+
```bash [yarn]
76+
yarn dlx swagger-typescript-api-es@latest --save-dev
77+
```
78+
79+
```bash [pnpm]
80+
pnpm i swagger-typescript-api-es@latest --save-dev
81+
```
82+
83+
```bash [bun]
84+
bun i swagger-typescript-api-es@latest --save-dev
85+
```
86+
87+
:::code-group-close
88+
89+
- Create a file `swagger-typescript-api.config.config.ts` in the root of the project
90+
91+
```ts twoslash
92+
import { defaultConfig } from 'swagger-typescript-api-es';
93+
94+
export default defaultConfig({
95+
name: 'api-axios.ts',
96+
output: './src/apis/axios-gentype',
97+
url: 'http://localhost:5002/api-json',
98+
httpClientType: 'axios',
99+
});
100+
101+
// Options
102+
interface IOptions {
103+
/**
104+
* name of output typescript api file (default: "Api.ts")
105+
*/
106+
name: string;
107+
/**
108+
* output path of typescript api file (default: "./")
109+
*/
110+
output: string;
111+
/**
112+
* path/url to swagger scheme
113+
*/
114+
url: string;
115+
input?: string;
116+
spec?: {
117+
swagger?: '2.0' | '3.0';
118+
info?: {
119+
version?: string;
120+
title?: string;
121+
};
122+
};
123+
templates?: string;
124+
httpClientType?: 'axios' | 'fetch';
125+
defaultResponseAsSuccess?: boolean;
126+
generateClient?: boolean;
127+
generateRouteTypes?: boolean;
128+
generateResponses?: boolean;
129+
toJS?: boolean;
130+
extractRequestParams?: boolean;
131+
extractRequestBody?: boolean;
132+
extractEnums?: boolean;
133+
unwrapResponseData?: boolean;
134+
/**
135+
* By default prettier config is load from your project
136+
*/
137+
prettier?: {
138+
printWidth?: number;
139+
tabWidth?: number;
140+
trailingComma?: 'all' | string;
141+
parser?: 'typescript' | string;
142+
};
143+
singleHttpClient?: boolean;
144+
cleanOutput?: boolean;
145+
enumNamesAsValues?: boolean;
146+
moduleNameFirstTag?: boolean;
147+
generateUnionEnums?: boolean;
148+
typePrefix?: string;
149+
typeSuffix?: string;
150+
enumKeyPrefix?: string;
151+
enumKeySuffix?: string;
152+
addReadonly?: boolean;
153+
sortTypes?: boolean;
154+
sortRouters?: boolean;
155+
extractingOptions?: {
156+
requestBodySuffix?: string[];
157+
requestParamsSuffix?: string[];
158+
responseBodySuffix?: string[];
159+
responseErrorSuffix?: string[];
160+
};
161+
/** allow to generate extra files based with this extra templates, see more below */
162+
extraTemplates?: [];
163+
anotherArrayType?: boolean;
164+
fixInvalidTypeNamePrefix?: string;
165+
fixInvalidEnumKeyPrefix?: string;
166+
prettierOptions?: Record<string, any>;
167+
constants?: Record<string, any>;
168+
templateInfos?: any;
169+
codeGenConstructs?: (constructs: any) => Record<string, any>;
170+
primitiveTypeConstructs?: (constructs: any) => Record<string, any>;
171+
hooks?: {
172+
onCreateComponent?: (component: any) => void;
173+
onCreateRequestParams?: (rawType: any) => void;
174+
onCreateRoute?: (routeData: any) => void;
175+
onCreateRouteName?: (routeNameInfo: any, rawRouteInfo: any) => void;
176+
onFormatRouteName?: (routeInfo: any, templateRouteName: any) => void;
177+
onFormatTypeName?: (typeName: any, rawTypeName: any, schemaType: any) => void;
178+
onInit?: (configuration: any) => void;
179+
onPreParseSchema?: (originalSchema: any, typeName: any, schemaType: any) => void;
180+
onParseSchema?: (originalSchema: any, parsedSchema: any) => void;
181+
onPrepareConfig?: (currentConfiguration: any) => void;
182+
};
183+
}
184+
```
185+
186+
- Config (file package.json)
187+
188+
```json
189+
{
190+
...
191+
"scripts": {
192+
...
193+
"gen-api-types": "swagger-typescript-api-es"
194+
},
195+
...
196+
}
197+
```
198+
199+
## 📝 License
200+
201+
Licensed under the [MIT License](https://github.com/hunghg255/swagger-typescript-api-es/blob/master/LICENSE).

docs/mdocs.config.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { defineConfig } from 'convert-markdown-to-html';
2+
3+
const ogDescription = 'Swagger Typescript Generate API Docs';
4+
const ogImage = 'https://hung.thedev.id/og-image.png';
5+
const ogTitle = 'Swagger Typescript Generate API Docs';
6+
const ogUrl = 'https://hung.thedev.id/images/patak-banner.jpg';
7+
8+
export default defineConfig({
9+
input: 'index.md',
10+
output: 'index.html',
11+
isTwoSlash: true,
12+
13+
title: 'Swagger Typescript Generate API Docs',
14+
description: 'Swagger Typescript Generate API Docs',
15+
16+
logo: '',
17+
18+
socialLinks: [
19+
{
20+
icon: 'twitter',
21+
url: 'https://twitter.com/hunghg255',
22+
},
23+
{
24+
icon: 'github',
25+
url: 'https://github.com/hunghg255/swagger-typescript-api-es',
26+
},
27+
],
28+
footer: {
29+
message: 'Released under the MIT License',
30+
copyright: 'Copyright © 2023-present Hunghg255',
31+
},
32+
33+
head: [
34+
['meta', { property: 'og:type', content: 'website' }],
35+
['meta', { property: 'og:title', content: ogTitle }],
36+
['meta', { property: 'og:image', content: ogImage }],
37+
['meta', { property: 'og:url', content: ogUrl }],
38+
['meta', { property: 'og:description', content: ogDescription }],
39+
['meta', { name: 'twitter:card', content: 'summary_large_image' }],
40+
['meta', { name: 'twitter:site', content: '@hunghg255' }],
41+
['meta', { name: 'theme-color', content: '#7eaf90' }],
42+
],
43+
});

0 commit comments

Comments
 (0)