dart_swagger_to_models 0.5.2 copy "dart_swagger_to_models: ^0.5.2" to clipboard
dart_swagger_to_models: ^0.5.2 copied to clipboard

Generate null-safe Dart models from Swagger/OpenAPI specs with multiple styles and per-file output.

example/main.dart

import 'dart:io';

import 'package:dart_swagger_to_models/dart_swagger_to_models.dart';

/// Simple example showing how to use the library API directly.
///
/// In real projects you would usually call the CLI, but this demonstrates
/// that the package can be used programmatically as well.
Future<void> main() async {
  // Suppose you have a local OpenAPI/Swagger file `example/swagger/api.yaml`.
  final inputSpec = 'example/dart_example/swagger/api.yaml';

  // Generate models into `example_output/models` directory inside this package.
  final outputDir = 'example_output/models';

  final result = await SwaggerToDartGenerator.generateModels(
    input: inputSpec,
    outputDir: outputDir,
    projectDir: Directory.current.path,
  );

  stdout.writeln('Generated ${result.generatedFiles.length} files:');
  for (final file in result.generatedFiles) {
    stdout.writeln('  - $file');
  }
}
1
likes
150
points
136
downloads
screenshot

Publisher

verified publishergoodwin.website

Weekly Downloads

Generate null-safe Dart models from Swagger/OpenAPI specs with multiple styles and per-file output.

Repository (GitHub)
View/report issues

Topics

#swagger #openapi #codegen #freezed #build-runner

Documentation

API reference

License

MIT (license)

Dependencies

args, build, crypto, http, json_annotation, path, yaml

More

Packages that depend on dart_swagger_to_models