Serverpod Swagger
Automatically generate and serve Swagger UI for your Serverpod backend
What is Serverpod Swagger?
Serverpod Swagger is a package that automatically generates OpenAPI specifications from your Serverpod protocol definitions and serves a Swagger UI interface directly from your Serverpod server. This makes it easy to document and test your API endpoints during development.
Automatic Generation
Automatically generates OpenAPI 3.0 specifications from your Serverpod protocol definitions.
Interactive UI
Serves Swagger UI directly from your Serverpod server for interactive API documentation and testing.
Easy Integration
Simple to integrate with just a few lines of code in your Serverpod server setup.
Quick Start
Get started with Serverpod Swagger in just a few steps:
1. Add the package to your pubspec.yaml
1dependencies:
2 serverpod: ^2.8.0
3 serverpod_swagger: ^0.1.5
2. Add the Swagger UI route to your server
1import 'dart:io';
2import 'package:serverpod/serverpod.dart';
3import 'package:serverpod_swagger/serverpod_swagger.dart';
4
5future<void> main() async {
6 // Create the server
7 final pod = Serverpod(
8 // ... your configuration
9 );
10
11 // Add the Swagger UI route
12 pod.webServer.addRoute(
13 SwaggerUIRoute(
14 Directory(Directory.current.path),
15 mountPath: '/swagger/',
16 ),
17 );
18
19 // Start the server
20 await pod.start();
21}
3. Generate the OpenAPI specification
1dart run serverpod_swagger:generate
4. Access the Swagger UI
Start your Serverpod server and navigate to http://localhost:8082/swagger/
in your browser.
Features
- Automatic OpenAPI 3.0 specification generation from Serverpod protocol definitions
- Support for all Serverpod data types and custom classes
- Interactive Swagger UI for testing endpoints
- Customizable authentication schemes
- HTTP method customization
- Live-reloading during development
- Compatible with Serverpod 2.8.0 and higher