@accelbyte/codegen 1.0.0-alpha.7 → 1.0.0-alpha.9
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.
|
@@ -127,10 +127,14 @@ class ParserUtils {
|
|
|
127
127
|
return `${attrName}: ${defaultValue}`;
|
|
128
128
|
};
|
|
129
129
|
static parseType = (pathParam) => {
|
|
130
|
-
if (pathParam.type === "int" || pathParam.type === "integer")
|
|
130
|
+
if (pathParam.type === "int" || pathParam.type === "integer" || pathParam?.schema?.type === "integer")
|
|
131
131
|
return "number";
|
|
132
132
|
if (pathParam.type === "array")
|
|
133
133
|
return `${pathParam.items.type ?? "any"}[]`;
|
|
134
|
+
if (pathParam?.schema?.type === "array")
|
|
135
|
+
return `${pathParam.schema.items.type ?? "any"}[]`;
|
|
136
|
+
if (pathParam?.schema?.type)
|
|
137
|
+
return pathParam.schema.type;
|
|
134
138
|
return pathParam.type;
|
|
135
139
|
};
|
|
136
140
|
static parseQueryParamsType = (queryParams) => {
|
|
@@ -183,7 +187,7 @@ class ParserUtils {
|
|
|
183
187
|
if (definition.type && ParserUtils.parseType(definition) === "number") {
|
|
184
188
|
return `${attrName}${required}: number`;
|
|
185
189
|
}
|
|
186
|
-
if (definition?.schema?.type && ParserUtils.parseType(definition
|
|
190
|
+
if (definition?.schema?.type && ParserUtils.parseType(definition) === "number") {
|
|
187
191
|
return `${attrName}${required}: number`;
|
|
188
192
|
}
|
|
189
193
|
if (definition.type && definition.type === "array") {
|
|
@@ -275,8 +279,8 @@ class ParserUtils {
|
|
|
275
279
|
}
|
|
276
280
|
let classMethod = httpMethod + "/" + replacedIdsPath;
|
|
277
281
|
classMethod = _.camelCase(classMethod);
|
|
278
|
-
classMethod = classMethod.replace("PublicNamespacesByNamespace", "");
|
|
279
|
-
classMethod = classMethod.replace("AdminNamespacesByNamespace", "
|
|
282
|
+
classMethod = classMethod.replace("PublicNamespacesByNamespace", "Ns");
|
|
283
|
+
classMethod = classMethod.replace("AdminNamespacesByNamespace", "AdminNs");
|
|
280
284
|
const searchWord = "NamespacesByNamespace";
|
|
281
285
|
const nsExistInsideMethod = classMethod.indexOf(searchWord) > 0 && classMethod.indexOf(searchWord) + searchWord.length < classMethod.length;
|
|
282
286
|
const excludedClasses = ["Policies"];
|
|
@@ -376,7 +380,7 @@ const Schema = zod.z.object({
|
|
|
376
380
|
$ref: zod.z.string().nullish(),
|
|
377
381
|
type: zod.z.string().nullish()
|
|
378
382
|
}).nullish(),
|
|
379
|
-
properties: zod.z.array(zod.z.string()).nullish(),
|
|
383
|
+
properties: zod.z.union([zod.z.array(zod.z.string()).nullish(), zod.z.record(zod.z.object({ type: zod.z.string() })).nullish()]),
|
|
380
384
|
description: zod.z.string().nullish(),
|
|
381
385
|
additionalProperties: zod.z.object({
|
|
382
386
|
type: zod.z.string().nullish()
|
|
@@ -421,7 +425,15 @@ const Endpoint = zod.z.object({
|
|
|
421
425
|
})
|
|
422
426
|
}).nullish()
|
|
423
427
|
})),
|
|
424
|
-
parameters: zod.z.array(EndpointParameters).nullish()
|
|
428
|
+
parameters: zod.z.array(EndpointParameters).nullish(),
|
|
429
|
+
requestBody: zod.z.object({
|
|
430
|
+
required: zod.z.boolean(),
|
|
431
|
+
content: zod.z.object({
|
|
432
|
+
"application/json": zod.z.object({
|
|
433
|
+
schema: Schema.nullish()
|
|
434
|
+
})
|
|
435
|
+
}).nullish()
|
|
436
|
+
}).nullish()
|
|
425
437
|
});
|
|
426
438
|
const Operation = zod.z.object({
|
|
427
439
|
get: Endpoint.nullish(),
|
|
@@ -638,13 +650,17 @@ class TemplateZod {
|
|
|
638
650
|
if (definition.additionalProperties) {
|
|
639
651
|
return this.parseToZodAttribute("", definition, []);
|
|
640
652
|
}
|
|
641
|
-
|
|
653
|
+
let properties;
|
|
654
|
+
if (definition.properties) {
|
|
655
|
+
properties = Object.entries(definition.properties);
|
|
656
|
+
} else if (definition.items?.properties) {
|
|
657
|
+
properties = Object.entries(definition.items.properties);
|
|
658
|
+
} else {
|
|
642
659
|
return {
|
|
643
660
|
schemaString: "z.any()",
|
|
644
661
|
typeString: "any"
|
|
645
662
|
};
|
|
646
663
|
}
|
|
647
|
-
const properties = Object.entries(definition.properties);
|
|
648
664
|
const schemaFields = [];
|
|
649
665
|
const typeFields = [];
|
|
650
666
|
for (const property of properties) {
|
|
@@ -653,6 +669,12 @@ class TemplateZod {
|
|
|
653
669
|
schemaFields.push(result.schemaString);
|
|
654
670
|
typeFields.push(result.typeString);
|
|
655
671
|
}
|
|
672
|
+
if (definition?.type === "array") {
|
|
673
|
+
return {
|
|
674
|
+
schemaString: `z.array(z.object({${schemaFields.join(",")}}))`,
|
|
675
|
+
typeString: typeFields.join(";")
|
|
676
|
+
};
|
|
677
|
+
}
|
|
656
678
|
return {
|
|
657
679
|
schemaString: `z.object({${schemaFields.join(",")}})`,
|
|
658
680
|
typeString: typeFields.join(";")
|
|
@@ -708,8 +730,8 @@ class TemplateZod {
|
|
|
708
730
|
model2 = this.parseEnumItems(items);
|
|
709
731
|
} else {
|
|
710
732
|
return {
|
|
711
|
-
schemaString: `${schemaAttribute} z.array(z.
|
|
712
|
-
typeString: `${typeAttribute}
|
|
733
|
+
schemaString: `${schemaAttribute} z.array(z.any())${schemaRequired}`,
|
|
734
|
+
typeString: `${typeAttribute} any[]${typeNullishability}`
|
|
713
735
|
};
|
|
714
736
|
}
|
|
715
737
|
return {
|
|
@@ -860,13 +882,22 @@ class CodeGenerator {
|
|
|
860
882
|
const isFormUrlEncoded = ParserUtils.isFormUrlEncoded(httpMethod, endpoint.consumes);
|
|
861
883
|
const queryParams = ParserUtils.filterQueryParameters(endpoint.parameters);
|
|
862
884
|
const pathParams = ParserUtils.filterPathParams(endpoint.parameters);
|
|
863
|
-
|
|
885
|
+
let bodyParams = ParserUtils.filterBodyParams(endpoint.parameters);
|
|
864
886
|
const classMethod = ParserUtils.generateClassMethod({
|
|
865
887
|
path: path2,
|
|
866
888
|
endpoint,
|
|
867
889
|
httpMethod,
|
|
868
890
|
className
|
|
869
891
|
});
|
|
892
|
+
if (endpoint.requestBody) {
|
|
893
|
+
bodyParams = [
|
|
894
|
+
{
|
|
895
|
+
name: "body",
|
|
896
|
+
in: "body",
|
|
897
|
+
schema: endpoint.requestBody.content["application/json"].schema
|
|
898
|
+
}
|
|
899
|
+
];
|
|
900
|
+
}
|
|
870
901
|
const pathWithBase = `${api.basePath ?? ""}${path2}`;
|
|
871
902
|
const [generatedMethodString, importStatements] = templateMethod({
|
|
872
903
|
classMethod,
|