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
* Add changelogs in prettier ignore
* Remove generateReactQueryFunctions
This is a legacy duplicate with the new queryFn
* Fix let keyword in the fetcher template
* Fix types issue on `deepMerge`
* Make sure to not generate an empty description
* Add type hint to avoid over generating
* Add support for SkipToken
* Update documentation
* Update example
Copy file name to clipboardExpand all lines: README.md
+65-88Lines changed: 65 additions & 88 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -79,85 +79,80 @@
79
79
80
80
- Wire up the `QueryClient` as described [here](https://tanstack.com/query/v4/docs/adapters/react-query).
81
81
82
-
## Philosophy
83
-
84
-
In software development, communication between components and documentation around it is often no fun.
85
-
86
-
GraphQL did resolve this by making documentation a part of the tooling (introspection), sadly this is often harder with REST APIs. OpenAPI can be an amazing tool, if, and only if the documentation (spec) and the actual implementation are aligned!
87
-
88
-
### Backend side
89
-
90
-
There are two different approaches:
91
-
92
-
1. The OpenAPI spec is generated from the code (**code first**)
93
-
2. The code is generated from the OpenAPI spec (**spec first**)
94
-
95
-
In either case, there needs to be an integration with the type system of the language, so everything is connected, and as we remove or update something that impacts the final response, this is **automatically** reflected!
96
-
97
-
This library has chosen the second approach, **spec first**. By doing so, your documentation is not your final (boring) task on the list, but the first and exciting one when adding new functionality! Indeed, you can’t start coding without generating your types (models & controllers) from the specs.
98
-
99
-
This has multiple benefits:
100
-
101
-
- You can take your time to think about your API before writing any code!
102
-
- You can discuss the API with your team (and discover API design problems earlier)
103
-
- You can generate all your validation rules
104
-
105
-
For example, if you add this object to your schema:
106
-
107
-
```yaml
108
-
SignUpInput:
109
-
type: object
110
-
properties:
111
-
email:
112
-
type: string
113
-
format: email
114
-
maxLength: 255
115
-
password:
116
-
type: string
117
-
maxLength: 255
118
-
firstName:
119
-
type: string
120
-
pattern: ^[0-9a-zA-Z]*$
121
-
maxLength: 255
122
-
lastName:
123
-
type: string
124
-
pattern: ^[0-9a-zA-Z]*$
125
-
maxLength: 255
126
-
required:
127
-
- email
128
-
- password
129
-
- firstName
130
-
- lastName
131
-
```
82
+
## Usage
83
+
84
+
### React Query components
132
85
133
-
OpenAPI Codegen will be able to generate all the relevant validation (or at least give you the choice to do it).
86
+
Using [https://api.apis.guru/v2/specs/giphy.com/1.0/openapi.yaml](giphy specs) as example
134
87
135
-
>**Note**
136
-
> You can also attach any custom logic by using the `x-*` tag, the possibilities are endless!
88
+
This will generate lot of ready-to-use hooks like:
137
89
138
-
### Frontend side
90
+
- `useRandomGif` -> Wrapper around `useQuery` with injected types
91
+
- `useSuspenseRandomGif` -> Same but with `useSuspense`
139
92
140
-
Having to reverse engineer a backend response is the least productive/fun task ever! However, given a nice OpenAPI specs, we can actually generate nicely typed code foryou that lets you interact with your APIin a safe manner.
93
+
And you will have some `useMutation`ifthe api expose some (not the casewith this example)
141
94
142
-
Taking React as example, calling an API can be as simple as this: _(this hooks are using **Tanstack Query** under the hood)_
95
+
Here an example of usage of this generated api:
143
96
144
97
```tsx
145
-
import { useListPets } from "./petStore/petStoreComponents"; // <- output from openapi-codegen
You can import any generator into the `to` section, those can be the ones provided by this project or your own custom ones. You have full control of what you are generating!
0 commit comments