|
| 1 | +<!-- --8<-- [start:docs] --> |
1 | 2 | # `oapi-codegen` |
2 | 3 |
|
3 | | -[](https://www.bestpractices.dev/projects/9450) |
4 | | - |
5 | 4 | > **Battle-tested**: This generator is continuously tested against 2,000+ real-world OpenAPI specs, successfully generating and compiling over 20 million lines of Go code. Handles complex specs with circular references, deep nesting, and union types. |
6 | 5 |
|
7 | 6 | Using `oapi-codegen` allows you to reduce the boilerplate required to create or integrate with |
@@ -53,14 +52,43 @@ oapi-codegen https://raw.githubusercontent.com/OAI/OpenAPI-Specification/main/ex |
53 | 52 | ``` |
54 | 53 |
|
55 | 54 | ## Examples |
56 | | -The [examples directory](examples) contains cases with useful examples how to use `oapi-codegen`. |
| 55 | +The [examples directory](https://github.com/doordash-oss/oapi-codegen-dd/tree/main/examples) contains useful examples of how to use `oapi-codegen`. |
| 56 | + |
| 57 | +## Why v3? |
| 58 | + |
| 59 | +This project is a fork of [oapi-codegen](https://github.com/oapi-codegen/oapi-codegen) v2, fully reworked to address limitations in the original. |
| 60 | + |
| 61 | +### Compatibility |
| 62 | + |
| 63 | +Tested against [2,137 real-world OpenAPI 3.0 specs](https://github.com/cubahno/specs): |
| 64 | + |
| 65 | +| Version | Passed | Failed | Pass Rate | |
| 66 | +|---------|--------|--------|-----------| |
| 67 | +| **v3** | 2,137 | 0 | **100%** | |
| 68 | +| v2 | 1,159 | 978 | 54.2% | |
| 69 | + |
| 70 | +### Key Improvements |
| 71 | + |
| 72 | +| Category | v2 | v3 | |
| 73 | +|----------|----|----| |
| 74 | +| **OpenAPI Support** | 3.0 only | 3.0, 3.1, 3.2 | |
| 75 | +| **Parser** | `kin-openapi` | `libopenapi` | |
| 76 | +| **Circular References** | Limited | Full support | |
| 77 | +| **Union Types (oneOf/anyOf)** | Basic | Full with optimizations | |
| 78 | +| **Name Conflicts** | Manual fix required | Automatic resolution | |
| 79 | +| **Validation** | None | `Validate()` methods | |
| 80 | +| **Server Scaffold** | Interface only, manual boilerplate | Full typed solution (service, middleware, main.go) | |
| 81 | +| **Filtering** | Tags, operation IDs | + Paths, extensions, schema properties | |
| 82 | +| **Overlays** | Single | Multiple, applied in order | |
| 83 | +| **Output** | Single file | Single or multiple files | |
| 84 | +| **Templates** | Monolithic | Composable with `{{define}}` blocks | |
| 85 | +| **Programmatic API** | Limited | Full (`ParseContext`, `TypeTracker`) | |
| 86 | +| **Server Frameworks** | 7 (Chi, Echo, Fiber, Gin, Gorilla, Iris, std-http) | 13 (+ Beego, go-zero, Kratos, GoFrame, Hertz, fasthttp) | |
57 | 87 |
|
| 88 | +### Migration |
58 | 89 |
|
59 | | -## Migrate from v2 |
60 | | -This project is a fork of [oapi-codegen](https://github.com/oapi-codegen/oapi-codegen) v2. |
61 | | -Due to the lack of OpenAPI 3.1 support in the original repository, we introduced a fully reworked implementation. |
62 | | -While this includes some breaking changes, it also brings more flexible generator and parser APIs for finer control over code generation. |
63 | | -If you're migrating from v2, please refer to the [migration guide](https://doordash-oss.github.io/oapi-codegen-dd/migrate-from-v2/) for important differences. |
| 90 | +If you're migrating from v2, please refer to the [migration guide](https://doordash-oss.github.io/oapi-codegen-dd/migrate-from-v2/). |
| 91 | +<!-- --8<-- [end:docs] --> |
64 | 92 |
|
65 | 93 | ## License |
66 | 94 | This project is licensed under the Apache License 2.0. |
|
0 commit comments