API: Update readme and scripts
This commit updates the readme to reflect the use of `@rtk-query/codegen` for generating API slice definitions and adds a new script, `api.sh`, that is used to generate the API slices when the user runs `npm run api`.
This commit is contained in:
parent
702b667dc5
commit
2776af4d6c
3 changed files with 37 additions and 12 deletions
36
README.md
36
README.md
|
|
@ -90,17 +90,17 @@ see [devel/README.md](devel/README.md).
|
||||||
## File Structure
|
## File Structure
|
||||||
|
|
||||||
### Quick Reference
|
### Quick Reference
|
||||||
| Directory | Description |
|
| Directory | Description |
|
||||||
| --------- | ----------- |
|
| --------- | ----------- |
|
||||||
| [`/config`](https://github.com/RedHatInsights/image-builder-frontend/tree/main/config) | webpack configuration |
|
| [`/api`](https://github.com/RedHatInsights/image-builder-frontend/tree/main/api) | API schema and config files |
|
||||||
| [`/devel`](https://github.com/RedHatInsights/image-builder-frontend/tree/main/devel) | tools for local development |
|
| [`/config`](https://github.com/RedHatInsights/image-builder-frontend/tree/main/config) | webpack configuration |
|
||||||
| [`/src`](https://github.com/RedHatInsights/image-builder-frontend/tree/main/src) | source code |
|
| [`/devel`](https://github.com/RedHatInsights/image-builder-frontend/tree/main/devel) | tools for local development |
|
||||||
| [`/src/Components`](https://github.com/RedHatInsights/image-builder-frontend/tree/main/src/Components) | source code split by individual components |
|
| [`/src`](https://github.com/RedHatInsights/image-builder-frontend/tree/main/src) | source code |
|
||||||
| [`/src/test`](https://github.com/RedHatInsights/image-builder-frontend/tree/main/src/test) | test utilities |
|
| [`/src/Components`](https://github.com/RedHatInsights/image-builder-frontend/tree/main/src/Components) | source code split by individual components |
|
||||||
| [`/src/test/mocks`](https://github.com/RedHatInsights/image-builder-frontend/tree/main/src/test/mocks) | mock handlers and server config for MSW |
|
| [`/src/test`](https://github.com/RedHatInsights/image-builder-frontend/tree/main/src/test) | test utilities |
|
||||||
| [`/src/store`](https://github.com/RedHatInsights/image-builder-frontend/tree/main/src/store) | Redux store |
|
| [`/src/test/mocks`](https://github.com/RedHatInsights/image-builder-frontend/tree/main/src/test/mocks) | mock handlers and server config for MSW |
|
||||||
| [`/src/api.js`](https://github.com/RedHatInsights/image-builder-frontend/blob/main/src/api.js) | API calls |
|
| [`/src/store`](https://github.com/RedHatInsights/image-builder-frontend/tree/main/src/store) | Redux store |
|
||||||
| [`/src/store/apiSlice.js`](https://github.com/RedHatInsights/image-builder-frontend/blob/main/src/store/apiSlice.js) | RTK Query calls |
|
| [`/src/api.js`](https://github.com/RedHatInsights/image-builder-frontend/blob/main/src/api.js) | API calls |
|
||||||
|
|
||||||
## Style Guidelines
|
## Style Guidelines
|
||||||
|
|
||||||
|
|
@ -139,3 +139,17 @@ npm run test
|
||||||
```
|
```
|
||||||
|
|
||||||
These tests will also be run in our Travis CI when a PR is opened.
|
These tests will also be run in our Travis CI when a PR is opened.
|
||||||
|
|
||||||
|
## API endpoints
|
||||||
|
|
||||||
|
API slice definitions are generated using the [@rtk-query/codegen-openapi](https://redux-toolkit.js.org/rtk-query/usage/code-generation) package.
|
||||||
|
|
||||||
|
OpenAPI schema for the endpoints are stored in `/api/schema`. Their
|
||||||
|
corresponding configuration files are stored in `/api/config`. Each endpoint
|
||||||
|
has a corresponding empty API slice and generated API slice which are stored in
|
||||||
|
`/src/store`.
|
||||||
|
|
||||||
|
To generate or update API slice definitions, run:
|
||||||
|
```bash
|
||||||
|
npm run api
|
||||||
|
```
|
||||||
|
|
|
||||||
11
api.sh
Normal file
11
api.sh
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Run commands in the background using & operator
|
||||||
|
npx @rtk-query/codegen-openapi ./api/config/image-builder.ts &
|
||||||
|
npx @rtk-query/codegen-openapi ./api/config/rhsm.ts &
|
||||||
|
npx @rtk-query/codegen-openapi ./api/config/contentSources.ts &
|
||||||
|
npx @rtk-query/codegen-openapi ./api/config/provisioning.ts &
|
||||||
|
|
||||||
|
# Wait for all background jobs to finish
|
||||||
|
wait
|
||||||
|
|
||||||
|
|
@ -112,7 +112,7 @@
|
||||||
"test": "TZ=UTC jest --verbose --no-cache",
|
"test": "TZ=UTC jest --verbose --no-cache",
|
||||||
"test:single": "jest --verbose -w 1",
|
"test:single": "jest --verbose -w 1",
|
||||||
"build": "webpack --config config/prod.webpack.config.js",
|
"build": "webpack --config config/prod.webpack.config.js",
|
||||||
"api": "npx @rtk-query/codegen-openapi ./api/config/image-builder.ts & npx @rtk-query/codegen-openapi ./api/config/rhsm.ts & npx @rtk-query/codegen-openapi ./api/config/contentSources.ts & npx @rtk-query/codegen-openapi ./api/config/provisioning.ts",
|
"api": "bash api.sh",
|
||||||
"verify": "npm-run-all build lint test"
|
"verify": "npm-run-all build lint test"
|
||||||
},
|
},
|
||||||
"insights": {
|
"insights": {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue