dart_openapi_generator 0.3.0 copy "dart_openapi_generator: ^0.3.0" to clipboard
dart_openapi_generator: ^0.3.0 copied to clipboard

Native-Dart, OpenAPI 3.x → Dart code generator. Generates idiomatic Dio-based model classes and API client services via build_runner. No JVM. No Mustache. Generated code looks hand-written.

example/lib/main.dart

import 'generated/generated.dart';

/// Run `dart run build_runner build --delete-conflicting-outputs` in this
/// directory to generate (config lives in `build.yaml`, see the
/// `dart_openapi_generator` options block):
/// - lib/generated/models/         (one .dart file per schema)
/// - lib/generated/services/       (one .dart file per tag)
/// - lib/generated/api_client.dart (ExampleApiClient with auth factories)
/// - lib/generated/generated.dart  (barrel export)
void main() {
  final client = ExampleApiClient(
    baseUrl: 'https://api.example.com/v1',
    interceptors: [
      ExampleApiClient.bearerAuth('your-bearer-token'),
    ],
  );

  // Example usage — run build_runner first to generate ExampleApiClient:
  // await client.users.listUsers();
  // await client.users.getUser('user-id');
  // await client.users.createUser(User(id: '1', name: 'Alice', email: 'alice@example.com'));
  // await client.auth.createToken(TokenRequest(username: 'alice', password: 'secret'));
  // await client.categories.listCategories();

  // Other available auth factories (generated from securitySchemes in the spec):
  // ExampleApiClient.apiKeyAuth('my-key', headerName: 'X-Api-Key')
  // ExampleApiClient.apiKeyQueryAuth('my-key', paramName: 'api_key')
  // ExampleApiClient.basicAuth('user', 'password')

  print(client.runtimeType);
}
0
likes
150
points
393
downloads

Documentation

API reference

Publisher

verified publisherangelocassano.it

Weekly Downloads

Native-Dart, OpenAPI 3.x → Dart code generator. Generates idiomatic Dio-based model classes and API client services via build_runner. No JVM. No Mustache. Generated code looks hand-written.

Homepage
Repository (GitHub)
View/report issues

Topics

#openapi #code-generation #dart #build-runner

License

MIT (license)

Dependencies

build, code_builder, dart_style, meta, path, pub_semver, source_span, yaml

More

Packages that depend on dart_openapi_generator