@accelbyte/codegen 1.0.0-alpha.6 → 1.0.0-alpha.7
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.
|
@@ -53,86 +53,6 @@ class CliParser {
|
|
|
53
53
|
};
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
-
const Schema = z.object({
|
|
57
|
-
$ref: z.string().nullish(),
|
|
58
|
-
type: z.union([
|
|
59
|
-
z.literal("array"),
|
|
60
|
-
z.literal("object"),
|
|
61
|
-
z.literal("file"),
|
|
62
|
-
z.literal("string"),
|
|
63
|
-
z.literal("boolean")
|
|
64
|
-
]).nullish(),
|
|
65
|
-
items: z.object({
|
|
66
|
-
$ref: z.string().nullish(),
|
|
67
|
-
type: z.string().nullish()
|
|
68
|
-
}).nullish(),
|
|
69
|
-
properties: z.array(z.string()).nullish(),
|
|
70
|
-
description: z.string().nullish(),
|
|
71
|
-
additionalProperties: z.object({
|
|
72
|
-
type: z.string().nullish()
|
|
73
|
-
}).nullish()
|
|
74
|
-
});
|
|
75
|
-
const Definition = z.object({
|
|
76
|
-
required: z.array(z.string()).nullish(),
|
|
77
|
-
properties: z.record(z.object({
|
|
78
|
-
type: z.string()
|
|
79
|
-
})).nullish()
|
|
80
|
-
});
|
|
81
|
-
const Definitions = z.record(Definition);
|
|
82
|
-
const EndpointParametersType = z.enum(["apiKey", "boolean", "int", "integer", "number", "string", "array", "file"]);
|
|
83
|
-
const EndpointParametersIn = z.enum(["body", "formData", "header", "path", "query"]);
|
|
84
|
-
const EndpointParameters = z.object({
|
|
85
|
-
type: EndpointParametersType.nullish(),
|
|
86
|
-
description: z.string().nullish(),
|
|
87
|
-
name: z.string(),
|
|
88
|
-
in: EndpointParametersIn,
|
|
89
|
-
required: z.boolean().nullish(),
|
|
90
|
-
schema: Schema.nullish(),
|
|
91
|
-
default: z.union([z.boolean(), z.string(), z.number()]).nullish(),
|
|
92
|
-
enum: z.array(z.union([z.boolean(), z.string(), z.number()])).nullish(),
|
|
93
|
-
items: z.object({
|
|
94
|
-
type: z.string()
|
|
95
|
-
}).nullish()
|
|
96
|
-
});
|
|
97
|
-
const Endpoint = z.object({
|
|
98
|
-
description: z.string().nullish(),
|
|
99
|
-
consumes: z.array(z.string()).nullish(),
|
|
100
|
-
produces: z.array(z.string()).nullish(),
|
|
101
|
-
tags: z.array(z.string()).nullish(),
|
|
102
|
-
summary: z.string().nullish(),
|
|
103
|
-
operationId: z.string(),
|
|
104
|
-
deprecated: z.boolean().nullish(),
|
|
105
|
-
responses: z.record(z.object({
|
|
106
|
-
description: z.string().nullish(),
|
|
107
|
-
schema: Schema.nullish()
|
|
108
|
-
})),
|
|
109
|
-
parameters: z.array(EndpointParameters).nullish()
|
|
110
|
-
});
|
|
111
|
-
const Operation = z.object({
|
|
112
|
-
get: Endpoint.nullish(),
|
|
113
|
-
post: Endpoint.nullish(),
|
|
114
|
-
patch: Endpoint.nullish(),
|
|
115
|
-
delete: Endpoint.nullish(),
|
|
116
|
-
put: Endpoint.nullish()
|
|
117
|
-
});
|
|
118
|
-
const Paths = z.record(Operation);
|
|
119
|
-
z.object({
|
|
120
|
-
paths: Paths,
|
|
121
|
-
definitions: Definitions,
|
|
122
|
-
basePath: z.string(),
|
|
123
|
-
info: z.object({
|
|
124
|
-
description: z.string(),
|
|
125
|
-
title: z.string(),
|
|
126
|
-
contact: z.object({
|
|
127
|
-
name: z.string(),
|
|
128
|
-
url: z.string(),
|
|
129
|
-
email: z.string()
|
|
130
|
-
}),
|
|
131
|
-
version: z.string()
|
|
132
|
-
}),
|
|
133
|
-
schemes: z.array(z.string()).nullish()
|
|
134
|
-
});
|
|
135
|
-
|
|
136
56
|
const getImportableVarMap = () => ({
|
|
137
57
|
"@accelbyte/sdk": ["CodeGenUtil", "SdkCache", "IResponse", "IResponseWithSync", "Validate"],
|
|
138
58
|
axios: ["AxiosRequestConfig", "AxiosResponse"],
|
|
@@ -240,12 +160,21 @@ class ParserUtils {
|
|
|
240
160
|
if (definition.type && ParserUtils.parseType(definition) === "number") {
|
|
241
161
|
return `${attrName}${required}: number`;
|
|
242
162
|
}
|
|
163
|
+
if (definition?.schema?.type && ParserUtils.parseType(definition.schema) === "number") {
|
|
164
|
+
return `${attrName}${required}: number`;
|
|
165
|
+
}
|
|
243
166
|
if (definition.type && definition.type === "array") {
|
|
244
167
|
return `${attrName}${required}: ${definition.items.type ?? "any"}[]`;
|
|
245
168
|
}
|
|
169
|
+
if (definition?.schema?.type && definition.schema.type === "array") {
|
|
170
|
+
return `${attrName}${required}: ${definition.schema.items.type ?? "any"}[]`;
|
|
171
|
+
}
|
|
246
172
|
if (definition.type && definition.type) {
|
|
247
173
|
return `${attrName}${required}: ${definition.type} | null`;
|
|
248
174
|
}
|
|
175
|
+
if (definition?.schema?.type && definition.schema.type) {
|
|
176
|
+
return `${attrName}${required}: ${definition.schema.type} | null`;
|
|
177
|
+
}
|
|
249
178
|
return `${attrName}${required}: any`;
|
|
250
179
|
};
|
|
251
180
|
static parseBodyParamsType = (bodyParams) => {
|
|
@@ -277,11 +206,14 @@ class ParserUtils {
|
|
|
277
206
|
keys.forEach((key) => {
|
|
278
207
|
if (String(key).startsWith("2")) {
|
|
279
208
|
const sch = methodEntity[key].schema;
|
|
209
|
+
const schV3 = methodEntity[key].content && methodEntity[key].content["application/json"].schema;
|
|
280
210
|
if (sch?.$ref) {
|
|
281
211
|
responseClass = ParserUtils.parseRefType(sch.$ref);
|
|
282
212
|
} else if (sch?.type === "array" && sch.items?.$ref) {
|
|
283
213
|
responseClass = ParserUtils.parseRefType(sch.items.$ref);
|
|
284
214
|
responseClass = `${responseClass}Array`;
|
|
215
|
+
} else if (schV3?.$ref) {
|
|
216
|
+
responseClass = ParserUtils.parseRefType(schV3.$ref);
|
|
285
217
|
} else ;
|
|
286
218
|
}
|
|
287
219
|
});
|
|
@@ -414,7 +346,96 @@ ${content}`;
|
|
|
414
346
|
};
|
|
415
347
|
}
|
|
416
348
|
|
|
417
|
-
const
|
|
349
|
+
const Schema = z.object({
|
|
350
|
+
$ref: z.string().nullish(),
|
|
351
|
+
type: z.union([z.literal("array"), z.literal("object"), z.literal("file"), z.literal("string"), z.literal("boolean"), z.literal("integer")]).nullish(),
|
|
352
|
+
items: z.object({
|
|
353
|
+
$ref: z.string().nullish(),
|
|
354
|
+
type: z.string().nullish()
|
|
355
|
+
}).nullish(),
|
|
356
|
+
properties: z.array(z.string()).nullish(),
|
|
357
|
+
description: z.string().nullish(),
|
|
358
|
+
additionalProperties: z.object({
|
|
359
|
+
type: z.string().nullish()
|
|
360
|
+
}).nullish()
|
|
361
|
+
});
|
|
362
|
+
const Definition = z.object({
|
|
363
|
+
required: z.array(z.string()).nullish(),
|
|
364
|
+
properties: z.record(z.object({
|
|
365
|
+
type: z.string()
|
|
366
|
+
})).nullish()
|
|
367
|
+
});
|
|
368
|
+
const Definitions = z.record(Definition);
|
|
369
|
+
const EndpointParametersType = z.enum(["apiKey", "boolean", "int", "integer", "number", "string", "array", "file"]);
|
|
370
|
+
const EndpointParametersIn = z.enum(["body", "formData", "header", "path", "query"]);
|
|
371
|
+
const EndpointParameters = z.object({
|
|
372
|
+
type: EndpointParametersType.nullish(),
|
|
373
|
+
description: z.string().nullish(),
|
|
374
|
+
name: z.string(),
|
|
375
|
+
in: EndpointParametersIn,
|
|
376
|
+
required: z.boolean().nullish(),
|
|
377
|
+
schema: Schema.nullish(),
|
|
378
|
+
default: z.union([z.boolean(), z.string(), z.number()]).nullish(),
|
|
379
|
+
enum: z.array(z.union([z.boolean(), z.string(), z.number()])).nullish(),
|
|
380
|
+
items: z.object({
|
|
381
|
+
type: z.string()
|
|
382
|
+
}).nullish()
|
|
383
|
+
});
|
|
384
|
+
const Endpoint = z.object({
|
|
385
|
+
description: z.string().nullish(),
|
|
386
|
+
consumes: z.array(z.string()).nullish(),
|
|
387
|
+
produces: z.array(z.string()).nullish(),
|
|
388
|
+
tags: z.array(z.string()).nullish(),
|
|
389
|
+
summary: z.string().nullish(),
|
|
390
|
+
operationId: z.string(),
|
|
391
|
+
deprecated: z.boolean().nullish(),
|
|
392
|
+
responses: z.record(z.object({
|
|
393
|
+
description: z.string().nullish(),
|
|
394
|
+
schema: Schema.nullish(),
|
|
395
|
+
content: z.object({
|
|
396
|
+
"application/json": z.object({
|
|
397
|
+
schema: Schema.nullish()
|
|
398
|
+
})
|
|
399
|
+
}).nullish()
|
|
400
|
+
})),
|
|
401
|
+
parameters: z.array(EndpointParameters).nullish()
|
|
402
|
+
});
|
|
403
|
+
const Operation = z.object({
|
|
404
|
+
get: Endpoint.nullish(),
|
|
405
|
+
post: Endpoint.nullish(),
|
|
406
|
+
patch: Endpoint.nullish(),
|
|
407
|
+
delete: Endpoint.nullish(),
|
|
408
|
+
put: Endpoint.nullish()
|
|
409
|
+
});
|
|
410
|
+
const Paths = z.record(Operation);
|
|
411
|
+
z.object({
|
|
412
|
+
paths: Paths,
|
|
413
|
+
definitions: Definitions,
|
|
414
|
+
basePath: z.string(),
|
|
415
|
+
info: z.object({
|
|
416
|
+
description: z.string(),
|
|
417
|
+
title: z.string(),
|
|
418
|
+
contact: z.object({
|
|
419
|
+
name: z.string(),
|
|
420
|
+
url: z.string(),
|
|
421
|
+
email: z.string()
|
|
422
|
+
}),
|
|
423
|
+
version: z.string()
|
|
424
|
+
}),
|
|
425
|
+
schemes: z.array(z.string()).nullish(),
|
|
426
|
+
components: z.object({
|
|
427
|
+
schemas: Definitions
|
|
428
|
+
}).nullish()
|
|
429
|
+
});
|
|
430
|
+
|
|
431
|
+
const templateJsdocMethod = ({
|
|
432
|
+
classMethod,
|
|
433
|
+
httpMethod,
|
|
434
|
+
path,
|
|
435
|
+
pathParams,
|
|
436
|
+
bodyParams,
|
|
437
|
+
queryParams
|
|
438
|
+
}) => {
|
|
418
439
|
let jsdoc = "";
|
|
419
440
|
let methodSignature = "";
|
|
420
441
|
let newPath = path;
|
|
@@ -650,7 +671,8 @@ class TemplateZod {
|
|
|
650
671
|
};
|
|
651
672
|
}
|
|
652
673
|
if (type === "array") {
|
|
653
|
-
const
|
|
674
|
+
const items = definition.items;
|
|
675
|
+
const ref2 = items?.$ref;
|
|
654
676
|
let model2;
|
|
655
677
|
if (ref2) {
|
|
656
678
|
const refType = ParserUtils.parseRefType(ref2);
|
|
@@ -659,9 +681,13 @@ class TemplateZod {
|
|
|
659
681
|
schemaString: refType,
|
|
660
682
|
typeString: refType
|
|
661
683
|
};
|
|
662
|
-
} else {
|
|
663
|
-
const items = definition.items;
|
|
684
|
+
} else if (items) {
|
|
664
685
|
model2 = this.parseEnumItems(items);
|
|
686
|
+
} else {
|
|
687
|
+
return {
|
|
688
|
+
schemaString: `${schemaAttribute} z.array(z.unknown())${schemaRequired}`,
|
|
689
|
+
typeString: `${typeAttribute} z.unknown()[]${typeNullishability}`
|
|
690
|
+
};
|
|
665
691
|
}
|
|
666
692
|
return {
|
|
667
693
|
schemaString: `${schemaAttribute} z.array(${model2.schemaString})${schemaRequired}`,
|
|
@@ -868,8 +894,9 @@ class CodeGenerator {
|
|
|
868
894
|
indexImportsSet.add(ParserUtils.getRelativePathToWebSdkSrcFolder(path__default.join(DIST_DIR, `${classGenName}`), targetSrcFolder));
|
|
869
895
|
}
|
|
870
896
|
const duplicates = /* @__PURE__ */ new Map();
|
|
871
|
-
|
|
872
|
-
|
|
897
|
+
const definitions = api?.components?.schemas || api.definitions;
|
|
898
|
+
for (const ref in definitions) {
|
|
899
|
+
const definition = definitions[ref];
|
|
873
900
|
let fileName = ParserUtils.parseRefType(ref);
|
|
874
901
|
const fileExist = fs__default.existsSync(path__default.join(DIST_DEFINITION_DIR, `${fileName}.ts`));
|
|
875
902
|
if (fileExist) {
|
|
@@ -880,8 +907,8 @@ class CodeGenerator {
|
|
|
880
907
|
ParserUtils.writeDefinitionFile(DIST_DEFINITION_DIR, fileName, buffer);
|
|
881
908
|
indexImportsSet.add(ParserUtils.getRelativePathToWebSdkSrcFolder(path__default.join(DIST_DEFINITION_DIR, fileName), targetSrcFolder));
|
|
882
909
|
}
|
|
883
|
-
for (const ref in
|
|
884
|
-
const definition =
|
|
910
|
+
for (const ref in definitions) {
|
|
911
|
+
const definition = definitions[ref];
|
|
885
912
|
const fileName = ParserUtils.parseRefType(ref);
|
|
886
913
|
const { buffer, duplicateFound } = new TemplateZod().render(fileName, definition, duplicates);
|
|
887
914
|
if (duplicateFound) {
|