Skip to main content

angel3_openapi 10.0.0 copy "angel3_openapi: ^10.0.0" to clipboard
angel3_openapi: ^10.0.0 copied to clipboard

OpenAPI 3.1 documents of Angel3 applications, built from their routes and services, with a Swagger UI page.

example/main.dart

import 'package:angel3_framework/angel3_framework.dart';
import 'package:angel3_framework/http.dart';
import 'package:angel3_openapi/angel3_openapi.dart';

Future<void> main() async {
  var app = Angel();

  var openApi = OpenApi(
    title: 'Todo API',
    version: '1.0.0',
    schemas: {
      'Todo': {
        'type': 'object',
        'properties': {
          'id': {'type': 'string'},
          'text': {'type': 'string'},
          'completed': {'type': 'boolean'},
        },
      },
    },
  );
  // GET /openapi.json, and the Swagger UI page at GET /docs.
  await app.configure(openApi.configureServer);

  // A service documents its own operations: GET /todos, POST /todos,
  // GET, PATCH, PUT and DELETE /todos/{id}.
  app.use('/todos', MapService());
  openApi.describeService('todos', schema: OpenApi.ref('Todo'));

  // A route documents its method, path and path parameters; describe adds
  // the rest.
  app.get('/stats/int:year', (req, res) => {'year': req.params['year']});
  openApi.describe(
    'GET',
    'stats/int:year',
    OpenApiOperation(
      summary: 'The statistics of a year',
      tags: ['stats'],
      responses: {200: OpenApiResponse('The statistics')},
    ),
  );

  app.fallback((req, res) => throw AngelHttpException.notFound());

  var http = AngelHttp(app);
  await http.startServer('127.0.0.1', 3000);
  print('Swagger UI at ${http.uri.replace(path: '/docs')}');
}
0
likes
160
points
72
downloads

Documentation

API reference

Publisher

verified publisherdukefirehawk.com

Weekly Downloads

OpenAPI 3.1 documents of Angel3 applications, built from their routes and services, with a Swagger UI page.

Homepage
Repository (GitHub)
View/report issues
Contributing

Topics

#openapi #swagger #documentation

License

BSD-3-Clause (license)

Dependencies

angel3_container, angel3_framework, angel3_route, http_parser

More

Packages that depend on angel3_openapi