OpenAPI¶
Diana generates an OpenAPI 3.0 document at build time from the same single classification pass that generates your route adapters — the spec cannot drift from the actual routes.
Enabling¶
server:
openapi:
enabled: true # default false
title: Todo API # patched into info.title
version: 1.2.3 # patched into info.version
The document is embedded in the generated code as a deterministic constant
and served at GET /openapi.json (guarded at runtime — toggling needs no
rebuild). Point Swagger UI or any OpenAPI tool at it.
What's in the document¶
- Paths and operations for every
@RestControllerroute (/todos/:id→/todos/{id}), withoperationId(Controller_method) and the controller name as tag. - Parameters from
@PathParam/@QueryParam/@Header: location, requiredness (nullable or defaulted ⇒ optional), primitive schema and default value. - Request bodies:
$refto the DTO schema for@Body()DTOs (arrays forList<Dto>),text/plainforStringbodies,multipart/form-dataforFormData, unconstrained objects for rawMap/Listbodies. - Responses keyed by the effective status (
@ResponseStatus, 204 forvoid) with the return schema. -
Schemas (
components/schemas) for every@Jsonclass and every validated DTO: property types (includingDateTime→string/date-time, enums with their values, nested$refs),requiredfrom non-nullable fields, and validation constraints mapped tominLength/maxLength/minimum/maximum/pattern/format: email(@NotBlank/@NotEmptyimplyminLength: 1). -
Content negotiation:
@Consumes/@ProducesMIME lists are projected intorequestBody.contentand responsecontent(same schema per MIME type); SSE routes (Streamreturns) are documented as a200withtext/event-streamcontent.
Best-effort areas (documented, not errors): DTOs that are neither @Json
nor validated (e.g. plain json_serializable classes) appear as unconstrained
{} schemas; DianaResponse returns have unspecified content.
Branding¶
info.title/info.version are patched at startup from
server.openapi.title/server.openapi.version (via patchOpenApiInfo),
keeping the build-time constant deterministic while letting deployments
brand the spec.