mirror of
https://github.com/hanzo-dart/sdk.git
synced 2026-10-30 19:32:47 +00:00
2479 operations over 1814 paths become 192 API classes and 2460 models, generated by hanzoai/openapi's driver from hanzoai/cloud openapi.yaml at the commit .spec-lock names. `dart` and not `dart-dio`: dart-dio's models declare 2460 `.g.dart` parts that only build_runner writes, so the package does not parse until a second code generator has run — output this driver neither invokes nor owns. The `dart` generator serializes in one pass over package:http, which is the transport hanzo-dart/hanzoai and hanzo-dart/base already speak. lib/hanzoai.dart is the only hand-written file under lib/: the front door, `hanzo()`, and a re-export. The driver owns the files it wrote, so it survives regeneration. dart pub get && dart analyze && dart test pass, and example/models.dart runs against api.hanzo.ai with no credential.
33 lines
1019 B
Dart
33 lines
1019 B
Dart
/// The Dart client for the Hanzo Cloud API at `api.hanzo.ai`.
|
|
///
|
|
/// Everything the generator writes lives in `api.dart` and is re-exported here,
|
|
/// so one import reaches the whole surface:
|
|
///
|
|
/// ```dart
|
|
/// import 'package:hanzoai/hanzoai.dart';
|
|
///
|
|
/// final models = ModelsApi(hanzo());
|
|
/// ```
|
|
library;
|
|
|
|
import 'api.dart';
|
|
|
|
export 'api.dart';
|
|
|
|
/// The Hanzo Cloud origin. Every generated API class defaults to it.
|
|
const String origin = 'https://api.hanzo.ai';
|
|
|
|
/// An [ApiClient] that sends [token] as the bearer credential on every call.
|
|
///
|
|
/// [token] is an access token minted by Hanzo IAM or an API key — `pk-`
|
|
/// publishable, `sk-` secret. Leave it out for the routes the document declares
|
|
/// open, such as `GET /v1/models`.
|
|
///
|
|
/// Point [base] elsewhere to reach another deployment.
|
|
ApiClient hanzo({String? token, String base = origin}) {
|
|
if (token == null) {
|
|
return ApiClient(basePath: base);
|
|
}
|
|
return ApiClient(basePath: base, authentication: HttpBearerAuth()..accessToken = token);
|
|
}
|