@accelbyte/codegen 1.0.0-alpha.1 → 1.0.0-alpha.12

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/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ AccelByte Development Code License
2
+
3
+ This development code license agreement (“Agreement”) is between you and AccelByte, Inc. ("AccelByte"), and governs your use of the library, sample code or other software that is accompanied by this license (the "Licensed Software"). By using the Licensed Software, you agree to be bound by the terms of this Agreement. If you do not agree to the terms of this Agreement, do not use the Licensed Software.
4
+
5
+ 1. License Grant. AccelByte hereby grants you a revocable, non-exclusive, non-sublicensable, non-transferrable license to use the Licensed Software, solely to develop your own games that are designed to operate on the AccelByte platform (available under a separate agreement), and solely as needed to enable that operation.
6
+
7
+ 2. Restrictions. Except as expressly permitted in this Agreement, you may not: (a) copy, modify, or create derivative works of the Licensed Software; (b) distribute, sublicense, lease, rent, loan, or otherwise transfer the Licensed Software or any rights granted under this Agreement; (c) reverse engineer, decompile, or disassemble the Licensed Software; or (d) make the functionality of the Licensed Software available to any third party.
8
+
9
+ 3. Termination. This Agreement will remain in effect until terminated by you or AccelByte. AccelByte may terminate this Agreement at any time for any reason. Upon termination of this Agreement, you must cease all use of the Licensed Software and destroy all copies of the Licensed Software in your possession or control.
10
+
11
+ 4. Proprietary Rights. The Licensed Software is owned and copyrighted by AccelByte. Your license to use the Licensed Software does not grant you any right, title, or interest in or to the Licensed Software, except for the limited rights expressly granted in this Agreement.
12
+
13
+ 5. Disclaimer of Warranties. THE LICENSED SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND. TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, ACCELBYTE DISCLAIMS ALL WARRANTIES, WHETHER EXPRESS, IMPLIED, OR STATUTORY, INCLUDING THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
14
+
15
+ 6. Limitation of Liability. TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, IN NO EVENT SHALL ACCELBYTE BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, PUNITIVE, OR CONSEQUENTIAL DAMAGES, OR ANY OTHER DAMAGES OF ANY KIND, ARISING FROM OR RELATED TO THIS AGREEMENT OR THE SDK, WHETHER IN CONTRACT, TORT, OR OTHERWISE, EVEN IF ACCELBYTE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
16
+
17
+ 7. Governing Law. This Agreement will be governed by and construed in accordance with the laws of the state of Washington in the United States of America, without regard to its conflict of law provisions.
18
+
19
+ 8. Contact Information. If you have any questions about this Agreement, please contact AccelByte at: hello@accelbyte.io. Last updated: October 26, 2022
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,143 +1,39 @@
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
- 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`
5
+ ## CLI
6
+ This codegen build a CLI called `accelbyte-codegen` that will be used to generate code from given config.
6
7
 
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
8
  ```
50
- Tests that the specified value is set in the document. If the test fails, then the patch as a whole should not apply.
9
+ Commands:
10
+ accelbyte-codegen download-swaggers Download swaggers JSON files
11
+ accelbyte-codegen generate-code Generate code based on downloaded swagger
12
+ files
51
13
 
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
- }
14
+ Options:
15
+ --version Show version number [boolean]
16
+ --config Config file providing backend services URL. [string] [required]
17
+ --swaggersOutput Output path for downloaded swaggers JSON files. [string] [required]
18
+ --output Output path for generated code. Required for generate-code [string]
19
+ --admin Only generate /admin endpoints. [boolean] [default: false]
20
+ --help Show help [boolean]
73
21
  ```
74
22
 
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
23
+ ### Config file
24
+ Provide swaggers url you wish to generate, store it in .json format file.
76
25
 
77
26
  ```
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"
27
+ [
28
+ ["iam", "Iam", "iam.json", "https://example.com/iam/apidocs/api.json"]
122
29
  ]
123
30
  ```
124
31
 
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
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`