darto_openapi library
OpenAPI 3.1 spec generation and Scalar API docs for the Darto web framework.
Describe a route once — it is mounted on the app (validating the request body) and recorded for the generated OpenAPI document.
import 'package:darto/darto.dart';
import 'package:darto_openapi/darto_openapi.dart';
final app = Darto();
final api = OpenApi(app, info: Info(title: 'Blog API', version: '1.0.0'));
api.post('/posts',
summary: 'Create a post',
tags: ['posts'],
request: Req(json: Schema.object({
'title': Schema.string(minLength: 1), // required by default
})),
responses: {201: Res('Created')},
handler: (c) => c.created(c.req.valid('json')),
);
app.use(api.docs()); // serves /openapi.json and /docs (Scalar)
await app.listen(3000);
Classes
- Info
-
OpenAPI
infoobject. - OpenApi
-
OpenAPI 3.1 registry for a
Dartoapp. - Req
- The request contract for a route — documents and validates.
- Res
- A documented response.
- Schema
- A schema builder that doubles as a validator and an OpenAPI 3.1 Schema Object generator.
- SecurityScheme
-
An OpenAPI security scheme (emitted under
components.securitySchemes). - Server
-
OpenAPI
serverobject.
Functions
-
generateDartClient(
Map< String, dynamic> spec, {String className = 'ApiClient', String baseUrl = 'http://localhost:3000'}) → String - Generates a typed Dart API client from an OpenAPI 3.1 document (such as the one produced by OpenApi.toJson).