jszy-swagger-doc-generator 1.1.0 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +106 -118
- package/dist/cli.js +17 -5
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +44 -12
- package/dist/index.js +364 -68
- package/dist/index.js.map +1 -1
- package/package.json +6 -3
- package/src/cli.ts +21 -5
- package/src/index.ts +401 -76
package/README.md
CHANGED
|
@@ -1,73 +1,146 @@
|
|
|
1
|
-
#
|
|
1
|
+
# jszy-swagger-doc-generator (api-sdk)
|
|
2
2
|
|
|
3
3
|
A tool to generate frontend documentation, TypeScript types, and React Hooks from Swagger/OpenAPI JSON files.
|
|
4
4
|
|
|
5
|
+
Available command aliases: `api-sdk`, `jszy-swagger-doc-generator`, `swagger-doc-generator`
|
|
6
|
+
|
|
7
|
+
## Features
|
|
8
|
+
|
|
9
|
+
- Fetches Swagger JSON from a URL or loads from a local file
|
|
10
|
+
- Generates comprehensive Markdown documentation
|
|
11
|
+
- Generates TypeScript type definitions from schemas
|
|
12
|
+
- Generates React Hooks for API endpoints, organized by tags
|
|
13
|
+
- Supports both Swagger 2.0 and OpenAPI 3.x specifications
|
|
14
|
+
- Handles API endpoints, parameters, request/response bodies, and responses
|
|
15
|
+
- All generated content automatically placed in `./generated` directory to keep your project clean
|
|
16
|
+
- Properly handles path and query parameters
|
|
17
|
+
- Generates proper TypeScript interfaces and type aliases
|
|
18
|
+
- Organizes generated code by API tags
|
|
19
|
+
|
|
5
20
|
## Installation
|
|
6
21
|
|
|
7
22
|
You can install this package globally to use it as a CLI tool:
|
|
8
23
|
|
|
9
24
|
```bash
|
|
10
|
-
npm install -g swagger-doc-generator
|
|
25
|
+
npm install -g jszy-swagger-doc-generator
|
|
11
26
|
```
|
|
12
27
|
|
|
13
28
|
Or you can use it without installing with npx:
|
|
14
29
|
|
|
15
30
|
```bash
|
|
16
|
-
npx swagger-doc-generator
|
|
31
|
+
npx jszy-swagger-doc-generator
|
|
17
32
|
```
|
|
18
33
|
|
|
19
|
-
## Usage
|
|
34
|
+
## Usage Examples
|
|
20
35
|
|
|
21
|
-
###
|
|
36
|
+
### Example 1: Generate docs from a local Swagger JSON file
|
|
22
37
|
|
|
23
|
-
|
|
38
|
+
1. First, make sure you have a swagger.json file in your project
|
|
39
|
+
2. Run the command using the primary alias:
|
|
40
|
+
```bash
|
|
41
|
+
api-sdk --input ./swagger.json
|
|
42
|
+
```
|
|
43
|
+
Alternatively, you can use the full package name:
|
|
44
|
+
```bash
|
|
45
|
+
npx jszy-swagger-doc-generator --input ./swagger.json
|
|
46
|
+
```
|
|
47
|
+
3. Check the generated documentation in `./generated/docs/api-documentation.md`
|
|
24
48
|
|
|
25
|
-
|
|
49
|
+
### Example 2: Generate from a live API endpoint
|
|
50
|
+
|
|
51
|
+
1. If your API is running and exposes Swagger JSON at `http://localhost:3000/api-docs-json`:
|
|
26
52
|
```bash
|
|
27
|
-
|
|
28
|
-
|
|
53
|
+
api-sdk --url http://localhost:3000/api-docs-json
|
|
54
|
+
```
|
|
55
|
+
2. All content will be generated in the `./generated` directory by default
|
|
29
56
|
|
|
30
|
-
|
|
31
|
-
swagger-doc-generator --input ./swagger.json
|
|
57
|
+
### Example 3: Generate TypeScript types and React hooks
|
|
32
58
|
|
|
33
|
-
|
|
34
|
-
|
|
59
|
+
1. To generate TypeScript types and React hooks from your Swagger file:
|
|
60
|
+
```bash
|
|
61
|
+
api-sdk --input ./swagger.json --generate-types --generate-hooks
|
|
35
62
|
```
|
|
63
|
+
2. Generated files will be in:
|
|
64
|
+
- TypeScript types: `./generated/types/`
|
|
65
|
+
- React hooks: `./generated/hooks/`
|
|
66
|
+
|
|
67
|
+
### Example 4: Generate everything from a URL
|
|
36
68
|
|
|
37
|
-
|
|
69
|
+
1. Generate all documentation, types, and hooks from a live API:
|
|
38
70
|
```bash
|
|
39
|
-
|
|
40
|
-
|
|
71
|
+
api-sdk --url http://localhost:3000/api-docs-json --generate-types --generate-hooks
|
|
72
|
+
```
|
|
73
|
+
2. This will create all outputs in the `./generated` directory
|
|
74
|
+
|
|
75
|
+
## CLI Options
|
|
76
|
+
|
|
77
|
+
The tool provides multiple command aliases: `api-sdk`, `jszy-swagger-doc-generator`, and `swagger-doc-generator`.
|
|
78
|
+
All commands support the same options:
|
|
79
|
+
|
|
80
|
+
- `--url, -u`: URL to the Swagger JSON file
|
|
81
|
+
- `--input, -i`: Path to the local Swagger JSON file
|
|
82
|
+
- `--output, -o`: Output path for the generated documentation (default: ./generated/docs/api-documentation.md)
|
|
83
|
+
- `--generate-types`: Generate TypeScript type definitions
|
|
84
|
+
- `--generate-hooks`: Generate React hooks
|
|
85
|
+
- `--types-output`: Output directory for TypeScript types (default: ./generated/types)
|
|
86
|
+
- `--hooks-output`: Output directory for React hooks (default: ./generated/hooks)
|
|
87
|
+
- `--help`: Show help information
|
|
41
88
|
|
|
42
|
-
|
|
43
|
-
|
|
89
|
+
## Generated Output Structure
|
|
90
|
+
|
|
91
|
+
By default, all generated content goes to the `./generated` directory:
|
|
92
|
+
|
|
93
|
+
```
|
|
94
|
+
generated/
|
|
95
|
+
├── docs/
|
|
96
|
+
│ └── api-documentation.md
|
|
97
|
+
├── types/
|
|
98
|
+
│ └── [generated TypeScript types]
|
|
99
|
+
└── hooks/
|
|
100
|
+
├── user/
|
|
101
|
+
├── config/
|
|
102
|
+
└── [other tags as directories]/
|
|
44
103
|
```
|
|
45
104
|
|
|
46
|
-
|
|
47
|
-
```bash
|
|
48
|
-
# Generate React hooks from a local file (output to ./generated/hooks/ by default)
|
|
49
|
-
swagger-doc-generator --input ./swagger.json --generate-hooks
|
|
105
|
+
## Using Generated TypeScript Types
|
|
50
106
|
|
|
51
|
-
|
|
52
|
-
swagger-doc-generator --input ./swagger.json --generate-hooks --hooks-output ./src/hooks
|
|
107
|
+
Once generated, the TypeScript types can be imported in your project:
|
|
53
108
|
|
|
54
|
-
|
|
55
|
-
|
|
109
|
+
```typescript
|
|
110
|
+
import { User, UserConfig } from './generated/types/your-api-types';
|
|
111
|
+
|
|
112
|
+
const user: User = {
|
|
113
|
+
id: 1,
|
|
114
|
+
name: 'John Doe',
|
|
115
|
+
email: 'john@example.com'
|
|
116
|
+
};
|
|
56
117
|
```
|
|
57
118
|
|
|
58
|
-
|
|
59
|
-
By default, all generated content is placed in the `./generated` directory to keep your project clean and separate generated content from source code:
|
|
119
|
+
## Using Generated React Hooks
|
|
60
120
|
|
|
61
|
-
|
|
62
|
-
- TypeScript types: `./generated/types/`
|
|
63
|
-
- React hooks: `./generated/hooks/`
|
|
121
|
+
The generated React hooks can be used in your React components:
|
|
64
122
|
|
|
65
|
-
|
|
123
|
+
```typescript
|
|
124
|
+
import { useUserController_queryUserInfo } from './generated/hooks/users/users.hooks';
|
|
125
|
+
|
|
126
|
+
function MyComponent() {
|
|
127
|
+
const { userController_queryUserInfo } = useUserController_queryUserInfo();
|
|
128
|
+
|
|
129
|
+
const fetchUser = async () => {
|
|
130
|
+
const user = await userController_queryUserInfo({ id: 1 });
|
|
131
|
+
console.log(user);
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
return <button onClick={fetchUser}>Fetch User</button>;
|
|
135
|
+
}
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
## Programmatic Usage
|
|
66
139
|
|
|
67
140
|
You can also use this package programmatically in your JavaScript/TypeScript code:
|
|
68
141
|
|
|
69
142
|
```javascript
|
|
70
|
-
const { SwaggerDocGenerator } = require('swagger-doc-generator');
|
|
143
|
+
const { SwaggerDocGenerator } = require('jszy-swagger-doc-generator');
|
|
71
144
|
|
|
72
145
|
async function generate() {
|
|
73
146
|
const generator = new SwaggerDocGenerator();
|
|
@@ -94,91 +167,6 @@ async function generate() {
|
|
|
94
167
|
generate().catch(console.error);
|
|
95
168
|
```
|
|
96
169
|
|
|
97
|
-
## Options
|
|
98
|
-
|
|
99
|
-
- `--url, -u`: URL to the Swagger JSON file
|
|
100
|
-
- `--input, -i`: Path to the local Swagger JSON file
|
|
101
|
-
- `--output, -o`: Output path for the generated documentation (default: ./docs/api-documentation.md)
|
|
102
|
-
- `--generate-types`: Generate TypeScript type definitions
|
|
103
|
-
- `--generate-hooks`: Generate React hooks
|
|
104
|
-
- `--types-output`: Output directory for TypeScript types (default: ./types)
|
|
105
|
-
- `--hooks-output`: Output directory for React hooks (default: ./hooks)
|
|
106
|
-
- `--help`: Show help information
|
|
107
|
-
|
|
108
|
-
## Features
|
|
109
|
-
|
|
110
|
-
- Fetches Swagger JSON from a URL
|
|
111
|
-
- Loads Swagger JSON from a local file
|
|
112
|
-
- Generates comprehensive documentation in Markdown format
|
|
113
|
-
- Generates TypeScript type definitions from schemas
|
|
114
|
-
- Generates React Hooks for API endpoints, organized by tags
|
|
115
|
-
- Supports both Swagger 2.0 and OpenAPI 3.x specifications
|
|
116
|
-
- Handles API endpoints, parameters, request/response bodies, and responses
|
|
117
|
-
- Creates output directory if it doesn't exist
|
|
118
|
-
- Properly handles path and query parameters
|
|
119
|
-
- Generates proper TypeScript interfaces and type aliases
|
|
120
|
-
- Organizes generated code by API tags
|
|
121
|
-
|
|
122
|
-
## Example Output
|
|
123
|
-
|
|
124
|
-
### Generated TypeScript Types
|
|
125
|
-
```typescript
|
|
126
|
-
// Auto-generated TypeScript types from Swagger schema
|
|
127
|
-
|
|
128
|
-
export interface User {
|
|
129
|
-
/** 用户ID */
|
|
130
|
-
id: number;
|
|
131
|
-
/** 用户名 */
|
|
132
|
-
name: string;
|
|
133
|
-
/** 用户邮箱 */
|
|
134
|
-
email: string;
|
|
135
|
-
/** 头像URL */
|
|
136
|
-
avatar?: string;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
export interface UserConfig {
|
|
140
|
-
/** 用户ID */
|
|
141
|
-
userId: number;
|
|
142
|
-
/** 主题设置 */
|
|
143
|
-
theme: "light" | "dark";
|
|
144
|
-
/** 语言设置 */
|
|
145
|
-
language: string;
|
|
146
|
-
/** 通知设置 */
|
|
147
|
-
notifications: NotificationSettings;
|
|
148
|
-
/** 个性化设置 */
|
|
149
|
-
preferences: Preferences;
|
|
150
|
-
}
|
|
151
|
-
```
|
|
152
|
-
|
|
153
|
-
### Generated React Hooks
|
|
154
|
-
```typescript
|
|
155
|
-
// Users API Hooks
|
|
156
|
-
|
|
157
|
-
export interface UserController_queryUserInfoParams {
|
|
158
|
-
id?: number;
|
|
159
|
-
name?: string;
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
export const useUserController_queryUserInfo = () => {
|
|
163
|
-
const apiCall = async (params: UserController_queryUserInfoParams) => {
|
|
164
|
-
const path = `${process.env.REACT_APP_API_BASE_URL || ''}/api/queryUserInfo`;
|
|
165
|
-
const queryParams = new URLSearchParams();
|
|
166
|
-
if (params.id) queryParams.append('id', params.id.toString());
|
|
167
|
-
if (params.name) queryParams.append('name', params.name.toString());
|
|
168
|
-
const queryString = queryParams.toString();
|
|
169
|
-
const url = `${path}${queryString ? '?' + queryString : ''}`;
|
|
170
|
-
const options: RequestInit = {
|
|
171
|
-
method: 'GET',
|
|
172
|
-
};
|
|
173
|
-
|
|
174
|
-
const result = await fetch(url, options);
|
|
175
|
-
return result.json() as Promise<User[]>;
|
|
176
|
-
};
|
|
177
|
-
|
|
178
|
-
return { userController_queryUserInfo: apiCall };
|
|
179
|
-
};
|
|
180
|
-
```
|
|
181
|
-
|
|
182
170
|
## Development
|
|
183
171
|
|
|
184
172
|
To run this project locally:
|
package/dist/cli.js
CHANGED
|
@@ -92,11 +92,11 @@ const argv = (0, yargs_1.default)((0, helpers_1.hideBin)(process.argv))
|
|
|
92
92
|
.parseSync();
|
|
93
93
|
async function run() {
|
|
94
94
|
try {
|
|
95
|
-
//
|
|
95
|
+
// Clean the entire generated directory before doing anything
|
|
96
96
|
const generatedDir = './generated';
|
|
97
|
-
if (
|
|
98
|
-
fs.
|
|
99
|
-
console.log(`
|
|
97
|
+
if (fs.existsSync(generatedDir)) {
|
|
98
|
+
fs.rmSync(generatedDir, { recursive: true, force: true });
|
|
99
|
+
console.log(`Cleared generated directory: ${generatedDir}`);
|
|
100
100
|
}
|
|
101
101
|
const generator = new index_1.SwaggerDocGenerator();
|
|
102
102
|
let swaggerDoc;
|
|
@@ -117,6 +117,10 @@ async function run() {
|
|
|
117
117
|
}
|
|
118
118
|
// Check if we need to generate types
|
|
119
119
|
if (argv.generateTypes) {
|
|
120
|
+
// Create the generated directory if it doesn't exist
|
|
121
|
+
if (!fs.existsSync(generatedDir)) {
|
|
122
|
+
fs.mkdirSync(generatedDir, { recursive: true });
|
|
123
|
+
}
|
|
120
124
|
console.log('Generating TypeScript type definitions...');
|
|
121
125
|
const types = generator.generateTypeDefinitions(swaggerDoc);
|
|
122
126
|
const typesOutputPath = argv.typesOutput.endsWith('.ts') ? argv.typesOutput :
|
|
@@ -126,13 +130,21 @@ async function run() {
|
|
|
126
130
|
}
|
|
127
131
|
// Check if we need to generate hooks
|
|
128
132
|
if (argv.generateHooks) {
|
|
133
|
+
// Create the generated directory if it doesn't exist
|
|
134
|
+
if (!fs.existsSync(generatedDir)) {
|
|
135
|
+
fs.mkdirSync(generatedDir, { recursive: true });
|
|
136
|
+
}
|
|
129
137
|
console.log('Generating React hooks...');
|
|
130
138
|
const hooksByTag = generator.generateReactHooks(swaggerDoc);
|
|
131
139
|
generator.saveHooksByTag(hooksByTag, argv.hooksOutput);
|
|
132
|
-
console.log(`React hooks generated successfully in: ${argv.hooksOutput}/`);
|
|
140
|
+
console.log(`React hooks and types generated successfully in: ${argv.hooksOutput}/`);
|
|
133
141
|
}
|
|
134
142
|
// Generate documentation if not generating types or hooks (for backward compatibility)
|
|
135
143
|
if (!argv.generateTypes && !argv.generateHooks) {
|
|
144
|
+
// Create the generated directory if it doesn't exist
|
|
145
|
+
if (!fs.existsSync(generatedDir)) {
|
|
146
|
+
fs.mkdirSync(generatedDir, { recursive: true });
|
|
147
|
+
}
|
|
136
148
|
console.log('Generating documentation...');
|
|
137
149
|
const documentation = generator.generateDocumentation(swaggerDoc);
|
|
138
150
|
generator.saveDocumentationToFile(documentation, argv.output);
|
package/dist/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,mCAA0D;AAC1D,kDAA0B;AAC1B,2CAAwC;AACxC,uCAAyB;
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,mCAA0D;AAC1D,kDAA0B;AAC1B,2CAAwC;AACxC,uCAAyB;AAGzB,MAAM,IAAI,GAAG,IAAA,eAAK,EAAC,IAAA,iBAAO,EAAC,OAAO,CAAC,IAAI,CAAC,CAAC;KACtC,KAAK,CAAC,qBAAqB,CAAC;KAC5B,MAAM,CAAC,KAAK,EAAE;IACb,KAAK,EAAE,GAAG;IACV,QAAQ,EAAE,8BAA8B;IACxC,IAAI,EAAE,QAAQ;CACf,CAAC;KACD,MAAM,CAAC,OAAO,EAAE;IACf,KAAK,EAAE,GAAG;IACV,QAAQ,EAAE,qCAAqC;IAC/C,IAAI,EAAE,QAAQ;CACf,CAAC;KACD,MAAM,CAAC,QAAQ,EAAE;IAChB,KAAK,EAAE,GAAG;IACV,QAAQ,EAAE,8FAA8F;IACxG,IAAI,EAAE,QAAQ;IACd,OAAO,EAAE,uCAAuC;CACjD,CAAC;KACD,MAAM,CAAC,gBAAgB,EAAE;IACxB,QAAQ,EAAE,sCAAsC;IAChD,IAAI,EAAE,SAAS;IACf,OAAO,EAAE,KAAK;CACf,CAAC;KACD,MAAM,CAAC,gBAAgB,EAAE;IACxB,QAAQ,EAAE,sBAAsB;IAChC,IAAI,EAAE,SAAS;IACf,OAAO,EAAE,KAAK;CACf,CAAC;KACD,MAAM,CAAC,cAAc,EAAE;IACtB,QAAQ,EAAE,oEAAo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,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;QACzC,CAAC;QACD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;AACH,CAAC;AAED,cAAc;AACd,GAAG,EAAE,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -93,35 +93,64 @@ export declare class SwaggerDocGenerator {
|
|
|
93
93
|
[key: string]: any;
|
|
94
94
|
}): string;
|
|
95
95
|
/**
|
|
96
|
-
* Generates React hooks from the paths in Swagger doc
|
|
96
|
+
* Generates React hooks from the paths in Swagger doc organized by tag
|
|
97
97
|
*/
|
|
98
|
-
generateReactHooks(swaggerDoc: SwaggerDoc): Map<string,
|
|
98
|
+
generateReactHooks(swaggerDoc: SwaggerDoc): Map<string, {
|
|
99
|
+
hooks: string;
|
|
100
|
+
types: string;
|
|
101
|
+
}>;
|
|
99
102
|
/**
|
|
100
|
-
*
|
|
103
|
+
* Checks if a schema is used in any of the endpoints
|
|
101
104
|
*/
|
|
102
|
-
|
|
105
|
+
isSchemaUsedInEndpoints(schemaName: string, endpoints: Array<{
|
|
106
|
+
path: string;
|
|
107
|
+
method: string;
|
|
108
|
+
endpointInfo: any;
|
|
109
|
+
}>, allSchemas: {
|
|
110
|
+
[key: string]: any;
|
|
111
|
+
}): boolean;
|
|
103
112
|
/**
|
|
104
|
-
*
|
|
113
|
+
* Checks if a schema contains a reference to another schema
|
|
105
114
|
*/
|
|
106
|
-
|
|
115
|
+
schemaContainsRef(schema: any, targetSchemaName: string, allSchemas: {
|
|
107
116
|
[key: string]: any;
|
|
108
|
-
}):
|
|
117
|
+
}): boolean;
|
|
118
|
+
/**
|
|
119
|
+
* Find all referenced schemas from a set of directly used schemas
|
|
120
|
+
*/
|
|
121
|
+
findAllReferencedSchemas(initialSchemas: Set<string>, allSchemas: {
|
|
122
|
+
[key: string]: any;
|
|
123
|
+
}): Set<string>;
|
|
124
|
+
/**
|
|
125
|
+
* Find schema references in a given schema
|
|
126
|
+
*/
|
|
127
|
+
findSchemaReferences(schema: any, allSchemas: {
|
|
128
|
+
[key: string]: any;
|
|
129
|
+
}): Set<string>;
|
|
109
130
|
/**
|
|
110
|
-
* Generates a
|
|
131
|
+
* Generates a parameter interface for an API endpoint
|
|
111
132
|
*/
|
|
112
|
-
|
|
133
|
+
generateParamInterface(path: string, method: string, endpointInfo: any, schemas: {
|
|
113
134
|
[key: string]: any;
|
|
114
135
|
}): string;
|
|
115
136
|
/**
|
|
116
|
-
* Generates a
|
|
137
|
+
* Generates a React Query hook using axios
|
|
117
138
|
*/
|
|
118
|
-
|
|
139
|
+
generateReactQueryHook(path: string, method: string, endpointInfo: any, schemas: {
|
|
119
140
|
[key: string]: any;
|
|
120
141
|
}): string;
|
|
121
142
|
/**
|
|
122
143
|
* Generate operation ID from path and method if not provided
|
|
123
144
|
*/
|
|
124
145
|
generateOperationId(path: string, method: string): string;
|
|
146
|
+
/**
|
|
147
|
+
* Formats code using Prettier - sync version with child process
|
|
148
|
+
*/
|
|
149
|
+
private formatCode;
|
|
150
|
+
/**
|
|
151
|
+
* Gets the parser based on file extension
|
|
152
|
+
*/
|
|
153
|
+
private getParserForFile;
|
|
125
154
|
/**
|
|
126
155
|
* Saves the generated documentation to a file
|
|
127
156
|
*/
|
|
@@ -133,5 +162,8 @@ export declare class SwaggerDocGenerator {
|
|
|
133
162
|
/**
|
|
134
163
|
* Saves the generated React hooks to files organized by tag
|
|
135
164
|
*/
|
|
136
|
-
saveHooksByTag(hooksByTag: Map<string,
|
|
165
|
+
saveHooksByTag(hooksByTag: Map<string, {
|
|
166
|
+
hooks: string;
|
|
167
|
+
types: string;
|
|
168
|
+
}>, outputDir: string): void;
|
|
137
169
|
}
|