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
+20-20Lines changed: 20 additions & 20 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
# OpenAPI Codegen
2
2
3
-
⚠️ This project is in early stage, please check the issues to see what’s is missing! ⚠️
3
+
⚠️ This project is in an early stage, please check the issues to see what’s missing! ⚠️
4
4
5
5
-> Insert logo and badges here
6
6
@@ -12,15 +12,15 @@ This will give you full auto-completion and type-safety of your APIs
12
12
13
13
**For backend:**
14
14
15
-
This will generate you everything to be able to deliver a perfect API, spec driven.
15
+
This will generate everything you need to deliver a perfect API, spec driven.
16
16
17
17
## Getting started
18
18
19
19
```bash
20
20
$ npx @openapi-codegen/cli init
21
21
```
22
22
23
-
Follow the steps, this will generate you a configuration file (openapi-codegen.config.ts) and update your `package.json`
23
+
Follow the steps, this will generate a configuration file for you (openapi-codegen.config.ts) and update your `package.json`
24
24
25
25
```bash
26
26
$ yarn gen # or the defined alias
@@ -30,28 +30,28 @@ You should have a bunch of types / components ready to be used.
30
30
31
31
## Philosophy
32
32
33
-
In software development, the harder part is usually communication and more specifically documentation.
33
+
In software development, communication between components and documentation around it is often no fun.
34
34
35
-
GraphQL did resolve this by having documentation part of the tooling (introspection), sadly this is often harder with REST API. OpenAPI can be an amazing tool, if, and if only the documentation and the actual implementation are aligned!
35
+
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!
36
36
37
37
### Backend side
38
38
39
-
For this, we have two viable options from the backend perspective:
39
+
There are two different approaches:
40
40
41
-
1. The OpenAPI is generated from the code (code first)
42
-
2. The code is generated from OpenAPI (spec first)
41
+
1. The OpenAPI spec is generated from the code (**code first**)
42
+
2. The code is generated from the OpenAPI spec (**spec first**)
43
43
44
-
And this need to be linked to the type system of the language, so everything is connected, and we remove or update something that impact the final response, this is **automatically** reflected!
44
+
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!
45
45
46
-
This library is to support the second option, spec first. By doing so, your documentation is not your last boring task on the list, but the first exiting one! Indeed, you can’t start coding without generating your types (models & controllers) from the specs.
46
+
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.
47
47
48
-
This have few benefits:
48
+
This has multiple benefits:
49
49
50
50
- You can take your time to think about your API before writing any code!
51
-
- You can discuss the API with your team (and discover API design problem earlier)
51
+
- You can discuss the API with your team (and discover API design problems earlier)
52
52
- You can generate all your validation rules
53
53
54
-
As example, if you write this object in your schema:
54
+
For example, if you add this object to your schema:
55
55
56
56
```yaml
57
57
SignUpInput:
@@ -79,15 +79,15 @@ SignUpInput:
79
79
- lastName
80
80
```
81
81
82
-
OpenAPI Codegen will be able to generate all the relevant validation (or at least give you the choice to do it)
82
+
OpenAPI Codegen will be able to generate all the relevant validation (or at least give you the choice to do it).
83
83
84
-
Note: You can also attach any custom logic with`x-*` tag, the possibilities are endless!
84
+
Note: You can also attach any custom logic by using the`x-*` tag, the possibilities are endless!
85
85
86
86
### Frontend side
87
87
88
-
Having to reverse engineer a backend response is the least productive/fun task ever! This is why, with some nice OpenAPI specs, we can actually generate some nice types components.
88
+
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 for you that lets you interact with your API in a safe manner.
89
89
90
-
Taking React as example, calling an API will be as simple as this:
90
+
Taking React as example, calling an API can be as simple as this:
91
91
92
92
```tsx
93
93
import { useListPets } from "./petStore/petStoreComponents"; // <- output from openapi-codegen
@@ -101,12 +101,12 @@ const App = () => {
101
101
102
102
And since this generated from the specs, everything is safe at build time!
103
103
104
-
Note: If you can’t trust your backend, some runtime validation can be useful to avoid surprise in production 😅
104
+
Note: If you can’t trust your backend, some runtime validation can be useful to avoid surprises in production 😅
105
105
106
106
## Configuration
107
107
108
108
The only thing you need to manage is the configuration.
109
-
Everything is typed and selfdocumented, but just in case, you can find here an example configuration.
109
+
Everything is typed and self-documented, but just in case, you can find here example configuration below:
110
110
111
111
```ts
112
112
// openapi-codegen.config.ts
@@ -151,7 +151,7 @@ export default defineConfig({
151
151
});
152
152
```
153
153
154
-
You can import any generator into the `to` section, those can be provided by us or you, you have the full control of what you are generating!
154
+
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