@accelbyte/codegen 1.0.0-alpha.1

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/CHANGELOG.md ADDED
@@ -0,0 +1,40 @@
1
+ ### 2022-11-23
2
+
3
+ - CW-1697 - Prettify config files
4
+
5
+ ### 2022-09-7
6
+
7
+ - CW-1449 - [WebSDK] WebSDK accepts cache argument at initialization
8
+
9
+ ### 2022-09-19
10
+
11
+ - CW-1034 - [Basic] dateOfBirth patten in basic service
12
+ - CW-1035 - [Basic] Language pattern in basic service
13
+
14
+ ### 2022-09-19
15
+
16
+ - CW-1225 - [WebSDK] Add Cache in WebSDK
17
+
18
+ ### 2022-09-16
19
+
20
+ - CW-1007 - CW-1008 CW-1009 - remove patches containing language patterns, WalletInfo definition, and OrderInfo definition
21
+
22
+ ### 2022-08-04
23
+
24
+ - OS-7129 - [Dev][Player Portal] Add a redirection page for user verification through link
25
+
26
+ ### 2022-07-29
27
+
28
+ - CW-753 - [Editor][PP][Launcher] Migrate Editor, PP and Launcher to the latest Config-Service endpoints
29
+
30
+ ### 2022-07-27
31
+
32
+ - Update the typings for `config.data` for Odin Config Web SDK
33
+
34
+ ### 2022-07-26
35
+
36
+ - CW-636 - [WebSDK] Web SDK is updated with new config-service endpoints
37
+
38
+ ### 2022-07-14
39
+
40
+ - CW-300 - [Technical] Audit and Remove unused NPM dependencies
package/README.md ADDED
@@ -0,0 +1,143 @@
1
+ # Odin Code Generator
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
4
+
5
+ To generate/regenerate the network call functions, run `yarn build:codegen` from the root directory (it won't work if it were inside `packages/od-codegen`). That command will check for every JSON inside the directory `packages/od-codegen/src/swaggers`. And will produce/update the files in `/accelbyte-web-sdk/packages/sdk/src/generated`
6
+
7
+ ## JSON Patch
8
+ 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.
9
+ We use https://github.com/Starcounter-Jack/JSON-Patch library that follow https://jsonpatch.com/ format
10
+
11
+ ### Operations
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 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
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
+ ```
138
+
139
+ # How to generate
140
+ So the flow to generate/regenerate Swagger JSON, here's what needs to be done.
141
+ 1. Download the JSON files and store it `packages/od-codegen/src/swaggers`
142
+ 2. Run `yarn build:codegen`
143
+ 3. See that `packages/od-web-sdk/src/generated` is changed