You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+118-3Lines changed: 118 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,120 @@
1
-
# layer5-repo-template
2
-
This repository is used as the boilerplate for consistency across all Layer5 repos.
1
+
# OpenAPI API Client Generation and Compilation
2
+
3
+
Generate an API client from an OpenAPI schema in YAML format and create a rtk-query api client. Thes package streamlines this process and ensures a smooth workflow.
4
+
5
+
## Dependencies
6
+
7
+
1.**Node.js and npm:** Ensure you have Node.js and npm installed on your system. You can download them from [nodejs.org](https://nodejs.org/).
If you only want to include a few endpoints, you can use the `filterEndpoints` config option to filter your endpoints.
53
+
54
+
```
55
+
{
56
+
// ...
57
+
// should only have endpoints loginUser, placeOrder, getOrderById, deleteOrder
58
+
filterEndpoints: ['loginUser', /Order/],
59
+
}
60
+
```
61
+
62
+
### Endpoint overrides
63
+
64
+
If an endpoint is generated as a mutation instead of a query or the other way round, you can override that.
65
+
66
+
```
67
+
{
68
+
// ...
69
+
"endpointOverrides": [
70
+
{
71
+
"pattern": "loginUser",
72
+
"type": "mutation"
73
+
}
74
+
]
75
+
}
76
+
```
77
+
78
+
### Generating hooks
79
+
80
+
Setting `hooks: true` will generate `useQuery` and `useMutation` hook exports. If you also want `useLazyQuery` hooks generated or more granular control, you can also pass an object in the shape of: `{ queries: boolean; lazyQueries: boolean; mutations: boolean }`.
The api.js file contains the generated api endpoints , it injects them into the base rtk client . And then exports all the hooks to use them .
105
+
If we need to override an api endpoint we can injectEnpoints in a separate file .
106
+
107
+
## Troubleshooting
108
+
109
+
- If any of the steps fail, the script will exit with a non-zero status code, indicating a failure. Review the error messages to diagnose and resolve any issues.
110
+
111
+
- Ensure that the Bash script is executable by running `chmod +x generate-api.sh`.
112
+
113
+
## Important Notes
114
+
115
+
- Make sure the OpenAPI schema (`schema.yml`) is updated with latest changes and doesnt contain any breaking changes .
116
+
117
+
- Always validate and test the generated API client to ensure it functions as expected.
3
118
4
119
<div> </div>
5
120
@@ -17,6 +132,7 @@ Become a <b>Meshtee</b> today!</p>
17
132
18
133
Find out more on the <ahref="https://layer5.io/community">Layer5 community</a>. <br />
19
134
<br /><br /><br /><br />
135
+
20
136
</p>
21
137
22
138
<div> </div>
@@ -30,7 +146,6 @@ Find out more on the <a href="https://layer5.io/community">Layer5 community</a>.
0 commit comments