Code generation for the Dogma libraries
The Dogma Codegen library provides mechanisms to generate source code that interfaces with the Dogma libraries for creating data layers. Using the library is not mandatory, but its usage is recommended as it eliminates the boilerplate code that needs to be written using the libraries.
Dogma Codegen can be used directly to generate source code but it is also leveraged to parse different file formats describing models and full RESTful APIs. Before using Dogma Codegen directly consider using one of those libraries instead as even more code can be automatically generated.
Library | Models | Unmodifiable Views | Convert | Mapper | Fluent Queries |
---|---|---|---|---|---|
Codegen | ❌ | ✔️ | ✔️ | ✔️ | ❌ |
JSON Schema | ✔️ | ✔️ | ✔️ | ✔️ | ❌ |
Swagger | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ |
Dogma Codegen should be installed as a developer dependency. Add the following to the project's pubspec.yaml.
dev_dependencies:
dogma_codegen: ^0.0.1
It can also be installed using den by using the following command
den install dogma_codegen --dev
.
Dogma Codegen is opinionated on the layout of the package. The following showcases the default structure.
+ lib
+ src
+ models
foo.dart
bar.dart
+ convert
foo_convert.dart
bar_convert.dart
models.dart
convert.dart
Dogma Codegen uses a build.dart
file at the root of the package to generate source code. For packages following the
above conventions a working build.dart
looks like.
import 'dart:async';
import 'package:dogma_codegen/build.dart';
Future<Null> main(List<String> args) async {
await build(args);
}
If the layout of the package is different then view the documentation on the build
method and modify the values
accordingly. It is however highly recommended to stick with the prescribed layout.
The build.dart
file can be invoked directly which will cause a full rebuild of the library.
Dogma Codegen supports incremental builds through the build_system library. Any change to the model files will be result in a rebuild when using build_system. See its documentation for the most up to date information on using it. Dogma Codegen will continue to follow the conventions of that library to ensure the built files are up to date with the model definitions.
Working examples of various third-party APIs are available collected at the Dogma Dart APIs Organization. These can be referenced for getting started with the Dogma libraries.
Please file feature requests and bugs at the issue tracker.