|
7 | 7 | [](https://github.com/oaswrap/spec/blob/main/go.mod) |
8 | 8 | [](LICENSE) |
9 | 9 |
|
10 | | -`spec` is a Go library for generating OpenAPI `3.0.x`, `3.1.x`, and `3.2.0` documents. It uses a router and functional options API, and owns its OpenAPI model and schema reflection — no external OpenAPI or JSON Schema generators needed. YAML serialization uses `github.com/goccy/go-yaml`. |
| 10 | +Code-first, framework-agnostic OpenAPI 3.x spec builder for Go. Generate docs from route registrations and Go structs — no annotations, no vendor lock-in. |
11 | 11 |
|
12 | 12 | --- |
13 | 13 |
|
|
16 | 16 | - **Native OpenAPI builder** — paths, operations, components, validation, and schema reflection are all implemented in this repository without third-party OpenAPI dependencies. |
17 | 17 | - **Framework-agnostic core** — use `spec.NewRouter` for static generation, or drop in adapters for Chi, Echo, Gin, Fiber, net/http, and Mux. |
18 | 18 | - **Code-first route documentation** — register routes and their documentation together using Go functions and typed options. |
19 | | -- **Version-aware output** — defaults to OpenAPI `3.0.4`, with full support for `3.1.2` and `3.2.0` features when selected. |
| 19 | +- **Version-aware output** — defaults to OpenAPI `3.1.2`, with full support for `3.0.x` and `3.2.0` features when selected. |
20 | 20 | - **Direct model escape hatches** — use typed `openapi` structs, `Extensions` for `x-*` fields, and `Extra` for official or future fields not yet wrapped by a helper option. |
21 | 21 | - **Deterministic output** — generated documents are stable enough for golden-file snapshot tests and CI documentation checks. |
22 | 22 |
|
@@ -124,7 +124,8 @@ type User struct { |
124 | 124 | | `MarshalJSON()` | Validates and serializes pretty-printed JSON. | |
125 | 125 | | `WriteSchemaTo("openapi.yaml")` | Infers format from file extension (`.yaml`, `.yml`, `.json`). | |
126 | 126 | | `Document()` | Returns the built `*openapi.Document`. | |
127 | | -| `Validate()` | Builds the document and checks OpenAPI invariants. | |
| 127 | +| `Validate()` | Builds the document and checks OpenAPI invariants. Returns only `SeverityError` findings. | |
| 128 | +| `ValidateReport()` | Builds and validates, returning all findings including warnings and info as `ValidationErrors`. | |
128 | 129 | | `Config()` | Returns the effective OpenAPI configuration. | |
129 | 130 |
|
130 | 131 | --- |
@@ -181,7 +182,7 @@ r := spec.NewRouter( |
181 | 182 | | Option | Purpose | |
182 | 183 | | --- | --- | |
183 | 184 | | `WithOpenAPIConfig(opts...)` | Build an `*openapi.Config` with defaults and apply options. | |
184 | | -| `WithOpenAPIVersion(version)` | Set `openapi`; default is `openapi.Version304`. Constants are available for `3.0.0`–`3.0.4`, `3.1.0`–`3.1.2`, and `3.2.0`. | |
| 185 | +| `WithOpenAPIVersion(version)` | Set `openapi`; default is `openapi.Version312`. Constants are available for `3.0.0`–`3.0.4`, `3.1.0`–`3.1.2`, and `3.2.0`. | |
185 | 186 | | `WithSelf(uri)` | Set OpenAPI `3.2.0` `$self`. | |
186 | 187 | | `WithJSONSchemaDialect(uri)` | Set root `jsonSchemaDialect`. | |
187 | 188 | | `WithTitle(title)` | Set `info.title`. | |
@@ -227,7 +228,7 @@ r := spec.NewRouter( |
227 | 228 |
|
228 | 229 | **Tag options:** `TagSummary`, `TagDescription`, `TagExternalDocs`, `TagParent` (3.2.0), `TagKind` (3.2.0). |
229 | 230 |
|
230 | | -**Server options:** `ServerDescription`, `ServerVariables`. |
| 231 | +**Server options:** `ServerDescription`, `ServerVariables`, `ServerName` (3.2.0). |
231 | 232 |
|
232 | 233 | --- |
233 | 234 |
|
@@ -283,6 +284,7 @@ api.Get("/users/{id}", |
283 | 284 | | --- | --- | |
284 | 285 | | `ContentType(contentType)` | Set media type; default is `application/json`. | |
285 | 286 | | `ContentDescription(description)` | Set request/response description. | |
| 287 | +| `ContentSummary(summary)` | Set request/response summary (OpenAPI `3.2.0`). | |
286 | 288 | | `ContentDefault(isDefault...)` | Mark response as `default`. | |
287 | 289 | | `ContentEncoding(prop, enc)` | Add media type encoding metadata for a property. | |
288 | 290 | | `ContentExample(value)` | Set media type `example`. | |
@@ -366,6 +368,7 @@ type SearchRequest struct { |
366 | 368 | | `header:"name"` | Header parameter. | |
367 | 369 | | `cookie:"name"` | Cookie parameter. | |
368 | 370 | | `querystring:"name"` | OpenAPI `3.2.0` whole-query-string parameter. | |
| 371 | +| `mediaType:"..."` | Media type for `querystring` parameter content; defaults to `application/x-www-form-urlencoded`. OpenAPI `3.2.0` only. | |
369 | 372 | | `form:"name"` | Form body property name for form content types. | |
370 | 373 |
|
371 | 374 | **Schema tags:** |
@@ -483,10 +486,13 @@ Selecting `openapi.Version320` enables the following additional features: |
483 | 486 | - Custom HTTP methods via `Add`, emitted as `additionalOperations`. |
484 | 487 | - `querystring` parameter tags. |
485 | 488 | - Root `$self` field. |
| 489 | +- Server `name` field. |
| 490 | +- Response `summary` field. |
486 | 491 | - Tag `parent` and `kind` fields. |
487 | 492 | - Security scheme metadata and deprecation fields. |
488 | 493 | - `components.mediaTypes`. |
489 | 494 | - Media type and encoding fields: `itemSchema`, `prefixEncoding`, `itemEncoding`. |
| 495 | +- Discriminator `defaultMapping`. |
490 | 496 | - Example `dataValue` and `serializedValue` fields. |
491 | 497 | - XML `nodeType`. |
492 | 498 |
|
|
0 commit comments