Skip to content

Commit be2f2ec

Browse files
committed
4565: Added documentation
1 parent 01cfc71 commit be2f2ec

File tree

2 files changed

+38
-3
lines changed

2 files changed

+38
-3
lines changed

README.md

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
## Development
44

55
```bash
6-
docker compose pull
6+
docker compose pull
77
docker compose up --detach
88
docker compose exec phpfpm composer install
99
docker compose run --rm node npm install
@@ -25,15 +25,46 @@ The fixtures have the image-text template, and two screen layouts: full screen a
2525

2626
TODO
2727

28-
## Documentation
28+
## API specification and generated code
29+
30+
When the API is changed a new OpenAPI specification should be generated that reflects the changes to the API.
31+
32+
To generate the updated API specification, run the following command:
33+
34+
```shell
35+
docker compose exec phpfpm composer update-api-spec
36+
```
37+
38+
This will generate `public/api-spec-v2.json` and `public/api-spec-v2.yaml`.
39+
40+
This generated API specification is used to generate
41+
[Redux Toolkit RTK Query](https://redux-toolkit.js.org/rtk-query/overview) code for interacting with the API.
42+
43+
To generate the Redux Toolkit RTK Query code, run the following command:
44+
45+
```shell
46+
docker compose exec node npx @rtk-query/codegen-openapi /app/assets/shared/redux/openapi-config.js
47+
```
48+
49+
This will generate `assets/shared/redux/generated-api.ts`. This generated code is enhanced by the custom file
50+
`assets/shared/redux/enhanced-api.ts`.
51+
52+
### Important
53+
54+
If new endpoints are added to the API, `assets/shared/redux/enhanced-api.ts` should be modified to reflect changes in
55+
Redux-Toolkit cache invalidation and new hooks should be added.
56+
57+
See
58+
[https://redux-toolkit.js.org/rtk-query/usage/code-generation](https://redux-toolkit.js.org/rtk-query/usage/code-generation)
59+
for information about the code generation.
2960

3061
## Tests
3162

3263
### API tests
3364

3465
TODO
3566

36-
### Admin / Client tests
67+
### Admin and Client tests
3768

3869
To run tests, use the script:
3970

assets/shared/redux/enhanced-api.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ const invalidatesTagsForEndpoints = {
6666
deleteV2UserActivationCodesById: ["UserActivationCode"],
6767
};
6868

69+
// Enhance the api with specifications about what should be invalidated for the
70+
// given endpoints.
6971
export const enhancedApi = generatedApi.enhanceEndpoints({
7072
// @ts-ignore
7173
endpoints: Object.fromEntries(
@@ -85,6 +87,8 @@ export const enhancedApi = generatedApi.enhanceEndpoints({
8587
)}
8688
);
8789

90+
// These hooks are copied from generated-api.
91+
// If new endpoints are added to the OpenAPI spec, this list should be updated.
8892
export const {
8993
useGetOidcAuthTokenItemQuery,
9094
useGetOidcAuthUrlsItemQuery,

0 commit comments

Comments
 (0)