OpenApi class

OpenAPI 3.1 registry for a Darto app.

Use get/post/… to register a route once — it is mounted on the app (with request validation when a request.json schema is given) and recorded for the generated spec. Mount docs to serve /openapi.json and a Scalar API reference UI.

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)})),
  responses: {201: Res('Created')},
  handler: (c) => c.created(c.req.valid('json')),
);

app.use(api.docs()); // /openapi.json + /docs (Scalar)

Constructors

OpenApi(Darto app, {required Info info, List<Server> servers = const [], Map<String, SecurityScheme> securitySchemes = const {}})

Properties

app → Darto
final
hashCode int
The hash code for this object.
no setterinherited
info Info
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
securitySchemes Map<String, SecurityScheme>
final
servers List<Server>
final

Methods

delete(String path, {String? summary, String? description, List<String>? tags, Req? request, Map<int, Res>? responses, List<String>? security, List<Middleware> middlewares = const [], required Handler handler}) → void
docs({String specPath = '/openapi.json', String uiPath = '/docs', String? title}) → Middleware
Global middleware that serves the spec at specPath and a Scalar API reference UI at uiPath.
get(String path, {String? summary, String? description, List<String>? tags, Req? request, Map<int, Res>? responses, List<String>? security, List<Middleware> middlewares = const [], required Handler handler}) → void
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
patch(String path, {String? summary, String? description, List<String>? tags, Req? request, Map<int, Res>? responses, List<String>? security, List<Middleware> middlewares = const [], required Handler handler}) → void
post(String path, {String? summary, String? description, List<String>? tags, Req? request, Map<int, Res>? responses, List<String>? security, List<Middleware> middlewares = const [], required Handler handler}) → void
put(String path, {String? summary, String? description, List<String>? tags, Req? request, Map<int, Res>? responses, List<String>? security, List<Middleware> middlewares = const [], required Handler handler}) → void
toJson() Map<String, dynamic>
The full OpenAPI 3.1 document.
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited