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
+81-44Lines changed: 81 additions & 44 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,47 +1,16 @@
1
1
# `oapi-codegen`
2
2
3
-
`oapi-codegen` is a library, and command-line tool, to convert OpenAPI API specifications to Go code, be it server-side implementations, API clients, or simply models.
3
+
`oapi-codegen` is a command-line tool and library, to convert OpenAPI API specifications to Go code, be it server-side implementations, API clients, or simply HTTP models.
4
4
5
5
`oapi-codegen` aims to reduce some of the tedious boilerplate that can be found when building or interacting with APIs, and focusses on:
6
6
7
7
- idiomatic Go, where possible
8
8
- fairly simple generated code, erring on the side of duplicate code over nicely refactored code
9
9
- supporting as much of OpenAPI 3.x as is possible, alongside Go's type system
10
10
11
-
⚠️ This README may be for the latest development version, which may contain
12
-
unreleased changes. Please ensure you're looking at the README for the latest
13
-
release version.
11
+
You can read more about our [Design Decisions](#design-decisions) below.
14
12
15
-
Does not 2.0
16
-
17
-
## OpenAPI Client and Server Code Generator
18
-
19
-
```
20
-
This package contains a set of utilities for generating Go boilerplate code for
[Iris](https://github.com/kataras/iris), and [1.22+ net/http](https://pkg.go.dev/net/http)
34
-
have also been added by contributors as additional routers.
35
-
We chose Echo because the `Context` object is a mockable interface, and it allows for some advanced
36
-
testing.
37
-
38
-
This package tries to be too simple rather than too generic, so we've made some
39
-
design decisions in favor of simplicity, knowing that we can't generate strongly
40
-
typed Go code for all possible OpenAPI Schemas. If there is a way to accomplish
41
-
something via utility code or reflection, it's probably a better approach than
42
-
code generation, which is fragile due to the very dynamic nature of OpenAPI and
43
-
the very static nature of Go.
44
-
```
13
+
⚠️ This README may be for the latest development version, which may contain unreleased changes. Please ensure you're looking at the README for the latest release version.
45
14
46
15
## Install
47
16
@@ -60,7 +29,11 @@ import (
60
29
)
61
30
```
62
31
63
-
Then, each **??**
32
+
Then, each invocation of `oapi-codegen` would be used like so:
33
+
34
+
```go
35
+
//go:generate go run github.com/deepmap/oapi-codegen/v2/cmd/oapi-codegen --config=config.yaml ../../api.yaml
36
+
```
64
37
65
38
Alternatively, you can install it as a binary with:
66
39
@@ -69,17 +42,23 @@ $ go install github.com/deepmap/oapi-codegen/v2/cmd/oapi-codegen@latest
69
42
$ oapi-codegen -version
70
43
```
71
44
45
+
Which then means you can invoke it like so:
46
+
47
+
```go
48
+
//go:generate go run oapi-codegen --config=config.yaml ../../api.yaml
49
+
```
50
+
72
51
## Usage
73
52
74
-
`oapi-codegen` is largely **??**.
53
+
`oapi-codegen` is largely configured using a YAML configuration file, to simplify the number of flags that users need to remember.
75
54
76
55
For full https://pkg.go.dev/github.com/deepmap/oapi-codegen/v2/pkg/codegen#Configuration
77
56
78
57
## Features
79
58
80
59
`oapi-codegen` supports:
81
60
82
-
- Generating server-side boilerplate for [a number of servers]
61
+
- Generating server-side boilerplate for [a number of servers] TODO
83
62
- Generating client API boilerplate
84
63
- Generating the types
85
64
- Splitting **??**
@@ -93,6 +72,18 @@ For full https://pkg.go.dev/github.com/deepmap/oapi-codegen/v2/pkg/codegen#Confi
93
72
- Single-file output
94
73
- Support multiple OpenAPI files by having a package-per-file
95
74
-**??**
75
+
- Support of OpenAPI 3.x
76
+
- OpenAPI 3.1 support is [awaiting upstream support](https://github.com/deepmap/oapi-codegen/issues/373)
77
+
- Note that this does not include OpenAPI 2.0 (aka Swagger)
78
+
79
+
```
80
+
This package tries to be too simple rather than too generic, so we've made some
81
+
design decisions in favor of simplicity, knowing that we can't generate strongly
82
+
typed Go code for all possible OpenAPI Schemas. If there is a way to accomplish
83
+
something via utility code or reflection, it's probably a better approach than
84
+
code generation, which is fragile due to the very dynamic nature of OpenAPI and
85
+
the very static nature of Go.
86
+
```
96
87
97
88
### Generating server-side boilerplate
98
89
@@ -116,42 +107,88 @@ To provide you a fully Test Driven Development style test harness, you could use
116
107
117
108
<tr>
118
109
<th>
119
-
Server name
110
+
Server
120
111
</th>
121
112
<th>
122
-
Configuration **??**
113
+
<code>generate</code> flag to enable code generation
123
114
</th>
124
115
</tr>
125
116
126
117
<tr>
127
118
<td>
119
+
120
+
[Chi](https://github.com/go-chi/chi)
121
+
128
122
</td>
129
123
<td>
130
-
<code></code>
124
+
<code>chi-server</code>
131
125
</td>
132
126
</tr>
133
127
134
128
<tr>
135
129
<td>
130
+
131
+
[Echo](https://github.com/labstack/echo)
132
+
136
133
</td>
137
134
<td>
138
-
<code></code>
135
+
<code>echo-server</code>
139
136
</td>
140
137
</tr>
141
138
142
139
<tr>
143
140
<td>
141
+
142
+
[Fiber](https://github.com/gofiber/fiber)
143
+
144
+
</td>
145
+
<td>
146
+
<code>fiber-server</code>
147
+
</td>
148
+
</tr>
149
+
150
+
151
+
<tr>
152
+
<td>
153
+
154
+
[Gin](https://github.com/gin-gonic/gin)
155
+
144
156
</td>
145
157
<td>
146
-
<code></code>
158
+
<code>gin-server</code>
147
159
</td>
148
160
</tr>
149
161
150
162
<tr>
151
163
<td>
164
+
165
+
[gorilla/mux](https://github.com/gorilla/mux)
166
+
167
+
</td>
168
+
<td>
169
+
<code>gorilla-server</code>
170
+
</td>
171
+
</tr>
172
+
173
+
<tr>
174
+
<td>
175
+
176
+
[Iris](https://github.com/kataras/iris)
177
+
178
+
</td>
179
+
<td>
180
+
<code>iris-server</code>
181
+
</td>
182
+
</tr>
183
+
184
+
<tr>
185
+
<td>
186
+
187
+
[1.22+ `net/http`](https://pkg.go.dev/net/http)
188
+
152
189
</td>
153
190
<td>
154
-
<code></code>
191
+
<code>std-http-server</code>
155
192
</td>
156
193
</tr>
157
194
@@ -225,7 +262,7 @@ Got one to add? Please raise a PR!
0 commit comments