jszy-swagger-doc-generator 1.4.1 → 1.5.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 +327 -113
- package/dist/cli.js +34 -1
- package/dist/cli.js.map +1 -1
- package/dist/generators/swagger.generator.d.ts +90 -0
- package/dist/generators/swagger.generator.js +626 -0
- package/dist/generators/swagger.generator.js.map +1 -0
- package/dist/helpers/handlebars.helpers.d.ts +4 -0
- package/dist/helpers/handlebars.helpers.js +92 -0
- package/dist/helpers/handlebars.helpers.js.map +1 -0
- package/dist/helpers/string.helpers.d.ts +8 -0
- package/dist/helpers/string.helpers.js +25 -0
- package/dist/helpers/string.helpers.js.map +1 -0
- package/dist/helpers/template.helpers.d.ts +4 -0
- package/dist/helpers/template.helpers.js +105 -0
- package/dist/helpers/template.helpers.js.map +1 -0
- package/dist/helpers/type.helpers.d.ts +18 -0
- package/dist/helpers/type.helpers.js +229 -0
- package/dist/helpers/type.helpers.js.map +1 -0
- package/dist/index.d.ts +31 -0
- package/dist/index.js +403 -158
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +97 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/package.json +1 -1
- package/src/cli.ts +35 -1
- package/src/generators/swagger.generator.ts +664 -0
- package/src/helpers/template.helpers.ts +72 -0
- package/src/helpers/type.helpers.ts +232 -0
- package/src/index.ts +435 -161
- package/src/types.ts +98 -0
- package/templates/hooks/individual-hook.hbs +55 -0
- package/templates/hooks/react-hook.hbs +14 -0
- package/templates/types/type-definition.hbs +5 -0
- package/test-openapi-swagger.json +454 -0
package/src/types.ts
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
export interface SwaggerDoc {
|
|
2
|
+
swagger?: string;
|
|
3
|
+
openapi?: string;
|
|
4
|
+
info: {
|
|
5
|
+
title: string;
|
|
6
|
+
version: string;
|
|
7
|
+
description?: string;
|
|
8
|
+
};
|
|
9
|
+
paths: {
|
|
10
|
+
[key: string]: {
|
|
11
|
+
[method: string]: {
|
|
12
|
+
summary?: string;
|
|
13
|
+
description?: string;
|
|
14
|
+
tags?: string[];
|
|
15
|
+
operationId?: string;
|
|
16
|
+
parameters?: Array<{
|
|
17
|
+
name: string;
|
|
18
|
+
in: string;
|
|
19
|
+
description?: string;
|
|
20
|
+
required?: boolean;
|
|
21
|
+
schema?: {
|
|
22
|
+
type?: string;
|
|
23
|
+
format?: string;
|
|
24
|
+
enum?: string[];
|
|
25
|
+
$ref?: string;
|
|
26
|
+
items?: any;
|
|
27
|
+
[key: string]: any;
|
|
28
|
+
};
|
|
29
|
+
}>;
|
|
30
|
+
requestBody?: {
|
|
31
|
+
content: {
|
|
32
|
+
[contentType: string]: {
|
|
33
|
+
schema: any;
|
|
34
|
+
example?: any;
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
responses: {
|
|
39
|
+
[statusCode: string]: {
|
|
40
|
+
description: string;
|
|
41
|
+
content?: {
|
|
42
|
+
[contentType: string]: {
|
|
43
|
+
schema: any;
|
|
44
|
+
example?: any;
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
components?: {
|
|
53
|
+
schemas: {
|
|
54
|
+
[key: string]: any;
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export interface Parameter {
|
|
60
|
+
name: string;
|
|
61
|
+
in: string;
|
|
62
|
+
description?: string;
|
|
63
|
+
required?: boolean;
|
|
64
|
+
schema?: {
|
|
65
|
+
type?: string;
|
|
66
|
+
format?: string;
|
|
67
|
+
enum?: string[];
|
|
68
|
+
$ref?: string;
|
|
69
|
+
items?: any;
|
|
70
|
+
[key: string]: any;
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// Define types for Handlebars context
|
|
75
|
+
export interface HandlebarsContext {
|
|
76
|
+
title: string;
|
|
77
|
+
description: string;
|
|
78
|
+
version: string;
|
|
79
|
+
tag: string;
|
|
80
|
+
endpoints: Array<{
|
|
81
|
+
path: string;
|
|
82
|
+
method: string;
|
|
83
|
+
operationId: string;
|
|
84
|
+
summary?: string;
|
|
85
|
+
description?: string;
|
|
86
|
+
parameters: any[];
|
|
87
|
+
responses: any;
|
|
88
|
+
requestBody?: any;
|
|
89
|
+
}>;
|
|
90
|
+
schemas: { [key: string]: any };
|
|
91
|
+
hasImportTypes: boolean;
|
|
92
|
+
usedTypeNames: string[];
|
|
93
|
+
paramInterfaces: string[];
|
|
94
|
+
hooks: string[];
|
|
95
|
+
typeDefinitions: string[];
|
|
96
|
+
camelCase?: (str: string) => string;
|
|
97
|
+
pascalCase?: (str: string) => string;
|
|
98
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
{{#if isGetRequest}}
|
|
2
|
+
{{#if hasParams}}
|
|
3
|
+
export const {{hookName}} = (params: {{paramInterfaceName}}) => {
|
|
4
|
+
return useQuery({
|
|
5
|
+
queryKey: ['{{operationId}}', params],
|
|
6
|
+
queryFn: async () => {
|
|
7
|
+
const response = await axios.get<{{responseType}}>(`{{{formattedPath}}}`, { params });
|
|
8
|
+
return response.data;
|
|
9
|
+
},
|
|
10
|
+
});
|
|
11
|
+
};
|
|
12
|
+
{{else}}
|
|
13
|
+
export const {{hookName}} = () => {
|
|
14
|
+
return useQuery({
|
|
15
|
+
queryKey: ['{{operationId}}'],
|
|
16
|
+
queryFn: async () => {
|
|
17
|
+
const response = await axios.get<{{responseType}}>(`{{{formattedPath}}}`);
|
|
18
|
+
return response.data;
|
|
19
|
+
},
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
{{/if}}
|
|
23
|
+
{{else}}
|
|
24
|
+
{{#if hasPathParams}}
|
|
25
|
+
export const {{hookName}} = (params: {{paramInterfaceName}}) => {
|
|
26
|
+
const queryClient = useQueryClient();
|
|
27
|
+
|
|
28
|
+
return useMutation({
|
|
29
|
+
mutationFn: async (data: {{requestBodyType}}) => {
|
|
30
|
+
const response = await axios.{{method}}<{{responseType}}>(`{{{formattedPath}}}`, data);
|
|
31
|
+
return response.data;
|
|
32
|
+
},
|
|
33
|
+
onSuccess: () => {
|
|
34
|
+
// Invalidate and refetch related queries
|
|
35
|
+
queryClient.invalidateQueries({ queryKey: ['{{operationId}}'] });
|
|
36
|
+
},
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
{{else}}
|
|
40
|
+
export const {{hookName}} = (data: {{requestBodyType}}) => {
|
|
41
|
+
const queryClient = useQueryClient();
|
|
42
|
+
|
|
43
|
+
return useMutation({
|
|
44
|
+
mutationFn: async (data: {{requestBodyType}}) => {
|
|
45
|
+
const response = await axios.{{method}}<{{responseType}}>(`{{{formattedPath}}}`, data);
|
|
46
|
+
return response.data;
|
|
47
|
+
},
|
|
48
|
+
onSuccess: () => {
|
|
49
|
+
// Invalidate and refetch related queries
|
|
50
|
+
queryClient.invalidateQueries({ queryKey: ['{{operationId}}'] });
|
|
51
|
+
},
|
|
52
|
+
});
|
|
53
|
+
};
|
|
54
|
+
{{/if}}
|
|
55
|
+
{{/if}}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// {{title}} API Hooks
|
|
2
|
+
import { useQuery, useMutation, useQueryClient } from 'react-query';
|
|
3
|
+
import axios from 'axios';
|
|
4
|
+
{{#if hasImportTypes}}
|
|
5
|
+
import type { {{#each usedTypeNames}}{{this}}{{#unless @last}}, {{/unless}}{{/each}} } from './{{camelCase tag}}.types';
|
|
6
|
+
{{/if}}
|
|
7
|
+
|
|
8
|
+
{{#each paramInterfaces}}
|
|
9
|
+
{{{this}}}
|
|
10
|
+
{{/each}}
|
|
11
|
+
|
|
12
|
+
{{#each endpointHooks}}
|
|
13
|
+
{{{this}}}
|
|
14
|
+
{{/each}}
|
|
@@ -0,0 +1,454 @@
|
|
|
1
|
+
{
|
|
2
|
+
"openapi": "3.1.0-rc0",
|
|
3
|
+
"info": {
|
|
4
|
+
"title": "Example Service",
|
|
5
|
+
"version": "1.0.0",
|
|
6
|
+
"description": "Example service for testing OpenAPI generation"
|
|
7
|
+
},
|
|
8
|
+
"servers": [
|
|
9
|
+
{
|
|
10
|
+
"url": "https://api.example.com",
|
|
11
|
+
"description": "Production server",
|
|
12
|
+
"x-environment": "production"
|
|
13
|
+
}
|
|
14
|
+
],
|
|
15
|
+
"paths": {
|
|
16
|
+
"/users/{userId}": {
|
|
17
|
+
"get": {
|
|
18
|
+
"summary": "获取用户信息",
|
|
19
|
+
"description": "根据用户ID获取用户详细信息",
|
|
20
|
+
"tags": ["User"],
|
|
21
|
+
"operationId": "getUserById",
|
|
22
|
+
"parameters": [
|
|
23
|
+
{
|
|
24
|
+
"name": "userId",
|
|
25
|
+
"in": "path",
|
|
26
|
+
"required": true,
|
|
27
|
+
"schema": {
|
|
28
|
+
"type": "integer"
|
|
29
|
+
},
|
|
30
|
+
"description": "用户ID"
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
"name": "includeProfile",
|
|
34
|
+
"in": "query",
|
|
35
|
+
"required": false,
|
|
36
|
+
"schema": {
|
|
37
|
+
"type": "boolean",
|
|
38
|
+
"default": false
|
|
39
|
+
},
|
|
40
|
+
"description": "是否包含用户档案信息"
|
|
41
|
+
}
|
|
42
|
+
],
|
|
43
|
+
"responses": {
|
|
44
|
+
"200": {
|
|
45
|
+
"description": "成功获取用户信息",
|
|
46
|
+
"content": {
|
|
47
|
+
"application/json": {
|
|
48
|
+
"schema": {
|
|
49
|
+
"$ref": "#/components/schemas/User"
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
"put": {
|
|
57
|
+
"summary": "更新用户信息",
|
|
58
|
+
"description": "根据用户ID更新用户信息",
|
|
59
|
+
"tags": ["User"],
|
|
60
|
+
"operationId": "updateUser",
|
|
61
|
+
"parameters": [
|
|
62
|
+
{
|
|
63
|
+
"name": "userId",
|
|
64
|
+
"in": "path",
|
|
65
|
+
"required": true,
|
|
66
|
+
"schema": {
|
|
67
|
+
"type": "integer"
|
|
68
|
+
},
|
|
69
|
+
"description": "用户ID"
|
|
70
|
+
}
|
|
71
|
+
],
|
|
72
|
+
"requestBody": {
|
|
73
|
+
"description": "更新的用户信息",
|
|
74
|
+
"content": {
|
|
75
|
+
"application/json": {
|
|
76
|
+
"schema": {
|
|
77
|
+
"$ref": "#/components/schemas/UserUpdate"
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
"required": true
|
|
82
|
+
},
|
|
83
|
+
"responses": {
|
|
84
|
+
"200": {
|
|
85
|
+
"description": "用户信息更新成功",
|
|
86
|
+
"content": {
|
|
87
|
+
"application/json": {
|
|
88
|
+
"schema": {
|
|
89
|
+
"$ref": "#/components/schemas/User"
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
},
|
|
97
|
+
"/users": {
|
|
98
|
+
"post": {
|
|
99
|
+
"summary": "创建用户",
|
|
100
|
+
"description": "创建新用户",
|
|
101
|
+
"tags": ["User"],
|
|
102
|
+
"operationId": "createUser",
|
|
103
|
+
"requestBody": {
|
|
104
|
+
"description": "新用户信息",
|
|
105
|
+
"content": {
|
|
106
|
+
"application/json": {
|
|
107
|
+
"schema": {
|
|
108
|
+
"$ref": "#/components/schemas/UserCreate"
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
},
|
|
112
|
+
"required": true
|
|
113
|
+
},
|
|
114
|
+
"responses": {
|
|
115
|
+
"201": {
|
|
116
|
+
"description": "用户创建成功",
|
|
117
|
+
"content": {
|
|
118
|
+
"application/json": {
|
|
119
|
+
"schema": {
|
|
120
|
+
"$ref": "#/components/schemas/User"
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
},
|
|
127
|
+
"get": {
|
|
128
|
+
"summary": "获取用户列表",
|
|
129
|
+
"description": "获取用户列表,支持分页和过滤",
|
|
130
|
+
"tags": ["User"],
|
|
131
|
+
"operationId": "getUsers",
|
|
132
|
+
"parameters": [
|
|
133
|
+
{
|
|
134
|
+
"name": "page",
|
|
135
|
+
"in": "query",
|
|
136
|
+
"required": false,
|
|
137
|
+
"schema": {
|
|
138
|
+
"type": "integer",
|
|
139
|
+
"default": 1
|
|
140
|
+
},
|
|
141
|
+
"description": "页码"
|
|
142
|
+
},
|
|
143
|
+
{
|
|
144
|
+
"name": "limit",
|
|
145
|
+
"in": "query",
|
|
146
|
+
"required": false,
|
|
147
|
+
"schema": {
|
|
148
|
+
"type": "integer",
|
|
149
|
+
"default": 10
|
|
150
|
+
},
|
|
151
|
+
"description": "每页数量"
|
|
152
|
+
}
|
|
153
|
+
],
|
|
154
|
+
"responses": {
|
|
155
|
+
"200": {
|
|
156
|
+
"description": "成功获取用户列表",
|
|
157
|
+
"content": {
|
|
158
|
+
"application/json": {
|
|
159
|
+
"schema": {
|
|
160
|
+
"type": "array",
|
|
161
|
+
"items": {
|
|
162
|
+
"$ref": "#/components/schemas/User"
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
},
|
|
171
|
+
"/products/{productId}": {
|
|
172
|
+
"get": {
|
|
173
|
+
"summary": "获取产品信息",
|
|
174
|
+
"description": "根据产品ID获取产品详细信息",
|
|
175
|
+
"tags": ["Product"],
|
|
176
|
+
"operationId": "getProductById",
|
|
177
|
+
"parameters": [
|
|
178
|
+
{
|
|
179
|
+
"name": "productId",
|
|
180
|
+
"in": "path",
|
|
181
|
+
"required": true,
|
|
182
|
+
"schema": {
|
|
183
|
+
"type": "integer"
|
|
184
|
+
},
|
|
185
|
+
"description": "产品ID"
|
|
186
|
+
}
|
|
187
|
+
],
|
|
188
|
+
"responses": {
|
|
189
|
+
"200": {
|
|
190
|
+
"description": "成功获取产品信息",
|
|
191
|
+
"content": {
|
|
192
|
+
"application/json": {
|
|
193
|
+
"schema": {
|
|
194
|
+
"$ref": "#/components/schemas/Product"
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
},
|
|
202
|
+
"/orders": {
|
|
203
|
+
"post": {
|
|
204
|
+
"summary": "创建订单",
|
|
205
|
+
"description": "创建新订单",
|
|
206
|
+
"tags": ["Order"],
|
|
207
|
+
"operationId": "createOrder",
|
|
208
|
+
"requestBody": {
|
|
209
|
+
"description": "订单信息",
|
|
210
|
+
"content": {
|
|
211
|
+
"application/json": {
|
|
212
|
+
"schema": {
|
|
213
|
+
"$ref": "#/components/schemas/OrderCreate"
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
},
|
|
217
|
+
"required": true
|
|
218
|
+
},
|
|
219
|
+
"responses": {
|
|
220
|
+
"201": {
|
|
221
|
+
"description": "订单创建成功",
|
|
222
|
+
"content": {
|
|
223
|
+
"application/json": {
|
|
224
|
+
"schema": {
|
|
225
|
+
"$ref": "#/components/schemas/Order"
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
},
|
|
234
|
+
"components": {
|
|
235
|
+
"schemas": {
|
|
236
|
+
"User": {
|
|
237
|
+
"type": "object",
|
|
238
|
+
"properties": {
|
|
239
|
+
"id": {
|
|
240
|
+
"type": "integer",
|
|
241
|
+
"title": "用户ID"
|
|
242
|
+
},
|
|
243
|
+
"name": {
|
|
244
|
+
"type": "string",
|
|
245
|
+
"title": "用户名"
|
|
246
|
+
},
|
|
247
|
+
"email": {
|
|
248
|
+
"type": ["string", "null"],
|
|
249
|
+
"title": "邮箱地址"
|
|
250
|
+
},
|
|
251
|
+
"profile": {
|
|
252
|
+
"oneOf": [
|
|
253
|
+
{
|
|
254
|
+
"type": "null"
|
|
255
|
+
},
|
|
256
|
+
{
|
|
257
|
+
"$ref": "#/components/schemas/UserProfile"
|
|
258
|
+
}
|
|
259
|
+
],
|
|
260
|
+
"title": "用户档案"
|
|
261
|
+
},
|
|
262
|
+
"tags": {
|
|
263
|
+
"type": "array",
|
|
264
|
+
"items": {
|
|
265
|
+
"type": "string"
|
|
266
|
+
},
|
|
267
|
+
"title": "用户标签"
|
|
268
|
+
},
|
|
269
|
+
"status": {
|
|
270
|
+
"$ref": "#/components/schemas/UserStatus"
|
|
271
|
+
}
|
|
272
|
+
},
|
|
273
|
+
"required": ["id", "name"]
|
|
274
|
+
},
|
|
275
|
+
"UserProfile": {
|
|
276
|
+
"type": "object",
|
|
277
|
+
"properties": {
|
|
278
|
+
"age": {
|
|
279
|
+
"type": "integer",
|
|
280
|
+
"title": "年龄"
|
|
281
|
+
},
|
|
282
|
+
"bio": {
|
|
283
|
+
"type": "string",
|
|
284
|
+
"title": "个人简介"
|
|
285
|
+
},
|
|
286
|
+
"preferences": {
|
|
287
|
+
"$ref": "#/components/schemas/UserPreferences"
|
|
288
|
+
}
|
|
289
|
+
},
|
|
290
|
+
"required": ["age", "bio"]
|
|
291
|
+
},
|
|
292
|
+
"UserPreferences": {
|
|
293
|
+
"type": "object",
|
|
294
|
+
"properties": {
|
|
295
|
+
"theme": {
|
|
296
|
+
"type": "string",
|
|
297
|
+
"enum": ["light", "dark"]
|
|
298
|
+
},
|
|
299
|
+
"notifications": {
|
|
300
|
+
"type": "boolean",
|
|
301
|
+
"default": true
|
|
302
|
+
}
|
|
303
|
+
},
|
|
304
|
+
"required": ["theme"]
|
|
305
|
+
},
|
|
306
|
+
"UserStatus": {
|
|
307
|
+
"type": "string",
|
|
308
|
+
"enum": ["active", "inactive", "suspended"]
|
|
309
|
+
},
|
|
310
|
+
"UserUpdate": {
|
|
311
|
+
"type": "object",
|
|
312
|
+
"properties": {
|
|
313
|
+
"name": {
|
|
314
|
+
"type": "string",
|
|
315
|
+
"title": "用户名"
|
|
316
|
+
},
|
|
317
|
+
"email": {
|
|
318
|
+
"type": "string",
|
|
319
|
+
"format": "email",
|
|
320
|
+
"title": "邮箱地址"
|
|
321
|
+
}
|
|
322
|
+
},
|
|
323
|
+
"required": ["name"]
|
|
324
|
+
},
|
|
325
|
+
"UserCreate": {
|
|
326
|
+
"allOf": [
|
|
327
|
+
{
|
|
328
|
+
"$ref": "#/components/schemas/UserUpdate"
|
|
329
|
+
},
|
|
330
|
+
{
|
|
331
|
+
"type": "object",
|
|
332
|
+
"properties": {
|
|
333
|
+
"password": {
|
|
334
|
+
"type": "string",
|
|
335
|
+
"format": "password",
|
|
336
|
+
"title": "密码"
|
|
337
|
+
}
|
|
338
|
+
},
|
|
339
|
+
"required": ["password"]
|
|
340
|
+
}
|
|
341
|
+
]
|
|
342
|
+
},
|
|
343
|
+
"Product": {
|
|
344
|
+
"type": "object",
|
|
345
|
+
"properties": {
|
|
346
|
+
"id": {
|
|
347
|
+
"type": "integer",
|
|
348
|
+
"title": "产品ID"
|
|
349
|
+
},
|
|
350
|
+
"name": {
|
|
351
|
+
"type": "string",
|
|
352
|
+
"title": "产品名称"
|
|
353
|
+
},
|
|
354
|
+
"price": {
|
|
355
|
+
"type": "number",
|
|
356
|
+
"format": "decimal",
|
|
357
|
+
"title": "价格"
|
|
358
|
+
},
|
|
359
|
+
"category": {
|
|
360
|
+
"$ref": "#/components/schemas/Category"
|
|
361
|
+
},
|
|
362
|
+
"tags": {
|
|
363
|
+
"type": "array",
|
|
364
|
+
"items": {
|
|
365
|
+
"type": "string"
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
},
|
|
369
|
+
"required": ["id", "name", "price"]
|
|
370
|
+
},
|
|
371
|
+
"Category": {
|
|
372
|
+
"type": "object",
|
|
373
|
+
"properties": {
|
|
374
|
+
"id": {
|
|
375
|
+
"type": "integer",
|
|
376
|
+
"title": "分类ID"
|
|
377
|
+
},
|
|
378
|
+
"name": {
|
|
379
|
+
"type": "string",
|
|
380
|
+
"title": "分类名称"
|
|
381
|
+
}
|
|
382
|
+
},
|
|
383
|
+
"required": ["id", "name"]
|
|
384
|
+
},
|
|
385
|
+
"Order": {
|
|
386
|
+
"type": "object",
|
|
387
|
+
"properties": {
|
|
388
|
+
"id": {
|
|
389
|
+
"type": "integer",
|
|
390
|
+
"title": "订单ID"
|
|
391
|
+
},
|
|
392
|
+
"userId": {
|
|
393
|
+
"type": "integer",
|
|
394
|
+
"title": "用户ID"
|
|
395
|
+
},
|
|
396
|
+
"products": {
|
|
397
|
+
"type": "array",
|
|
398
|
+
"items": {
|
|
399
|
+
"$ref": "#/components/schemas/OrderItem"
|
|
400
|
+
},
|
|
401
|
+
"title": "订单商品"
|
|
402
|
+
},
|
|
403
|
+
"total": {
|
|
404
|
+
"type": "number",
|
|
405
|
+
"title": "订单总金额"
|
|
406
|
+
},
|
|
407
|
+
"status": {
|
|
408
|
+
"$ref": "#/components/schemas/OrderStatus"
|
|
409
|
+
}
|
|
410
|
+
},
|
|
411
|
+
"required": ["id", "userId", "products", "total", "status"]
|
|
412
|
+
},
|
|
413
|
+
"OrderItem": {
|
|
414
|
+
"type": "object",
|
|
415
|
+
"properties": {
|
|
416
|
+
"productId": {
|
|
417
|
+
"type": "integer",
|
|
418
|
+
"title": "产品ID"
|
|
419
|
+
},
|
|
420
|
+
"quantity": {
|
|
421
|
+
"type": "integer",
|
|
422
|
+
"title": "数量"
|
|
423
|
+
},
|
|
424
|
+
"price": {
|
|
425
|
+
"type": "number",
|
|
426
|
+
"title": "单价"
|
|
427
|
+
}
|
|
428
|
+
},
|
|
429
|
+
"required": ["productId", "quantity", "price"]
|
|
430
|
+
},
|
|
431
|
+
"OrderStatus": {
|
|
432
|
+
"type": "string",
|
|
433
|
+
"enum": ["pending", "confirmed", "shipped", "delivered", "cancelled"]
|
|
434
|
+
},
|
|
435
|
+
"OrderCreate": {
|
|
436
|
+
"type": "object",
|
|
437
|
+
"properties": {
|
|
438
|
+
"userId": {
|
|
439
|
+
"type": "integer",
|
|
440
|
+
"title": "用户ID"
|
|
441
|
+
},
|
|
442
|
+
"products": {
|
|
443
|
+
"type": "array",
|
|
444
|
+
"items": {
|
|
445
|
+
"$ref": "#/components/schemas/OrderItem"
|
|
446
|
+
},
|
|
447
|
+
"title": "订单商品"
|
|
448
|
+
}
|
|
449
|
+
},
|
|
450
|
+
"required": ["userId", "products"]
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
}
|