0.21.0 • Published 6 months ago
@sdk-it/dart v0.21.0
@sdk-it/dart
A Dart SDK generator that converts OpenAPI specifications into type-safe Dart client libraries.
Description
This package generates Dart client code from OpenAPI specifications. The generated SDK includes:
- Dart classes for API models
- API client classes for each tag/group
- Request and response handling
- Type-safe method signatures
Installation
Add the generated SDK to your Dart or Flutter project. The generator will create a pubspec.yaml with required dependencies (such as http and mime).
Usage
Note: This uses the OpenStatus public OpenAPI spec as an example.
npx @sdk-it/cli@latest dart \
--spec https://api.openstatus.dev/v1/openapi \
--output ./openstatus \
--name OpenStatus \
--mode fullThis command creates a Dart package in the ./openstatus directory.
Add the SDK to Your Project
Add the generated SDK as a dependency in your pubspec.yaml:
dependencies:
openstatus_sdk:
path: ./openstatusRun dart pub get or flutter pub get to install dependencies.
Create and Configure the Client
import 'package:openstatus_sdk/package.dart';
final openstatus = OpenStatus(Options(baseUrl: 'https://api.openstatus.dev/v1/'));Make an API Request
final status = await openstatus.statusReport.getStatusReport();
if (status != null) {
print('Status: \\${status.summary}');
} else {
print('Request failed');
}Format Generated Code
The generator can format the output using dart format automatically. You can also run it manually:
dart format ./openstatusNotes
- The Dart SDK generator creates a package structure compatible with Dart and Flutter projects.
- The generated code uses the
httppackage for HTTP requests. - Each API group (tag) is mapped to a Dart client class.
- The generator supports OpenAPI 3.0 and 3.1 specifications.
- For advanced usage, see the TypeScript package documentation for general SDK-IT concepts.