@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.
|
@@ -76,86 +76,6 @@ class CliParser {
|
|
|
76
76
|
};
|
|
77
77
|
}
|
|
78
78
|
|
|
79
|
-
const Schema = zod.z.object({
|
|
80
|
-
$ref: zod.z.string().nullish(),
|
|
81
|
-
type: zod.z.union([
|
|
82
|
-
zod.z.literal("array"),
|
|
83
|
-
zod.z.literal("object"),
|
|
84
|
-
zod.z.literal("file"),
|
|
85
|
-
zod.z.literal("string"),
|
|
86
|
-
zod.z.literal("boolean")
|
|
87
|
-
]).nullish(),
|
|
88
|
-
items: zod.z.object({
|
|
89
|
-
$ref: zod.z.string().nullish(),
|
|
90
|
-
type: zod.z.string().nullish()
|
|
91
|
-
}).nullish(),
|
|
92
|
-
properties: zod.z.array(zod.z.string()).nullish(),
|
|
93
|
-
description: zod.z.string().nullish(),
|
|
94
|
-
additionalProperties: zod.z.object({
|
|
95
|
-
type: zod.z.string().nullish()
|
|
96
|
-
}).nullish()
|
|
97
|
-
});
|
|
98
|
-
const Definition = zod.z.object({
|
|
99
|
-
required: zod.z.array(zod.z.string()).nullish(),
|
|
100
|
-
properties: zod.z.record(zod.z.object({
|
|
101
|
-
type: zod.z.string()
|
|
102
|
-
})).nullish()
|
|
103
|
-
});
|
|
104
|
-
const Definitions = zod.z.record(Definition);
|
|
105
|
-
const EndpointParametersType = zod.z.enum(["apiKey", "boolean", "int", "integer", "number", "string", "array", "file"]);
|
|
106
|
-
const EndpointParametersIn = zod.z.enum(["body", "formData", "header", "path", "query"]);
|
|
107
|
-
const EndpointParameters = zod.z.object({
|
|
108
|
-
type: EndpointParametersType.nullish(),
|
|
109
|
-
description: zod.z.string().nullish(),
|
|
110
|
-
name: zod.z.string(),
|
|
111
|
-
in: EndpointParametersIn,
|
|
112
|
-
required: zod.z.boolean().nullish(),
|
|
113
|
-
schema: Schema.nullish(),
|
|
114
|
-
default: zod.z.union([zod.z.boolean(), zod.z.string(), zod.z.number()]).nullish(),
|
|
115
|
-
enum: zod.z.array(zod.z.union([zod.z.boolean(), zod.z.string(), zod.z.number()])).nullish(),
|
|
116
|
-
items: zod.z.object({
|
|
117
|
-
type: zod.z.string()
|
|
118
|
-
}).nullish()
|
|
119
|
-
});
|
|
120
|
-
const Endpoint = zod.z.object({
|
|
121
|
-
description: zod.z.string().nullish(),
|
|
122
|
-
consumes: zod.z.array(zod.z.string()).nullish(),
|
|
123
|
-
produces: zod.z.array(zod.z.string()).nullish(),
|
|
124
|
-
tags: zod.z.array(zod.z.string()).nullish(),
|
|
125
|
-
summary: zod.z.string().nullish(),
|
|
126
|
-
operationId: zod.z.string(),
|
|
127
|
-
deprecated: zod.z.boolean().nullish(),
|
|
128
|
-
responses: zod.z.record(zod.z.object({
|
|
129
|
-
description: zod.z.string().nullish(),
|
|
130
|
-
schema: Schema.nullish()
|
|
131
|
-
})),
|
|
132
|
-
parameters: zod.z.array(EndpointParameters).nullish()
|
|
133
|
-
});
|
|
134
|
-
const Operation = zod.z.object({
|
|
135
|
-
get: Endpoint.nullish(),
|
|
136
|
-
post: Endpoint.nullish(),
|
|
137
|
-
patch: Endpoint.nullish(),
|
|
138
|
-
delete: Endpoint.nullish(),
|
|
139
|
-
put: Endpoint.nullish()
|
|
140
|
-
});
|
|
141
|
-
const Paths = zod.z.record(Operation);
|
|
142
|
-
zod.z.object({
|
|
143
|
-
paths: Paths,
|
|
144
|
-
definitions: Definitions,
|
|
145
|
-
basePath: zod.z.string(),
|
|
146
|
-
info: zod.z.object({
|
|
147
|
-
description: zod.z.string(),
|
|
148
|
-
title: zod.z.string(),
|
|
149
|
-
contact: zod.z.object({
|
|
150
|
-
name: zod.z.string(),
|
|
151
|
-
url: zod.z.string(),
|
|
152
|
-
email: zod.z.string()
|
|
153
|
-
}),
|
|
154
|
-
version: zod.z.string()
|
|
155
|
-
}),
|
|
156
|
-
schemes: zod.z.array(zod.z.string()).nullish()
|
|
157
|
-
});
|
|
158
|
-
|
|
159
79
|
const getImportableVarMap = () => ({
|
|
160
80
|
"@accelbyte/sdk": ["CodeGenUtil", "SdkCache", "IResponse", "IResponseWithSync", "Validate"],
|
|
161
81
|
axios: ["AxiosRequestConfig", "AxiosResponse"],
|
|
@@ -263,12 +183,21 @@ class ParserUtils {
|
|
|
263
183
|
if (definition.type && ParserUtils.parseType(definition) === "number") {
|
|
264
184
|
return `${attrName}${required}: number`;
|
|
265
185
|
}
|
|
186
|
+
if (definition?.schema?.type && ParserUtils.parseType(definition.schema) === "number") {
|
|
187
|
+
return `${attrName}${required}: number`;
|
|
188
|
+
}
|
|
266
189
|
if (definition.type && definition.type === "array") {
|
|
267
190
|
return `${attrName}${required}: ${definition.items.type ?? "any"}[]`;
|
|
268
191
|
}
|
|
192
|
+
if (definition?.schema?.type && definition.schema.type === "array") {
|
|
193
|
+
return `${attrName}${required}: ${definition.schema.items.type ?? "any"}[]`;
|
|
194
|
+
}
|
|
269
195
|
if (definition.type && definition.type) {
|
|
270
196
|
return `${attrName}${required}: ${definition.type} | null`;
|
|
271
197
|
}
|
|
198
|
+
if (definition?.schema?.type && definition.schema.type) {
|
|
199
|
+
return `${attrName}${required}: ${definition.schema.type} | null`;
|
|
200
|
+
}
|
|
272
201
|
return `${attrName}${required}: any`;
|
|
273
202
|
};
|
|
274
203
|
static parseBodyParamsType = (bodyParams) => {
|
|
@@ -300,11 +229,14 @@ class ParserUtils {
|
|
|
300
229
|
keys.forEach((key) => {
|
|
301
230
|
if (String(key).startsWith("2")) {
|
|
302
231
|
const sch = methodEntity[key].schema;
|
|
232
|
+
const schV3 = methodEntity[key].content && methodEntity[key].content["application/json"].schema;
|
|
303
233
|
if (sch?.$ref) {
|
|
304
234
|
responseClass = ParserUtils.parseRefType(sch.$ref);
|
|
305
235
|
} else if (sch?.type === "array" && sch.items?.$ref) {
|
|
306
236
|
responseClass = ParserUtils.parseRefType(sch.items.$ref);
|
|
307
237
|
responseClass = `${responseClass}Array`;
|
|
238
|
+
} else if (schV3?.$ref) {
|
|
239
|
+
responseClass = ParserUtils.parseRefType(schV3.$ref);
|
|
308
240
|
} else ;
|
|
309
241
|
}
|
|
310
242
|
});
|
|
@@ -437,7 +369,96 @@ ${content}`;
|
|
|
437
369
|
};
|
|
438
370
|
}
|
|
439
371
|
|
|
440
|
-
const
|
|
372
|
+
const Schema = zod.z.object({
|
|
373
|
+
$ref: zod.z.string().nullish(),
|
|
374
|
+
type: zod.z.union([zod.z.literal("array"), zod.z.literal("object"), zod.z.literal("file"), zod.z.literal("string"), zod.z.literal("boolean"), zod.z.literal("integer")]).nullish(),
|
|
375
|
+
items: zod.z.object({
|
|
376
|
+
$ref: zod.z.string().nullish(),
|
|
377
|
+
type: zod.z.string().nullish()
|
|
378
|
+
}).nullish(),
|
|
379
|
+
properties: zod.z.array(zod.z.string()).nullish(),
|
|
380
|
+
description: zod.z.string().nullish(),
|
|
381
|
+
additionalProperties: zod.z.object({
|
|
382
|
+
type: zod.z.string().nullish()
|
|
383
|
+
}).nullish()
|
|
384
|
+
});
|
|
385
|
+
const Definition = zod.z.object({
|
|
386
|
+
required: zod.z.array(zod.z.string()).nullish(),
|
|
387
|
+
properties: zod.z.record(zod.z.object({
|
|
388
|
+
type: zod.z.string()
|
|
389
|
+
})).nullish()
|
|
390
|
+
});
|
|
391
|
+
const Definitions = zod.z.record(Definition);
|
|
392
|
+
const EndpointParametersType = zod.z.enum(["apiKey", "boolean", "int", "integer", "number", "string", "array", "file"]);
|
|
393
|
+
const EndpointParametersIn = zod.z.enum(["body", "formData", "header", "path", "query"]);
|
|
394
|
+
const EndpointParameters = zod.z.object({
|
|
395
|
+
type: EndpointParametersType.nullish(),
|
|
396
|
+
description: zod.z.string().nullish(),
|
|
397
|
+
name: zod.z.string(),
|
|
398
|
+
in: EndpointParametersIn,
|
|
399
|
+
required: zod.z.boolean().nullish(),
|
|
400
|
+
schema: Schema.nullish(),
|
|
401
|
+
default: zod.z.union([zod.z.boolean(), zod.z.string(), zod.z.number()]).nullish(),
|
|
402
|
+
enum: zod.z.array(zod.z.union([zod.z.boolean(), zod.z.string(), zod.z.number()])).nullish(),
|
|
403
|
+
items: zod.z.object({
|
|
404
|
+
type: zod.z.string()
|
|
405
|
+
}).nullish()
|
|
406
|
+
});
|
|
407
|
+
const Endpoint = zod.z.object({
|
|
408
|
+
description: zod.z.string().nullish(),
|
|
409
|
+
consumes: zod.z.array(zod.z.string()).nullish(),
|
|
410
|
+
produces: zod.z.array(zod.z.string()).nullish(),
|
|
411
|
+
tags: zod.z.array(zod.z.string()).nullish(),
|
|
412
|
+
summary: zod.z.string().nullish(),
|
|
413
|
+
operationId: zod.z.string(),
|
|
414
|
+
deprecated: zod.z.boolean().nullish(),
|
|
415
|
+
responses: zod.z.record(zod.z.object({
|
|
416
|
+
description: zod.z.string().nullish(),
|
|
417
|
+
schema: Schema.nullish(),
|
|
418
|
+
content: zod.z.object({
|
|
419
|
+
"application/json": zod.z.object({
|
|
420
|
+
schema: Schema.nullish()
|
|
421
|
+
})
|
|
422
|
+
}).nullish()
|
|
423
|
+
})),
|
|
424
|
+
parameters: zod.z.array(EndpointParameters).nullish()
|
|
425
|
+
});
|
|
426
|
+
const Operation = zod.z.object({
|
|
427
|
+
get: Endpoint.nullish(),
|
|
428
|
+
post: Endpoint.nullish(),
|
|
429
|
+
patch: Endpoint.nullish(),
|
|
430
|
+
delete: Endpoint.nullish(),
|
|
431
|
+
put: Endpoint.nullish()
|
|
432
|
+
});
|
|
433
|
+
const Paths = zod.z.record(Operation);
|
|
434
|
+
zod.z.object({
|
|
435
|
+
paths: Paths,
|
|
436
|
+
definitions: Definitions,
|
|
437
|
+
basePath: zod.z.string(),
|
|
438
|
+
info: zod.z.object({
|
|
439
|
+
description: zod.z.string(),
|
|
440
|
+
title: zod.z.string(),
|
|
441
|
+
contact: zod.z.object({
|
|
442
|
+
name: zod.z.string(),
|
|
443
|
+
url: zod.z.string(),
|
|
444
|
+
email: zod.z.string()
|
|
445
|
+
}),
|
|
446
|
+
version: zod.z.string()
|
|
447
|
+
}),
|
|
448
|
+
schemes: zod.z.array(zod.z.string()).nullish(),
|
|
449
|
+
components: zod.z.object({
|
|
450
|
+
schemas: Definitions
|
|
451
|
+
}).nullish()
|
|
452
|
+
});
|
|
453
|
+
|
|
454
|
+
const templateJsdocMethod = ({
|
|
455
|
+
classMethod,
|
|
456
|
+
httpMethod,
|
|
457
|
+
path,
|
|
458
|
+
pathParams,
|
|
459
|
+
bodyParams,
|
|
460
|
+
queryParams
|
|
461
|
+
}) => {
|
|
441
462
|
let jsdoc = "";
|
|
442
463
|
let methodSignature = "";
|
|
443
464
|
let newPath = path;
|
|
@@ -673,7 +694,8 @@ class TemplateZod {
|
|
|
673
694
|
};
|
|
674
695
|
}
|
|
675
696
|
if (type === "array") {
|
|
676
|
-
const
|
|
697
|
+
const items = definition.items;
|
|
698
|
+
const ref2 = items?.$ref;
|
|
677
699
|
let model2;
|
|
678
700
|
if (ref2) {
|
|
679
701
|
const refType = ParserUtils.parseRefType(ref2);
|
|
@@ -682,9 +704,13 @@ class TemplateZod {
|
|
|
682
704
|
schemaString: refType,
|
|
683
705
|
typeString: refType
|
|
684
706
|
};
|
|
685
|
-
} else {
|
|
686
|
-
const items = definition.items;
|
|
707
|
+
} else if (items) {
|
|
687
708
|
model2 = this.parseEnumItems(items);
|
|
709
|
+
} else {
|
|
710
|
+
return {
|
|
711
|
+
schemaString: `${schemaAttribute} z.array(z.unknown())${schemaRequired}`,
|
|
712
|
+
typeString: `${typeAttribute} z.unknown()[]${typeNullishability}`
|
|
713
|
+
};
|
|
688
714
|
}
|
|
689
715
|
return {
|
|
690
716
|
schemaString: `${schemaAttribute} z.array(${model2.schemaString})${schemaRequired}`,
|
|
@@ -891,8 +917,9 @@ class CodeGenerator {
|
|
|
891
917
|
indexImportsSet.add(ParserUtils.getRelativePathToWebSdkSrcFolder(path.join(DIST_DIR, `${classGenName}`), targetSrcFolder));
|
|
892
918
|
}
|
|
893
919
|
const duplicates = /* @__PURE__ */ new Map();
|
|
894
|
-
|
|
895
|
-
|
|
920
|
+
const definitions = api?.components?.schemas || api.definitions;
|
|
921
|
+
for (const ref in definitions) {
|
|
922
|
+
const definition = definitions[ref];
|
|
896
923
|
let fileName = ParserUtils.parseRefType(ref);
|
|
897
924
|
const fileExist = fs.existsSync(path.join(DIST_DEFINITION_DIR, `${fileName}.ts`));
|
|
898
925
|
if (fileExist) {
|
|
@@ -903,8 +930,8 @@ class CodeGenerator {
|
|
|
903
930
|
ParserUtils.writeDefinitionFile(DIST_DEFINITION_DIR, fileName, buffer);
|
|
904
931
|
indexImportsSet.add(ParserUtils.getRelativePathToWebSdkSrcFolder(path.join(DIST_DEFINITION_DIR, fileName), targetSrcFolder));
|
|
905
932
|
}
|
|
906
|
-
for (const ref in
|
|
907
|
-
const definition =
|
|
933
|
+
for (const ref in definitions) {
|
|
934
|
+
const definition = definitions[ref];
|
|
908
935
|
const fileName = ParserUtils.parseRefType(ref);
|
|
909
936
|
const { buffer, duplicateFound } = new TemplateZod().render(fileName, definition, duplicates);
|
|
910
937
|
if (duplicateFound) {
|