OpenAPI Specification
Build self-documenting REST APIs using OpenAPI 3.1 specification with component schemas, request bodies, responses, and parameters.
Tutorials
Browse the step-by-step guides below to learn OpenAPI features in Kestrun:
- Hello World — Create a simple OpenAPI spec with a single endpoint
- Component Schemas — Define reusable request and response schemas
- RequestBody Components — Create reusable request body components
- Parameter Components — Define reusable query and path parameters
- Response Components — Create consistent response structures
- Complete Components — Combine all component types in a full API
- Tags and External Docs — Group operations and attach documentation links
- Document Information — Populate title, contact, license, and server metadata
- Component Headers — Define reusable response headers
- Component Links — Define operation links
- Component Callbacks — Define asynchronous callbacks
- WebHooks — Define top-level webhooks (Planned)
- Examples — Component and inline examples for requests, responses, and parameters
- Swagger Petstore — Full implementation of the Swagger Petstore API
- Redocly Museum API — Full implementation of the Redocly Museum API
- Multiple OpenAPI Documents — Serve multiple OpenAPI documents (default + webhook) from one server
- Product Search with HTTP QUERY — OpenAPI 3.2 QUERY method with request body search filters
- SSE (OpenAPI) — Document a
text/event-streamSSE endpoint - SSE Broadcast (OpenAPI) — Document broadcast SSE + a trigger API
- SignalR (OpenAPI) — Document SignalR-adjacent HTTP routes with OpenAPI
- XML Modeling — OpenAPI 3.2 XML metadata (
OpenApiXml) for schemas - RFC 6570 Variable Mapping — RFC6570 path expressions (
{+path}) mapped from ASP.NET route values
Quick start: run the samples
From the repository root:
# 1) Hello World - minimal OpenAPI spec
pwsh .\docs\_includes\examples\pwsh\10.1-OpenAPI-Hello-World.ps1
# 2) Component schemas - request/response definitions
pwsh .\docs\_includes\examples\pwsh\10.2-OpenAPI-Component-Schema.ps1
# 3) RequestBody components - reusable request structures
pwsh .\docs\_includes\examples\pwsh\10.3-OpenAPI-Component-RequestBody.ps1
# 4) Parameter components - reusable query/path parameters
pwsh .\docs\_includes\examples\pwsh\10.4-OpenAPI-Component-Parameter.ps1
# 5) Response components - reusable response structures
pwsh .\docs\_includes\examples\pwsh\10.5-OpenAPI-Component-Response.ps1
# 6) Complete components - full API with all component types
pwsh .\docs\_includes\examples\pwsh\10.6-OpenAPI-Components-RequestBody-Response.ps1
# 7) Tags and external docs - group operations and link docs
pwsh .\docs\_includes\examples\pwsh\10.7-OpenAPI-Tags.ps1
# 8) Document info - contact, license, servers
pwsh .\docs\_includes\examples\pwsh\10.8-OpenAPI-Document-Info.ps1
# 9) Component headers - reusable response headers
pwsh .\docs\_includes\examples\pwsh\10.9-OpenAPI-Component-Header.ps1
# 10) Component links - operation relationships
pwsh .\docs\_includes\examples\pwsh\10.10-OpenAPI-Component-Link.ps1
# 13) Examples - component + inline examples
pwsh .\docs\_includes\examples\pwsh\10.13-OpenAPI-Examples.ps1
Key Concepts
- OpenAPI 3.0+ Specifications (including 3.2): Industry-standard API documentation format
- Component Schemas: Reusable data structures defined once and referenced multiple times
- RequestBody Components: Standardized request payloads across endpoints
- Parameter Components: Consistent query string, path, header, and cookie parameters
- Response Components: Uniform response structures for success and error cases
- Swagger UI: Interactive API documentation and testing interface
- Code Generation: Use OpenAPI specs to generate client SDKs
Documentation Routes
Kestrun provides multiple documentation viewers for your OpenAPI spec:
- Swagger UI — Classic, feature-rich interactive documentation
- ReDoc — Clean, responsive documentation layout
- Scalar — Modern, beautiful API explorer
- RapidOC — Fast, performant alternative
- Elements — StopLight Elements API viewer
Visit http://localhost:5000/swagger, /redoc, /scalar, /rapidoc, or /elements to view the documentation (paths vary by script).
Table of contents
- Hello World
- Component Schemas
- RequestBody Components
- Parameter Components
- Response Components
- Complete Components
- Tags and External Docs
- Document Information
- Component Headers
- Component Links
- Component Callbacks
- WebHooks
- Examples
- Swagger Petstore
- Redocly Museum API
- Multiple OpenAPI Documents
- Product Search with HTTP QUERY (OpenAPI 3.2)
- SSE (OpenAPI)
- SSE Broadcast (OpenAPI)
- SignalR (OpenAPI)
- XML Modeling
- RFC 6570 Variable Mapping