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
|
||||
|
||||
### Quick Reference
|
||||
| Directory | Description |
|
||||
| --------- | ----------- |
|
||||
| [`/config`](https://github.com/RedHatInsights/image-builder-frontend/tree/main/config) | webpack configuration |
|
||||
| [`/devel`](https://github.com/RedHatInsights/image-builder-frontend/tree/main/devel) | tools for local development |
|
||||
| [`/src`](https://github.com/RedHatInsights/image-builder-frontend/tree/main/src) | source code |
|
||||
| [`/src/Components`](https://github.com/RedHatInsights/image-builder-frontend/tree/main/src/Components) | source code split by individual components |
|
||||
| [`/src/test`](https://github.com/RedHatInsights/image-builder-frontend/tree/main/src/test) | test utilities |
|
||||
| [`/src/test/mocks`](https://github.com/RedHatInsights/image-builder-frontend/tree/main/src/test/mocks) | mock handlers and server config for MSW |
|
||||
| [`/src/store`](https://github.com/RedHatInsights/image-builder-frontend/tree/main/src/store) | Redux store |
|
||||
| [`/src/api.js`](https://github.com/RedHatInsights/image-builder-frontend/blob/main/src/api.js) | API calls |
|
||||
| [`/src/store/apiSlice.js`](https://github.com/RedHatInsights/image-builder-frontend/blob/main/src/store/apiSlice.js) | RTK Query calls |
|
||||
| Directory | Description |
|
||||
| --------- | ----------- |
|
||||
| [`/api`](https://github.com/RedHatInsights/image-builder-frontend/tree/main/api) | API schema and config files |
|
||||
| [`/config`](https://github.com/RedHatInsights/image-builder-frontend/tree/main/config) | webpack configuration |
|
||||
| [`/devel`](https://github.com/RedHatInsights/image-builder-frontend/tree/main/devel) | tools for local development |
|
||||
| [`/src`](https://github.com/RedHatInsights/image-builder-frontend/tree/main/src) | source code |
|
||||
| [`/src/Components`](https://github.com/RedHatInsights/image-builder-frontend/tree/main/src/Components) | source code split by individual components |
|
||||
| [`/src/test`](https://github.com/RedHatInsights/image-builder-frontend/tree/main/src/test) | test utilities |
|
||||
| [`/src/test/mocks`](https://github.com/RedHatInsights/image-builder-frontend/tree/main/src/test/mocks) | mock handlers and server config for MSW |
|
||||
| [`/src/store`](https://github.com/RedHatInsights/image-builder-frontend/tree/main/src/store) | Redux store |
|
||||
| [`/src/api.js`](https://github.com/RedHatInsights/image-builder-frontend/blob/main/src/api.js) | API calls |
|
||||
|
||||
## Style Guidelines
|
||||
|
||||
|
|
@ -139,3 +139,17 @@ npm run test
|
|||
```
|
||||
|
||||
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:single": "jest --verbose -w 1",
|
||||
"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"
|
||||
},
|
||||
"insights": {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue