@dazhicheng/openapi 1.1.13 → 1.1.14

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.
@@ -1,54 +1,54 @@
1
- function isObject(obj) {
2
- return !!obj && typeof obj === "object";
3
- }
4
-
5
- function objectify(thing) {
6
- if (!isObject(thing)) return {};
7
- return thing;
8
- }
9
-
10
- function get(entity: any, path: (string | number)[]) {
11
- let current = entity;
12
-
13
- for (let i = 0; i < path.length; i += 1) {
14
- if (current === null || current === undefined) {
15
- return undefined;
16
- }
17
-
18
- current = current[path[i]];
19
- }
20
-
21
- return current;
22
- }
23
-
24
- function normalizeArray(arr) {
25
- if (Array.isArray(arr)) return arr;
26
- return [arr];
27
- }
28
-
29
- function isFunc(thing) {
30
- return typeof thing === "function";
31
- }
32
-
33
- function inferSchema(thing) {
34
- if (thing.schema) {
35
- return thing.schema;
36
- }
37
-
38
- if (thing.properties) {
39
- return {
40
- ...thing,
41
- type: "object",
42
- };
43
- }
44
-
45
- return thing;
46
- }
47
-
48
- function getRandomInt(min, max) {
49
- const minCeiled = Math.ceil(min);
50
- const maxFloored = Math.floor(max);
51
- return Math.floor(Math.random() * (maxFloored - minCeiled) + minCeiled);
52
- }
53
-
54
- export { isObject, get, objectify, isFunc, inferSchema, normalizeArray, getRandomInt };
1
+ function isObject(obj) {
2
+ return !!obj && typeof obj === "object";
3
+ }
4
+
5
+ function objectify(thing) {
6
+ if (!isObject(thing)) return {};
7
+ return thing;
8
+ }
9
+
10
+ function get(entity: any, path: (string | number)[]) {
11
+ let current = entity;
12
+
13
+ for (let i = 0; i < path.length; i += 1) {
14
+ if (current === null || current === undefined) {
15
+ return undefined;
16
+ }
17
+
18
+ current = current[path[i]];
19
+ }
20
+
21
+ return current;
22
+ }
23
+
24
+ function normalizeArray(arr) {
25
+ if (Array.isArray(arr)) return arr;
26
+ return [arr];
27
+ }
28
+
29
+ function isFunc(thing) {
30
+ return typeof thing === "function";
31
+ }
32
+
33
+ function inferSchema(thing) {
34
+ if (thing.schema) {
35
+ return thing.schema;
36
+ }
37
+
38
+ if (thing.properties) {
39
+ return {
40
+ ...thing,
41
+ type: "object",
42
+ };
43
+ }
44
+
45
+ return thing;
46
+ }
47
+
48
+ function getRandomInt(min, max) {
49
+ const minCeiled = Math.ceil(min);
50
+ const maxFloored = Math.floor(max);
51
+ return Math.floor(Math.random() * (maxFloored - minCeiled) + minCeiled);
52
+ }
53
+
54
+ export { isObject, get, objectify, isFunc, inferSchema, normalizeArray, getRandomInt };
@@ -0,0 +1,460 @@
1
+ import type { OpenAPIObject, OperationObject, ParameterObject, ReferenceObject, RequestBodyObject, ResponsesObject, SchemaObject } from "openapi3-ts";
2
+ import type { GenerateServiceProps } from "./index";
3
+ export type TypescriptFileType = "interface" | "serviceController" | "serviceIndex";
4
+ export interface APIDataType extends OperationObject {
5
+ path: string;
6
+ method: string;
7
+ }
8
+ export type TagAPIDataType = Record<string, APIDataType[]>;
9
+ export interface MappingItemType {
10
+ antTechApi: string;
11
+ popAction: string;
12
+ popProduct: string;
13
+ antTechVersion: string;
14
+ }
15
+ export interface ControllerType {
16
+ fileName: string;
17
+ controllerName: string;
18
+ }
19
+ export declare const getPath: () => string;
20
+ export declare const getGenInfo: (isDirExist: boolean, appName: string, absSrcPath: string) => boolean[];
21
+ declare class ServiceGenerator {
22
+ protected apiData: TagAPIDataType;
23
+ protected classNameList: ControllerType[];
24
+ protected version: string;
25
+ protected mappings: MappingItemType[];
26
+ protected finalPath: string;
27
+ protected config: GenerateServiceProps;
28
+ protected openAPIData: OpenAPIObject;
29
+ constructor(config: GenerateServiceProps, openAPIData: OpenAPIObject);
30
+ genFile(): Promise<void>;
31
+ concatOrNull: (...arrays: any[]) => never[] | null;
32
+ getFuncationName(data: APIDataType): string;
33
+ getTypeName(data: APIDataType): string;
34
+ getServiceTP(): {
35
+ genType: string;
36
+ className: string;
37
+ instanceName: string;
38
+ list: {
39
+ functionName: string;
40
+ typeName: string;
41
+ path: string;
42
+ pathInComment: string;
43
+ hasPathVariables: boolean;
44
+ hasApiPrefix: boolean;
45
+ method: string;
46
+ desc: string | undefined;
47
+ hasHeader: boolean;
48
+ params: Record<string, ParameterObject[]>;
49
+ hasParams: boolean;
50
+ options: Record<string, any>;
51
+ body: {
52
+ required: any;
53
+ propertiesList: ({
54
+ key: string;
55
+ schema: {
56
+ type: string;
57
+ required: boolean;
58
+ nullable?: boolean;
59
+ discriminator?: import("openapi3-ts").DiscriminatorObject;
60
+ readOnly?: boolean;
61
+ writeOnly?: boolean;
62
+ xml?: import("openapi3-ts").XmlObject;
63
+ externalDocs?: import("openapi3-ts").ExternalDocumentationObject;
64
+ example?: any;
65
+ examples?: any[];
66
+ deprecated?: boolean;
67
+ format?: "int32" | "int64" | "float" | "double" | "byte" | "binary" | "date" | "date-time" | "password" | string;
68
+ allOf?: (SchemaObject | ReferenceObject)[];
69
+ oneOf?: (SchemaObject | ReferenceObject)[];
70
+ anyOf?: (SchemaObject | ReferenceObject)[];
71
+ not?: SchemaObject | ReferenceObject;
72
+ items?: SchemaObject | ReferenceObject;
73
+ properties?: {
74
+ [propertyName: string]: SchemaObject | ReferenceObject;
75
+ };
76
+ additionalProperties?: SchemaObject | ReferenceObject | boolean;
77
+ description?: string;
78
+ default?: any;
79
+ title?: string;
80
+ multipleOf?: number;
81
+ maximum?: number;
82
+ exclusiveMaximum?: boolean;
83
+ minimum?: number;
84
+ exclusiveMinimum?: boolean;
85
+ maxLength?: number;
86
+ minLength?: number;
87
+ pattern?: string;
88
+ maxItems?: number;
89
+ minItems?: number;
90
+ uniqueItems?: boolean;
91
+ maxProperties?: number;
92
+ minProperties?: number;
93
+ enum?: any[];
94
+ } | {
95
+ type: string;
96
+ required: boolean;
97
+ $ref: string;
98
+ };
99
+ } | undefined)[];
100
+ nullable?: boolean;
101
+ discriminator?: import("openapi3-ts").DiscriminatorObject;
102
+ readOnly?: boolean;
103
+ writeOnly?: boolean;
104
+ xml?: import("openapi3-ts").XmlObject;
105
+ externalDocs?: import("openapi3-ts").ExternalDocumentationObject;
106
+ example?: any;
107
+ examples?: any[];
108
+ deprecated?: boolean;
109
+ type?: "integer" | "number" | "string" | "boolean" | "object" | "null" | "array";
110
+ format?: "int32" | "int64" | "float" | "double" | "byte" | "binary" | "date" | "date-time" | "password" | string;
111
+ allOf?: (SchemaObject | ReferenceObject)[];
112
+ oneOf?: (SchemaObject | ReferenceObject)[];
113
+ anyOf?: (SchemaObject | ReferenceObject)[];
114
+ not?: SchemaObject | ReferenceObject;
115
+ items?: SchemaObject | ReferenceObject;
116
+ properties?: {
117
+ [propertyName: string]: SchemaObject | ReferenceObject;
118
+ };
119
+ additionalProperties?: SchemaObject | ReferenceObject | boolean;
120
+ description?: string;
121
+ default?: any;
122
+ title?: string;
123
+ multipleOf?: number;
124
+ maximum?: number;
125
+ exclusiveMaximum?: boolean;
126
+ minimum?: number;
127
+ exclusiveMinimum?: boolean;
128
+ maxLength?: number;
129
+ minLength?: number;
130
+ pattern?: string;
131
+ maxItems?: number;
132
+ minItems?: number;
133
+ uniqueItems?: boolean;
134
+ maxProperties?: number;
135
+ minProperties?: number;
136
+ enum?: any[];
137
+ mediaType: string | undefined;
138
+ } | {
139
+ mediaType: string | undefined;
140
+ required: any;
141
+ type: string;
142
+ } | null;
143
+ file: any;
144
+ hasFormData: boolean;
145
+ response: {
146
+ mediaType: string;
147
+ type: string;
148
+ };
149
+ tags?: string[];
150
+ summary?: string;
151
+ description?: string;
152
+ externalDocs?: import("openapi3-ts").ExternalDocumentationObject;
153
+ operationId?: string;
154
+ parameters?: (ParameterObject | ReferenceObject)[];
155
+ requestBody?: RequestBodyObject | ReferenceObject;
156
+ responses: ResponsesObject;
157
+ callbacks?: import("openapi3-ts").CallbacksObject;
158
+ deprecated?: boolean;
159
+ security?: import("openapi3-ts").SecurityRequirementObject[];
160
+ servers?: import("openapi3-ts").ServerObject[];
161
+ }[];
162
+ }[];
163
+ getBodyTP(requestBody?: any): {
164
+ required: any;
165
+ propertiesList: ({
166
+ key: string;
167
+ schema: {
168
+ type: string;
169
+ required: boolean;
170
+ nullable?: boolean;
171
+ discriminator?: import("openapi3-ts").DiscriminatorObject;
172
+ readOnly?: boolean;
173
+ writeOnly?: boolean;
174
+ xml?: import("openapi3-ts").XmlObject;
175
+ externalDocs?: import("openapi3-ts").ExternalDocumentationObject;
176
+ example?: any;
177
+ examples?: any[];
178
+ deprecated?: boolean;
179
+ format?: "int32" | "int64" | "float" | "double" | "byte" | "binary" | "date" | "date-time" | "password" | string;
180
+ allOf?: (SchemaObject | ReferenceObject)[];
181
+ oneOf?: (SchemaObject | ReferenceObject)[];
182
+ anyOf?: (SchemaObject | ReferenceObject)[];
183
+ not?: SchemaObject | ReferenceObject;
184
+ items?: SchemaObject | ReferenceObject;
185
+ properties?: {
186
+ [propertyName: string]: SchemaObject | ReferenceObject;
187
+ };
188
+ additionalProperties?: SchemaObject | ReferenceObject | boolean;
189
+ description?: string;
190
+ default?: any;
191
+ title?: string;
192
+ multipleOf?: number;
193
+ maximum?: number;
194
+ exclusiveMaximum?: boolean;
195
+ minimum?: number;
196
+ exclusiveMinimum?: boolean;
197
+ maxLength?: number;
198
+ minLength?: number;
199
+ pattern?: string;
200
+ maxItems?: number;
201
+ minItems?: number;
202
+ uniqueItems?: boolean;
203
+ maxProperties?: number;
204
+ minProperties?: number;
205
+ enum?: any[];
206
+ } | {
207
+ type: string;
208
+ required: boolean;
209
+ $ref: string;
210
+ };
211
+ } | undefined)[];
212
+ nullable?: boolean;
213
+ discriminator?: import("openapi3-ts").DiscriminatorObject;
214
+ readOnly?: boolean;
215
+ writeOnly?: boolean;
216
+ xml?: import("openapi3-ts").XmlObject;
217
+ externalDocs?: import("openapi3-ts").ExternalDocumentationObject;
218
+ example?: any;
219
+ examples?: any[];
220
+ deprecated?: boolean;
221
+ type?: "integer" | "number" | "string" | "boolean" | "object" | "null" | "array";
222
+ format?: "int32" | "int64" | "float" | "double" | "byte" | "binary" | "date" | "date-time" | "password" | string;
223
+ allOf?: (SchemaObject | ReferenceObject)[];
224
+ oneOf?: (SchemaObject | ReferenceObject)[];
225
+ anyOf?: (SchemaObject | ReferenceObject)[];
226
+ not?: SchemaObject | ReferenceObject;
227
+ items?: SchemaObject | ReferenceObject;
228
+ properties?: {
229
+ [propertyName: string]: SchemaObject | ReferenceObject;
230
+ };
231
+ additionalProperties?: SchemaObject | ReferenceObject | boolean;
232
+ description?: string;
233
+ default?: any;
234
+ title?: string;
235
+ multipleOf?: number;
236
+ maximum?: number;
237
+ exclusiveMaximum?: boolean;
238
+ minimum?: number;
239
+ exclusiveMinimum?: boolean;
240
+ maxLength?: number;
241
+ minLength?: number;
242
+ pattern?: string;
243
+ maxItems?: number;
244
+ minItems?: number;
245
+ uniqueItems?: boolean;
246
+ maxProperties?: number;
247
+ minProperties?: number;
248
+ enum?: any[];
249
+ mediaType: string | undefined;
250
+ } | {
251
+ mediaType: string | undefined;
252
+ required: any;
253
+ type: string;
254
+ } | null;
255
+ getFileTP(requestBody?: any): any;
256
+ resolveFileTP(obj: any): any;
257
+ getResponseTP(responses?: ResponsesObject): {
258
+ mediaType: string;
259
+ type: string;
260
+ };
261
+ getParamsTP(parameters?: (ParameterObject | ReferenceObject)[], path?: string): Record<string, ParameterObject[]>;
262
+ private collectRefs;
263
+ getInterfaceTP(): {
264
+ typeName: string;
265
+ type: any;
266
+ parent: any;
267
+ props: any;
268
+ isEnum: any;
269
+ }[] | undefined;
270
+ private genFileFromTemplate;
271
+ private getTemplate;
272
+ getProps(schemaObject: SchemaObject): {
273
+ name: string;
274
+ type: string;
275
+ desc: string;
276
+ required: boolean;
277
+ nullable?: boolean;
278
+ discriminator?: import("openapi3-ts").DiscriminatorObject;
279
+ readOnly?: boolean;
280
+ writeOnly?: boolean;
281
+ xml?: import("openapi3-ts").XmlObject;
282
+ externalDocs?: import("openapi3-ts").ExternalDocumentationObject;
283
+ example?: any;
284
+ examples?: any[];
285
+ deprecated?: boolean;
286
+ format?: "int32" | "int64" | "float" | "double" | "byte" | "binary" | "date" | "date-time" | "password" | string;
287
+ allOf?: (SchemaObject | ReferenceObject)[];
288
+ oneOf?: (SchemaObject | ReferenceObject)[];
289
+ anyOf?: (SchemaObject | ReferenceObject)[];
290
+ not?: SchemaObject | ReferenceObject;
291
+ items?: SchemaObject | ReferenceObject;
292
+ properties?: {
293
+ [propertyName: string]: SchemaObject | ReferenceObject;
294
+ };
295
+ additionalProperties?: SchemaObject | ReferenceObject | boolean;
296
+ description?: string;
297
+ default?: any;
298
+ title?: string;
299
+ multipleOf?: number;
300
+ maximum?: number;
301
+ exclusiveMaximum?: boolean;
302
+ minimum?: number;
303
+ exclusiveMinimum?: boolean;
304
+ maxLength?: number;
305
+ minLength?: number;
306
+ pattern?: string;
307
+ maxItems?: number;
308
+ minItems?: number;
309
+ uniqueItems?: boolean;
310
+ maxProperties?: number;
311
+ minProperties?: number;
312
+ enum?: any[];
313
+ }[];
314
+ getType(schemaObject: SchemaObject | undefined, namespace?: string): string;
315
+ resolveObject(schemaObject: SchemaObject): any;
316
+ resolveArray(schemaObject: SchemaObject): "any[]" | {
317
+ type: string;
318
+ };
319
+ resolveProperties(schemaObject: SchemaObject): {
320
+ props: {
321
+ name: string;
322
+ type: string;
323
+ desc: string;
324
+ required: boolean;
325
+ nullable?: boolean;
326
+ discriminator?: import("openapi3-ts").DiscriminatorObject;
327
+ readOnly?: boolean;
328
+ writeOnly?: boolean;
329
+ xml?: import("openapi3-ts").XmlObject;
330
+ externalDocs?: import("openapi3-ts").ExternalDocumentationObject;
331
+ example?: any;
332
+ examples?: any[];
333
+ deprecated?: boolean;
334
+ format?: "int32" | "int64" | "float" | "double" | "byte" | "binary" | "date" | "date-time" | "password" | string;
335
+ allOf?: (SchemaObject | ReferenceObject)[];
336
+ oneOf?: (SchemaObject | ReferenceObject)[];
337
+ anyOf?: (SchemaObject | ReferenceObject)[];
338
+ not?: SchemaObject | ReferenceObject;
339
+ items?: SchemaObject | ReferenceObject;
340
+ properties?: {
341
+ [propertyName: string]: SchemaObject | ReferenceObject;
342
+ };
343
+ additionalProperties?: SchemaObject | ReferenceObject | boolean;
344
+ description?: string;
345
+ default?: any;
346
+ title?: string;
347
+ multipleOf?: number;
348
+ maximum?: number;
349
+ exclusiveMaximum?: boolean;
350
+ minimum?: number;
351
+ exclusiveMinimum?: boolean;
352
+ maxLength?: number;
353
+ minLength?: number;
354
+ pattern?: string;
355
+ maxItems?: number;
356
+ minItems?: number;
357
+ uniqueItems?: boolean;
358
+ maxProperties?: number;
359
+ minProperties?: number;
360
+ enum?: any[];
361
+ }[][];
362
+ };
363
+ resolveEnumObject(schemaObject: SchemaObject): {
364
+ isEnum: boolean;
365
+ type: string | undefined;
366
+ };
367
+ resolveAllOfObject(schemaObject: SchemaObject): {
368
+ props: ({
369
+ name: string;
370
+ type: string;
371
+ desc: string;
372
+ required: boolean;
373
+ nullable?: boolean;
374
+ discriminator?: import("openapi3-ts").DiscriminatorObject;
375
+ readOnly?: boolean;
376
+ writeOnly?: boolean;
377
+ xml?: import("openapi3-ts").XmlObject;
378
+ externalDocs?: import("openapi3-ts").ExternalDocumentationObject;
379
+ example?: any;
380
+ examples?: any[];
381
+ deprecated?: boolean;
382
+ format?: "int32" | "int64" | "float" | "double" | "byte" | "binary" | "date" | "date-time" | "password" | string;
383
+ allOf?: (SchemaObject | ReferenceObject)[];
384
+ oneOf?: (SchemaObject | ReferenceObject)[];
385
+ anyOf?: (SchemaObject | ReferenceObject)[];
386
+ not?: SchemaObject | ReferenceObject;
387
+ items?: SchemaObject | ReferenceObject;
388
+ properties?: {
389
+ [propertyName: string]: SchemaObject | ReferenceObject;
390
+ };
391
+ additionalProperties?: SchemaObject | ReferenceObject | boolean;
392
+ description?: string;
393
+ default?: any;
394
+ title?: string;
395
+ multipleOf?: number;
396
+ maximum?: number;
397
+ exclusiveMaximum?: boolean;
398
+ minimum?: number;
399
+ exclusiveMinimum?: boolean;
400
+ maxLength?: number;
401
+ minLength?: number;
402
+ pattern?: string;
403
+ maxItems?: number;
404
+ minItems?: number;
405
+ uniqueItems?: boolean;
406
+ maxProperties?: number;
407
+ minProperties?: number;
408
+ enum?: any[];
409
+ }[] | ({
410
+ type: string | undefined;
411
+ nullable?: boolean;
412
+ discriminator?: import("openapi3-ts").DiscriminatorObject;
413
+ readOnly?: boolean;
414
+ writeOnly?: boolean;
415
+ xml?: import("openapi3-ts").XmlObject;
416
+ externalDocs?: import("openapi3-ts").ExternalDocumentationObject;
417
+ example?: any;
418
+ examples?: any[];
419
+ deprecated?: boolean;
420
+ format?: "int32" | "int64" | "float" | "double" | "byte" | "binary" | "date" | "date-time" | "password" | string;
421
+ allOf?: (SchemaObject | ReferenceObject)[];
422
+ oneOf?: (SchemaObject | ReferenceObject)[];
423
+ anyOf?: (SchemaObject | ReferenceObject)[];
424
+ not?: SchemaObject | ReferenceObject;
425
+ items?: SchemaObject | ReferenceObject;
426
+ properties?: {
427
+ [propertyName: string]: SchemaObject | ReferenceObject;
428
+ };
429
+ additionalProperties?: SchemaObject | ReferenceObject | boolean;
430
+ description?: string;
431
+ default?: any;
432
+ title?: string;
433
+ multipleOf?: number;
434
+ maximum?: number;
435
+ exclusiveMaximum?: boolean;
436
+ minimum?: number;
437
+ exclusiveMinimum?: boolean;
438
+ maxLength?: number;
439
+ minLength?: number;
440
+ pattern?: string;
441
+ maxItems?: number;
442
+ minItems?: number;
443
+ uniqueItems?: boolean;
444
+ maxProperties?: number;
445
+ minProperties?: number;
446
+ required?: string[];
447
+ enum?: any[];
448
+ } | {
449
+ type: string | undefined;
450
+ $ref: string;
451
+ })[])[];
452
+ };
453
+ private genDefaultFunctionName;
454
+ private getBasePrefix;
455
+ private resolveRefObject;
456
+ private getFinalFileName;
457
+ private replaceDot;
458
+ private resolveFunctionName;
459
+ }
460
+ export { ServiceGenerator };