space_gen 1.2.2
space_gen: ^1.2.2 copied to clipboard
An OpenAPI generator, focused on generating high quality code.
space_gen example #
A tiny OpenAPI 3.1 spec for a pet store, plus the command to generate a Dart client package from it.
The spec #
petstore.yaml defines two operations — listPets and
getPet — and a Pet model with a PetStatus enum. It's intentionally
small so the generated output is easy to skim.
Generating a client #
From this directory:
dart pub global activate space_gen
space_gen -i petstore.yaml -o petstore_api
Or, without a global install:
dart run space_gen -i petstore.yaml -o petstore_api
space_gen writes a full Dart package into petstore_api/, including:
lib/api/default_api.dart— aDefaultApiclass withlistPets()andgetPet()methods.lib/models/pet.dartandlib/models/pet_status.dart— immutable model classes withfromJson/toJsonand a real Dart enum.lib/api_client.dart,lib/api_exception.dart— the shared runtime.lib/api.dart— a barrel that re-exports the APIs, models, and runtime for consumers.test/models/— round-trip tests for each model.pubspec.yaml,analysis_options.yaml— ready todart pub get.
Using the generated client #
import 'package:petstore_api/api.dart';
Future<void> main() async {
final api = DefaultApi(ApiClient());
final pets = await api.listPets();
for (final pet in pets) {
print('${pet.id}: ${pet.name} (${pet.status.name})');
}
}
See the top-level README for the full list of supported OpenAPI features and configuration flags.