schema2dart 1.0.0 copy "schema2dart: ^1.0.0" to clipboard
schema2dart: ^1.0.0 copied to clipboard

Generate strongly typed Dart models from JSON Schema documents.

example/schema2dart_example.dart

// Example of using schema2dart's standalone API
// Run with: dart run example.dart

import 'package:schema2dart/schema2dart.dart';

void main() {
  print('=== schema2dart Standalone API Example ===\n');

  basicExample();
}

void basicExample() {
  print('Example: Basic Code Generation\n');

  final schema = {
    'type': 'object',
    'title': 'Person',
    'properties': {
      'name': {'type': 'string'},
      'age': {'type': 'integer', 'minimum': 0},
    },
    'required': ['name'],
  };

  final options = SchemaGeneratorOptions(
    rootClassName: 'Person',
    emitDocumentation: true,
    emitValidationHelpers: true,
  );

  // Generate code from schema
  final generator = SchemaGenerator(options: options);
  final code = generator.generate(schema);

  print('Generated ${code.split('\n').length} lines of Dart code\n');
  print('Output preview:\n');
  print(code);
}
3
likes
150
points
90
downloads

Publisher

unverified uploader

Weekly Downloads

Generate strongly typed Dart models from JSON Schema documents.

Repository (GitHub)
View/report issues

Topics

#json-schema #codegen #build-runner #validation #schema

Documentation

API reference

Funding

Consider supporting this project:

buymeacoffee.com

License

MIT (license)

Dependencies

build, collection, glob, meta, path

More

Packages that depend on schema2dart