@accelbyte/codegen 2.0.0-beta.8 → 2.0.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 CHANGED
@@ -1,4 +1,4 @@
1
- # AccelByte Code Generator
1
+ # AccelByte Web SDK Code Generator
2
2
 
3
3
  AccelByte Code Generator is a CLI tool that facilitates creating an AccelByte Web SDK from AccelByte OpenAPI definitions.
4
4
 
@@ -30,10 +30,93 @@ Provide swaggers url you wish to generate, store it in .json format file.
30
30
  ```
31
31
 
32
32
  ## How to Generate
33
- 1. Provide the `config.json` file
34
- 2. Download swagger files
35
- `accelbyte-codegen download-swaggers --config ./config.json --swaggersOutput ./swaggers`
36
- 3. Generate code from swagger files
37
- `accelbyte-codegen generate-code --config ./config.json --swaggersOutput ./swaggers --output ./sdk`
38
- 4. Prettify the files using
39
- `yarn prettier`
33
+
34
+ **Step 1: Set Up Your Node.js Environment** Make sure you have Node.js and npm (Node Package Manager) installed on your system. You can download and install them from the official website: https://nodejs.org/en/
35
+
36
+ __*It is recommended__ to use [nvm](https://github.com/nvm-sh/nvm) or [fnm](https://github.com/Schniz/fnm) to install Node.js so you can switch between Node versions more easily
37
+
38
+ **Step 2: Create a New Node.js Project (if needed)** If you are starting a new project, create a new directory and initialize it as a Node.js project. You can do this using the following commands:
39
+ ```
40
+ mkdir my-project
41
+ cd my-project
42
+ npm init
43
+ ```
44
+ Follow the prompts to set up your project's package.json file.
45
+
46
+ **Step 3: Install the Package** To use `@accelbyte/codegen`, you need to install it as a dependency for your project. Run the following command within your project directory:
47
+ ```
48
+ npm install @accelbyte/codegen
49
+ # Or, with yarn:
50
+ yarn add @accelbyte/codegen
51
+ ```
52
+ **Step 4: Configure the Package** Check the documentation or the README of the package for specific configuration instructions.
53
+ 1. Prepare The `CHANGELOG.md` file, create the Changelog file in the root project with `CHANGELOG.md` file name.
54
+ 2. Prepare Config file, Provide the swaggers URL you wish to generate with the format of an Array of array detailed services, so we can add multiple services at the same time, by adding an Array of detailed services into `Config.json` Array like this:
55
+ ```
56
+ [
57
+ [serviceName, aliasName, swaggerFileOutput, swaggerURL],
58
+ [serviceName2, aliasName2, swaggerFileOutput2, swaggerURL2],
59
+ ...
60
+ ]
61
+ ```
62
+ and then store it in .json format file (we suggest placing the file in the root directory). example:
63
+ ```
64
+ [
65
+ ["iam", "Iam", "iam.json", "https://example.com/iam/apidocs/api.json"]
66
+ ]
67
+ ```
68
+ for the Accelbyte Demo environment, this will look like this
69
+ ```
70
+ [
71
+ ["iam", "Iam", "iam.json", "https://demo.accelbyte.io/iam/apidocs/api.json"]
72
+ ]
73
+ ```
74
+
75
+ **Step 5: Download Swagger Files** download the swagger file to the project by executing this command
76
+ ```
77
+ npm exec -- accelbyte-codegen download-swaggers --config ./config.json --swaggersOutput ./swaggers
78
+ # Or, with yarn:
79
+ yarn accelbyte-codegen download-swaggers --config ./config.json --swaggersOutput ./swaggers
80
+ ```
81
+ *note: please adjust the `--config` flag with the path of config.json file that was already set up before, and please specify the swagger output directory by using `--swaggersOutput` flag.
82
+
83
+ **Step 6: Generate Code from Swagger Files** after the swagger file has already been downloaded we can proceed to generating Web SDK code from the Swagger File using this command :
84
+ ```
85
+ npm exec -- accelbyte-codegen generate-code --config ./config.json --swaggersOutput ./swaggers --output ./sdk
86
+ ```
87
+ *note: please adjust the `--config` flag with the path of config.json file that was already set up before, and please specify for the swagger output directory by using `--swaggersOutput` flag, and the directory output of generated SDK using `--output` flag.
88
+ if it is successful the result will look like this, and the WebSDK code should be generated under the/sdk directory
89
+
90
+ ```
91
+ ----------
92
+ Generating API: { title: 'justice-iam-service', version: '7.4.0' }
93
+ !!!! Missing x-version for ./sdk/generated-public/iam {
94
+ description: 'Justice IAM Service',
95
+ title: 'justice-iam-service',
96
+ contact: {
97
+ name: 'Engineering Team at AccelByte',
98
+ url: 'https://accelbyte.io',
99
+ email: 'engineering@accelbyte.io'
100
+ },
101
+ version: '7.4.0',
102
+ gitHash: '7.4.0'
103
+ }
104
+
105
+ COMPLETED
106
+ ----------
107
+ ```
108
+
109
+ **Step 7: Prettify the files (Optional)**
110
+
111
+ To prettify the code file using the prettier tool, please install the plugin first by doing this:
112
+ ```
113
+ npm install prettier
114
+ # Or, with yarn:
115
+ yarn add prettier
116
+ ```
117
+ after installing, execute prettier as below
118
+ ```
119
+ npm exec prettier --write swaggers/*.json && prettier --write sdk/**/*
120
+ # Or, with yarn:
121
+ yarn prettier --write swaggers/*.json && prettier --write sdk/**/*
122
+ ```
@@ -346,6 +346,12 @@ class ParserUtils {
346
346
  if (definition?.schema?.type && definition.schema.type === "array") {
347
347
  return `${attrName}${required}: ${definition.schema.items.type ?? "any"}[]`;
348
348
  }
349
+ if (definition.type && definition.type === "file") {
350
+ return `${attrName}${required}: File`;
351
+ }
352
+ if (definition?.schema?.type && definition.schema.type === "file") {
353
+ return `${attrName}${required}: File`;
354
+ }
349
355
  if (definition.type && definition.type) {
350
356
  return `${attrName}${required}: ${definition.type} | null`;
351
357
  }
@@ -772,7 +778,13 @@ ${exportedTypeString}
772
778
  const schemaAttribute = name ? `'${name}':` : "";
773
779
  const typeAttribute = name ? `'${name}'${typeRequired}:` : "";
774
780
  const type = definition?.type;
775
- if (type) {
781
+ if (definition.properties) {
782
+ const result = this.parseToZodSchema(definition, requiredAttrs);
783
+ return {
784
+ schemaString: `${schemaAttribute} ${result.schemaString}${schemaRequired}`,
785
+ typeString: `${typeAttribute} ${result.typeString}${typeNullishability}`
786
+ };
787
+ } else if (type) {
776
788
  if (type === "object" && definition.additionalProperties) {
777
789
  const zodAttribute = this.parseToZodAttribute("", definition.additionalProperties, [""]);
778
790
  return {
@@ -848,12 +860,6 @@ ${exportedTypeString}
848
860
  typeString: `${typeAttribute} ${result.typeString}`
849
861
  };
850
862
  }
851
- } else if (definition.properties) {
852
- const result = this.parseToZodSchema(definition, requiredAttrs);
853
- return {
854
- schemaString: `${schemaAttribute} ${result.schemaString}${schemaRequired}`,
855
- typeString: `${typeAttribute} ${result.typeString}${typeNullishability}`
856
- };
857
863
  }
858
864
  const ref = definition.$ref;
859
865
  let model = `z.record(z.any())`;