@accelbyte/codegen 1.0.0-alpha.8 → 1.0.0-beta.11

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/PATCHING.md ADDED
@@ -0,0 +1,137 @@
1
+ # Code Generator Patching
2
+
3
+ This document outlines the steps required when patching an Open API specs.
4
+
5
+ ## JSON Patch
6
+
7
+ Inside the directory `packages/od-codegen/src/swaggers`, there are also JSON Patch that will patch the Swagger document. The patches will adjust the endpoints so that it will produce the proper functions to match the actual backend service.
8
+ We use https://github.com/Starcounter-Jack/JSON-Patch library that follow https://jsonpatch.com/ format
9
+
10
+ ### Operations
11
+
12
+ #### Add
13
+ ```
14
+ { "op": "add", "path": "/biscuits/1", "value": { "name": "Ginger Nut" } }
15
+ ```
16
+ Adds a value to an object or inserts it into an array. In the case of an array, the value is inserted before the given index. The - character can be used instead of an index to insert at the end of an array.
17
+
18
+ #### Remove
19
+ ```
20
+ { "op": "remove", "path": "/biscuits" }
21
+ ```
22
+ Removes a value from an object or array.
23
+ ```
24
+ { "op": "remove", "path": "/biscuits/0" }
25
+ ```
26
+ Removes the first element of the array at biscuits (or just removes the “0” key if biscuits is an object)
27
+
28
+ #### Replace
29
+ ```
30
+ { "op": "replace", "path": "/biscuits/0/name", "value": "Chocolate Digestive" }
31
+ ```
32
+ Replaces a value. Equivalent to a “remove” followed by an “add”.
33
+
34
+ #### Copy
35
+ ```
36
+ { "op": "copy", "from": "/biscuits/0", "path": "/best_biscuit" }
37
+ ```
38
+ Copies a value from one location to another within the JSON document. Both from and path are JSON Pointers.
39
+
40
+ #### Move
41
+ ```
42
+ { "op": "move", "from": "/biscuits", "path": "/cookies" }
43
+ ```
44
+ Moves a value from one location to the other. Both from and path are JSON Pointers.
45
+
46
+ #### Test
47
+ ```
48
+ { "op": "test", "path": "/best_biscuit/name", "value": "Choco Leibniz" }
49
+ ```
50
+ Tests that the specified value is set in the document. If the test fails, then the patch as a whole should not apply.
51
+
52
+ ### Example
53
+ For example, take a look at the this object
54
+ ```oauthmodel.TokenResponseV3": {
55
+ "required": [
56
+ "access_token",
57
+ "refresh_token",
58
+ "expires_in",
59
+ "token_type",
60
+ "roles",
61
+ "permissions",
62
+ "bans",
63
+ "user_id",
64
+ "display_name",
65
+ "namespace",
66
+ "namespace_roles",
67
+ "refresh_expires_in",
68
+ "scope",
69
+ "xuid"
70
+ ],
71
+ // ...
72
+ }
73
+ ```
74
+
75
+ This definition says that `TokenResponseV3` will always give out `xuid`. Yet at the moment, that property shouldn't always appear in the current IAM and the Swagger JSON is mistakenly written that way. If we kept the `xuid` property there, the response validation in the Web SDK will throw error and say the response missed the `xuid` property. Therefore, the JSON Patches are created, and it looks like this
76
+
77
+ ```
78
+ {
79
+ "op": "remove",
80
+ "path": "/definitions/oauthmodel.TokenResponseV3/required/13"
81
+ }
82
+ ```
83
+
84
+ #### NOTE
85
+ Be careful if we want to use remove multiple array the results will be different from what is expected because at the first opportunity it will change the array order
86
+
87
+ for example the original json:
88
+ ```
89
+ "required": [
90
+ "validateOnly",
91
+ "code",
92
+ "contactType",
93
+ "languageTag"
94
+ ]
95
+ ```
96
+
97
+ what we expect:
98
+ ```
99
+ "required": [
100
+ "code",
101
+ "languageTag"
102
+ ]
103
+ ```
104
+
105
+ patch:
106
+ ```
107
+ {
108
+ "op": "remove",
109
+ "path": "/required/0"
110
+ },
111
+ {
112
+ "op": "remove",
113
+ "path": "/required/2"
114
+ }
115
+ ```
116
+
117
+ result:
118
+ ```
119
+ "required": [
120
+ "code",
121
+ "contactType"
122
+ ]
123
+ ```
124
+
125
+ So instead of doing multiple removes on array it's better to use replace operation
126
+
127
+ patch:
128
+ ```
129
+ {
130
+ "op": "replace",
131
+ "path": "/required",
132
+ "value": [
133
+ "code",
134
+ "languageTag"
135
+ ]
136
+ }
137
+ ```
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
- # Odin Code Generator
1
+ # AccelByte Code Generator
2
2
 
3
- Odin Code Generator is a utility tool to generate network calls in Typescript for each of the endpoints on Swagger's JSON document found in Justice backend services
3
+ AccelByte Code Generator is a CLI tool that facilitates creating an AccelByte Web SDK from AccelByte OpenAPI definitions.
4
4
 
5
5
  ## CLI
6
6
  This codegen build a CLI called `accelbyte-codegen` that will be used to generate code from given config.
@@ -30,140 +30,10 @@ 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 config
33
+ 1. Provide the `config.json` file
34
34
  2. Download swagger files
35
- ``accelbyte-codegen download-swaggers --config ./config.json --swaggersOutput ./swaggers``
35
+ `accelbyte-codegen download-swaggers --config ./config.json --swaggersOutput ./swaggers`
36
36
  3. Generate code from swagger files
37
- ``accelbyte-codegen generate-code --config ./config.json --swaggersOutput ./swaggers --output ./sdk``
38
-
39
- ## JSON Patch
40
- Inside the directory `packages/od-codegen/src/swaggers`, there are also JSON Patch that will patch the Swagger document. The patches will adjust the endpoints so that it will produce the proper functions to match the actual backend service.
41
- We use https://github.com/Starcounter-Jack/JSON-Patch library that follow https://jsonpatch.com/ format
42
-
43
- ### Operations
44
- #### Add
45
- ```
46
- { "op": "add", "path": "/biscuits/1", "value": { "name": "Ginger Nut" } }
47
- ```
48
- Adds a value to an object or inserts it into an array. In the case of an array, the value is inserted before the given index. The - character can be used instead of an index to insert at the end of an array.
49
-
50
- #### Remove
51
- ```
52
- { "op": "remove", "path": "/biscuits" }
53
- ```
54
- Removes a value from an object or array.
55
- ```
56
- { "op": "remove", "path": "/biscuits/0" }
57
- ```
58
- Removes the first element of the array at biscuits (or just removes the “0” key if biscuits is an object)
59
-
60
- #### Replace
61
- ```
62
- { "op": "replace", "path": "/biscuits/0/name", "value": "Chocolate Digestive" }
63
- ```
64
- Replaces a value. Equivalent to a “remove” followed by an “add”.
65
-
66
- #### Copy
67
- ```
68
- { "op": "copy", "from": "/biscuits/0", "path": "/best_biscuit" }
69
- ```
70
- Copies a value from one location to another within the JSON document. Both from and path are JSON Pointers.
71
-
72
- #### Move
73
- ```
74
- { "op": "move", "from": "/biscuits", "path": "/cookies" }
75
- ```
76
- Moves a value from one location to the other. Both from and path are JSON Pointers.
77
-
78
- #### Test
79
- ```
80
- { "op": "test", "path": "/best_biscuit/name", "value": "Choco Leibniz" }
81
- ```
82
- Tests that the specified value is set in the document. If the test fails, then the patch as a whole should not apply.
83
-
84
- ### Example
85
- For example, take a look at the this object
86
- ```oauthmodel.TokenResponseV3": {
87
- "required": [
88
- "access_token",
89
- "refresh_token",
90
- "expires_in",
91
- "token_type",
92
- "roles",
93
- "permissions",
94
- "bans",
95
- "user_id",
96
- "display_name",
97
- "namespace",
98
- "namespace_roles",
99
- "refresh_expires_in",
100
- "scope",
101
- "xuid"
102
- ],
103
- // ...
104
- }
105
- ```
106
-
107
- This definition says that `TokenResponseV3` will always give out `xuid`. Yet at the moment, that property shouldn't always appear in the current IAM and the Swagger JSON is mistakenly written that way. If we kept the `xuid` property there, the response validation in Odin Web SDK will throw error and say the response missed the `xuid` property. Therefore, the JSON Patches are created, and it looks like this
108
-
109
- ```
110
- {
111
- "op": "remove",
112
- "path": "/definitions/oauthmodel.TokenResponseV3/required/13"
113
- }
114
- ```
115
-
116
- #### NOTE
117
- Be careful if we want to use remove multiple array the results will be different from what is expected because at the first opportunity it will change the array order
118
-
119
- for example the original json:
120
- ```
121
- "required": [
122
- "validateOnly",
123
- "code",
124
- "contactType",
125
- "languageTag"
126
- ]
127
- ```
128
-
129
- what we expect:
130
- ```
131
- "required": [
132
- "code",
133
- "languageTag"
134
- ]
135
- ```
136
-
137
- patch:
138
- ```
139
- {
140
- "op": "remove",
141
- "path": "/required/0"
142
- },
143
- {
144
- "op": "remove",
145
- "path": "/required/2"
146
- }
147
- ```
148
-
149
- result:
150
- ```
151
- "required": [
152
- "code",
153
- "contactType"
154
- ]
155
- ```
156
-
157
- So instead of doing multiple removes on array it's better to use replace operation
158
-
159
- patch:
160
- ```
161
- {
162
- "op": "replace",
163
- "path": "/required",
164
- "value": [
165
- "code",
166
- "languageTag"
167
- ]
168
- }
169
- ```
37
+ `accelbyte-codegen generate-code --config ./config.json --swaggersOutput ./swaggers --output ./sdk`
38
+ 4. Prettify the files using
39
+ `yarn prettier`