Skip to content
pubscout

tonik

0.11.1, released 4 weeks ago by ottenweller.net

Pure Dart OpenAPI 3.0/3.1 code generator for type-safe API client packages.

$ flutter pub add tonik
Source repository

What it does

Generates type-safe API client packages for Dart and Flutter from OpenAPI specifications. It produces idiomatic code with sealed classes for oneOf variants, exhaustive pattern matching for status codes, and support for multiple HTTP backends.

AI-written summary of version 0.11.1, based on the package's README and metadata. Report an inaccuracy

Use it when

  • You want to generate a type-safe API client package from an OpenAPI specification without JVM or Docker dependencies.
  • You need strict status-code and content-type response handling using sealed classes and pattern matching.

Skip it when

  • You prefer hand-written API clients or runtime reflection instead of generated code.

Strengths

  • Generates distinct types for every status code and content type combination.
  • Pure Dart implementation with no JVM or Docker requirement.
  • Supports all OpenAPI parameter encoding styles and advanced composition features like oneOf and allOf.

Weaknesses

  • Requires code regeneration whenever the OpenAPI specification changes.

Setup

Kind
Pure Dart
Effort
Low
Code generation
No
Direct dependencies
9

Activate the package globally using `dart pub global activate tonik` and run generation from the command line.

import 'package:my_api/my_api.dart';
import 'package:tonik_util/tonik_util.dart';

final api = PetApi(CustomServer(baseUrl: 'https://api.example.com'));

final response = await api.getPetById(petId: 1);
switch (response) {
  case TonikSuccess(:final value):
    print('Response: $value');
  case TonikError(:final error):
    print('Failed: $error');
}

Alternatives

Packages that do the same job and could replace tonik.

Works with

Packages commonly used together with tonik: ones it builds on, ones built on it, and its own family.