luthor_generator 1.0.0
luthor_generator: ^1.0.0 copied to clipboard
Generate luthor schemas
1.0.0 #
- BREAKING: Require Dart 3.11 or later (Flutter 3.41 or later).
- FEAT: Support
analyzer10 to 14 (>=10.0.0 <15.0.0), so every Flutter release from 3.41 to current is supported. Flutter 3.41 pinsmeta1.17.0, which resolves analyzer 10.0.x; newer SDKs resolve analyzer 13 or 14. - FEAT: Require
source_gen^4.2.0andbuild^4.0.4. Both ranges resolve with every analyzer from 10 to 14. - FEAT: Depend on
luthor^1.0.0instead of exactly1.0.0, so aluthorpatch or minor release does not need a matchingluthor_generatorrelease. - BREAKING: Generate code for the
luthor1.0 API. Schemas are declared asfinal SchemaValidator $XSchema = l.schema({...}).withName('X');, with the explicit type becauseforwardRefmakes inference circular. Lists usel.list(element),numandboolfields usel.num()andl.bool(), and$XValidateandvalidateSelf()returnValidationResult<X>.$XValidateaccepts any input (Object?), such as decoded JSON. - BREAKING: Enum fields generate
l.oneOf([...])with their serialized values, and enum map keysl.oneOf()with the values as strings. Map keys of typeint,double,numandBigIntgeneratel.string().custom((key) => int.tryParse(key) != null)(or the matching parser), and a key that fails is an invalid key of the map. - BREAKING:
@MatchRegexgenerates.regex(RegExp(r'...'))with itscaseSensitive,multiLine,unicodeanddotAllflags when they are not the default.@IsFile(accept: ...)generatesl.file(accept: ...). Annotations passmessageBuilder:instead ofmessageFn:. - BREAKING:
@HasMinand@HasMaxreplace theDoubleandNumbervariants. A fractional value on anintorStringfield fails generation. - BREAKING: Generated schemas strip unknown keys before
fromJsonruns, like everyluthor1.0 schema. Public settable fields thatjson_serializableassigns after the constructor are now schema fields, so their keys survive. Models whose serializer may read keys that are not fields (a@JsonKey(readValue: ...)field, a private field with@JsonKey(includeFromJson: true), or a@MappableClass(hook: ...)) get.passthrough(), and areadValuefield is validated as an optionall.any(). - BREAKING:
@WithCustomValidatorand@WithSchemaCustomValidatoron aNullfield fail generation, sincel.nullValue()has nocustom(). - BREAKING: Generated
$XSchemavariables arefinal. - BREAKING: Auto-generated schemas, for classes that a model uses but that have no
@luthor, are now private (_$XSchema) and emitted once per library. They no longer get publicSchemaKeys,ErrorKeys,$XValidateorvalidateSelf(). Two libraries that nest the same class no longer clash when imported together. Annotate a class with@luthorto get its public API. - BREAKING: Generation fails with a clear error for
freezedunions (more than one redirecting factory; union dispatch is not supported yet), for generic models and fields of generic types, and for annotations placed on a field type they don't apply to, such as@IsEmailon anintor@HasLengthon aList. These used to generate code that silently skipped validation or did not compile. - BREAKING: Unsupported field types fail with an
InvalidGenerationSourceErrorthat names the class, the field and the type, with advice for the kind of type, instead of anUnsupportedErrorwithout a location. - BREAKING:
validateSelf()is generated only for models with atoJsonmethod (including the onefreezedgenerates) or adart_mappabletoMap.@JsonSerializable(createToJson: false)and@Freezed(toJson: false)are respected. - BREAKING: Fields with a
JsonConverteror a@JsonKey(fromJson: ...)function are validated asl.any(). - BREAKING: Nested schema references are always wrapped in
forwardRef.@luthorForwardRefis still accepted but has no effect, and is deprecated. - BREAKING: Validation annotations are emitted in the order they are written, so
@HasMin(8) @HasMax(200)generates.min(8).max(200). - BREAKING: The generator's internal libraries moved under
lib/src. Onlypackage:luthor_generator/builder.dartandpackage:luthor_generator/luthor_generator.dart, which exports it, are public. - BREAKING:
luthor_generatorno longer depends onjson_annotation,freezed_annotation,dart_mappableorcollection. Serializer annotations are matched by name and package. - FIX: Apply
source_gen:combining_builder, so projects withoutjson_serializableget a.g.dartfile. - FIX: Build the schema from the constructor the serializer uses: the one named in
@JsonSerializable(constructor: ...), the@MappableConstructor, the unnamed constructor, or the first public constructor with parameters. A private orfromJsonconstructor declared first no longer produces an empty or wrong schema. - FIX: Read annotations from fields, including fields reached through
super.parameters, as well as constructor parameters. - FIX: Apply
@JsonSerializable(fieldRename: ...)on the class or thefreezedfactory (#49),@JsonKey(name: ...)on fields,@MappableField(key: ...)and@MappableClass(caseStyle: ...)to schema keys and error keys. - FIX: Treat fields with a constructor default or
@JsonKey(defaultValue: ...)as optional, and leave fields with@JsonKey(includeFromJson: false)out of the schema. - FIX: Validate enums against their serialized values (names,
@JsonValue,@JsonEnum(fieldRename:, valueField:),@MappableEnum,@MappableValue), including in lists and as map keys. - FIX: An enum field with
@JsonKey(unknownEnumValue: ...), or a list of such enums, generatesl.string()(l.int()for integer-valued enums) instead ofl.oneOf([...]), sincejson_serializablemaps unknown values to the fallback. - FIX: Support
SetandIterablelikeList,Urias a string, andObject/Object?asl.any(). - FIX: Add
.dateTime()to nullableDateTimefields and toDateTimevalues inside collections, and give nested maps their key and value validators, so invalid input is a validation error instead of an exception fromfromJson. - FIX: Validate
Mapkeys of typeint,double,numandBigIntas strings that parse to that type, since JSON object keys are always strings. - FIX: Keep import prefixes on nested schemas and custom validator functions, and qualify static methods declared in extensions. A nested
@luthorschema hidden by ashow/hidecombinator gets a private schema instead. - FIX: Recursion through nested collections (
List<List<Node>>,Map<String, List<Node>>) and mutual recursion between models no longer overflow the stack. - FIX:
validateSelf()converts nested objects with theirtoJson()before validating, so it works whenjson_serializable'sexplicitToJsonisfalse. - FIX: Nested model fields in
ErrorKeysget a$keyentry for the field's own error. EveryErrorKeysentry is the flat error path thatgetErrorlooks up, such ashome.street. - FIX: Accept
fromJsongenerative constructors and static methods, not only factories. - FIX: Keep the
messageandmessageBuilderof@IsFile, emitdouble.infinity,double.negativeInfinityanddouble.nanin annotation values, escape$in class names passed towithName, and stop markingNullfields as required. - FIX:
@IsFilegeneratesl.file()whatever the field's declared type, so a field typed as a package class such asMultipartFile, or a list of one, no longer fails generation as "not a luthor model". - FIX: Detect
DateTime,Uri,Fileand serializer annotations by library instead of by display name, so same-named types from other packages are not mistaken for them.
0.18.0 #
- FIX: Escape generated Dart string literals for messages, regexes, JSON keys, and other annotation values so quotes, backslashes, and dollar signs produce valid generated code.
0.17.0 #
- FEAT: Add code generation support for
l.file()validator using the@IsFileannotation.
0.16.0 #
- FEAT: Update
analyzerdependency to^9.0.0.
0.15.0 #
- FEAT: Update
builddependency to^4.0.0. - FEAT: Update
analyzerdependency to^8.0.0. - FEAT: Update
source_gendependency to^4.0.0.
0.14.0 #
-
FEAT: Add code generation support for
Map<K, V>types with automatic key and value validator generation. When a field is typed asMap<String, Comment>, the generator automatically creates validators for both the key type (String) and value type (Comment). -
FEAT: Add automatic
forwardRefdetection for self-referential types. The generator now automatically wraps schema references withforwardRef()when:- The field type directly matches the enclosing class (e.g.,
Comment? parent) - The field type is a generic containing the enclosing class (e.g.,
List<Comment>? replies,Map<String, Comment>? mentions)
This prevents stack overflow errors during schema construction for recursive data structures.
- The field type directly matches the enclosing class (e.g.,
-
FEAT: Add
@luthorForwardRefannotation support for explicit forward references. Use this annotation when you have cross-class circular references (e.g.,UserhasList<Comment>andCommenthasUser) where automatic detection isn't possible, requiring explicit annotation on the constructor parameter. -
FEAT: Add nullable type support for map key and value validators. Nullable types in
Map<K?, V?>correctly omit.required()validation when appropriate. -
FEAT: Add code generation support for
@IsUuid/@isUuid,@IsCuid/@isCuid,@IsCuid2/@isCuid2, and@IsEmoji/@isEmojiannotations. The generator now automatically generates.uuid(),.cuid(),.cuid2(), and.emoji()validation calls respectively when these annotations are used on string fields.
0.13.1 #
- FEAT: Functions passed to annotations now resolve with full qualified names. Before, if you had a function like this:
@WithCustomValidator(MyClass.customValidator)
The generated code would look like this:
.custom(customValidator)
This causes an analysis error because the function is not found. This version fixes this by resolving the function name to the full qualified name. Now, the generated code will look like this:
.custom(MyClass.customValidator)
0.13.0 #
- FEAT: Add
messageFnsupport to all validation annotations, enabling dynamic error message generation in generated schemas through top-level function references.
0.12.0 #
- FEAT: Update dependencies.
0.11.0 #
- FEAT: Add generation of type-safe
SchemaKeysconstants for schema field access with compile-time safety. - FEAT: Add support for
@WithSchemaCustomValidatorannotation to enable cross-field validation in generated schemas. - FEAT: Enhanced
ErrorKeysgeneration with improved nested field support and dot-notation access. - FEAT: Automatic JsonKey integration - SchemaKeys and ErrorKeys respect
@JsonKeyannotations for proper field mapping.
0.10.0 #
- FEAT: Add support for generating type safe error keys.
0.9.0 #
- FIX: Fix nullable DateTime handling in auto-generated schemas. Nullable DateTime fields now properly validate without requiring @luthor annotation.
0.8.0 #
- FEAT: Add auto-generation support for classes without @luthor annotation. Compatible classes (with fromJson constructor or @MappableClass annotation and named parameters) are now automatically discovered and schemas are generated for them when referenced in @luthor classes.
0.7.2 #
- FIX: Add support for nullable types and custom types in list validations. Lists can now contain nullable primitives (e.g.,
List<String?>) and custom objects with@luthorannotations (e.g.,List<MyClass>).
0.7.1 #
Note: This release has breaking changes.
- FIX: failedMessage not set is value is not a Map for SchemaValidation (#108).
0.7.0 #
Note: This release has breaking changes.
- BREAKING FEAT(luthor_generator): Add support for Freezed 3.0 (#106).
0.6.3 #
- FIX: Nullable ? in generated code.
0.5.1 #
- FEAT: Updated dependencies.
0.4.4+1 #
- Update a dependency to the latest release.
0.4.3 #
- FIX(luthor_generator): invalid identifier.
- FEAT(luthor_generator): remove validate method (#78).
- FEAT(luthor_generator): remove need for validate method.
0.4.2 #
- FEAT(luthor_generator): remove need for validate method.
- FEAT: deprecate luthor_annotation (#77).
0.4.0+1 #
0.4.0 #
0.3.2 #
- FEAT: update analyzer.
0.3.1 #
- FEAT(luthor_generator): add support for DateTime.
0.3.0 #
- FEAT(luthor_generator): validate method generates unique methods allowing multiple luthor classes in one file.
0.2.4 #
- FIX: dependencies.
- FIX(luthor): SchemaValidation null error due to covariant.
- FEAT(luthor_generator): Add support for JsonKey.name.
- FEAT(luthor_generator): luthor classes now require a validate method instead of exposing the raw schema.
- FEAT(luthor): add fromJson argument to validateSchema.
0.2.3 #
- FIX: dependencies.
- FIX(luthor): SchemaValidation null error due to covariant.
- FEAT(luthor_generator): luthor classes now require a validate method instead of exposing the raw schema.
- FEAT(luthor): add fromJson argument to validateSchema.
0.2.2 #
- Update
luthor_annotationdependency to^0.2.1
0.2.0 #
- Minimum Dart SDK version is now 3.0.0
- Luthor classes now require a validate method to be defined instead of exposing a
schemavariable. The schema is still globally accessible via$<name_of_class>Schema luthor_generatorwill validate the newvalidatemethod. If it doesn't match, it will give you the code to copy/paste in your class in the error message.
0.1.1+2 #
- Update
luthor_annotationversion in pubspec.yaml
0.1.1+1 #
- Change collect to
^1.17.0to make it compatible with Flutter 3.7
0.1.1 #
- Update README example
0.1.0 #
- [Breaking change]
schemafield is required on class with@luthorannotation - Add support for nested schemas
0.0.1 #
- Initial version.