No reflection
- JSON encoding is code-generated and optimized, using go-faster/jx for speed and to overcome
encoding/jsonlimitations - Validation is code-generated directly from the specification
- No
interfaceoranyon the hot path
No boilerplate
- Structures are generated from the OpenAPI v3 specification
- Path arguments, headers and query parameters are parsed into typed structures
- String formats like
uuid,date,date-timeandurimap to Go types directly
Type-safe client & server
- Statically typed client and server generated from a single spec
- Implement one
Handlerinterface and you are done - Code-generated static radix router for fast request dispatch
Optional & nullable
- Optional and nullable fields without pointers when possible
- Generated
OptT,NilTandOptNilTwrappers with helpers - Array
nilsemantics follow the specification
Sum types
- Sum types are generated for
oneOf - Discriminator field is used when defined in the schema
- Otherwise the variant is inferred by type, unique fields or enum values
Batteries included
- OpenTelemetry tracing and metrics out of the box
- Server-Sent Events (SSE) client generation
- Middlewares, convenient errors and per-request options
From spec to Go, instantly
Describe your API once in OpenAPI v3 and let ogen generate a statically typed client and server.
petstore.yml
paths:
/pet/{petId}:
get:
operationId: getPetById
parameters:
- name: petId
in: path
required: true
schema:
type: integer
format: int64
responses:
'200':
description: Pet
content:
application/json:
schema:
$ref: '#/components/schemas/Pet'
generated Go
// Pet describes #/components/schemas/Pet.
type Pet struct {
ID int64 `json:"id"`
Name string `json:"name"`
Tag OptUUID `json:"tag"`
}
// Handler handles operations described
// by OpenAPI v3 specification.
type Handler interface {
// GET /pet/{petId}
GetPetById(ctx context.Context,
params GetPetByIdParams) (*Pet, error)
}