diff --git a/catalyst_voices/packages/internal/catalyst_voices_repositories/lib/src/dto/document/schema/document_property_schema_dto.dart b/catalyst_voices/packages/internal/catalyst_voices_repositories/lib/src/dto/document/schema/document_property_schema_dto.dart index 85d86686f68..cab42d22f36 100644 --- a/catalyst_voices/packages/internal/catalyst_voices_repositories/lib/src/dto/document/schema/document_property_schema_dto.dart +++ b/catalyst_voices/packages/internal/catalyst_voices_repositories/lib/src/dto/document/schema/document_property_schema_dto.dart @@ -51,28 +51,28 @@ final class DocumentPropertySchemaDto { final List? order; const DocumentPropertySchemaDto({ - this.ref, - this.types, - this.format, - this.contentMediaType, - this.title, - this.description, - this.defaultValue, - this.guidance, - this.constValue, - this.enumValues, - this.properties, - this.items, - this.minimum, - this.maximum, - this.minLength, - this.maxLength, - this.maxItems, - this.minItems, - this.oneOf, - this.required, - this.order, - this.pattern, + required this.ref, + required this.types, + required this.format, + required this.contentMediaType, + required this.title, + required this.description, + required this.defaultValue, + required this.guidance, + required this.constValue, + required this.enumValues, + required this.properties, + required this.items, + required this.minimum, + required this.maximum, + required this.minLength, + required this.maxLength, + required this.maxItems, + required this.minItems, + required this.oneOf, + required this.required, + required this.order, + required this.pattern, }); factory DocumentPropertySchemaDto.fromJson(Map json) => @@ -208,6 +208,9 @@ final class DocumentPropertySchemaDto { title: title ?? other.title, description: description ?? other.description, defaultValue: defaultValue ?? other.defaultValue, + guidance: guidance ?? other.guidance, + constValue: constValue ?? other.constValue, + enumValues: enumValues ?? other.enumValues, properties: mergedProperties, items: mergedItems, minimum: minimum ?? other.minimum, diff --git a/catalyst_voices/packages/internal/catalyst_voices_repositories/lib/src/dto/document/schema/document_schema_dto.dart b/catalyst_voices/packages/internal/catalyst_voices_repositories/lib/src/dto/document/schema/document_schema_dto.dart index 7efcc8a2701..be04cd5e308 100644 --- a/catalyst_voices/packages/internal/catalyst_voices_repositories/lib/src/dto/document/schema/document_schema_dto.dart +++ b/catalyst_voices/packages/internal/catalyst_voices_repositories/lib/src/dto/document/schema/document_schema_dto.dart @@ -5,7 +5,7 @@ import 'package:json_annotation/json_annotation.dart'; part 'document_schema_dto.g.dart'; -@JsonSerializable() +@JsonSerializable(includeIfNull: false) final class DocumentSchemaDto { @JsonKey(name: r'$schema') final String schema; @@ -36,6 +36,7 @@ final class DocumentSchemaDto { required this.order, required this.propertiesSchema, }); + factory DocumentSchemaDto.fromJson(Map json) { final segmentsMap = json['properties'] as Map; json['propertiesSchema'] = diff --git a/catalyst_voices/packages/internal/catalyst_voices_repositories/lib/src/dto/document/values/grouped_tags_dto.dart b/catalyst_voices/packages/internal/catalyst_voices_repositories/lib/src/dto/document/values/grouped_tags_dto.dart deleted file mode 100644 index 2b67972eb1c..00000000000 --- a/catalyst_voices/packages/internal/catalyst_voices_repositories/lib/src/dto/document/values/grouped_tags_dto.dart +++ /dev/null @@ -1,57 +0,0 @@ -import 'package:catalyst_voices_models/catalyst_voices_models.dart'; -import 'package:json_annotation/json_annotation.dart'; - -part 'grouped_tags_dto.g.dart'; - -@JsonSerializable() -final class GroupedTagsSelectionDto { - final String? group; - final String? tag; - - const GroupedTagsSelectionDto({ - this.group, - this.tag, - }); - - factory GroupedTagsSelectionDto.fromModel(GroupedTagsSelection tags) { - return GroupedTagsSelectionDto( - group: tags.group, - tag: tags.tag, - ); - } - - factory GroupedTagsSelectionDto.fromJson(Map json) => - _$GroupedTagsSelectionDtoFromJson(json); - - Map toJson() => _$GroupedTagsSelectionDtoToJson(this); - - GroupedTagsSelection toModel() { - return GroupedTagsSelection( - group: group, - tag: tag, - ); - } -} - -class GroupedTagsSelectionConverter - implements JsonConverter?> { - const GroupedTagsSelectionConverter(); - - @override - GroupedTagsSelection? fromJson(Map? json) { - if (json == null) { - return null; - } - - return GroupedTagsSelectionDto.fromJson(json).toModel(); - } - - @override - Map? toJson(GroupedTagsSelection? object) { - if (object == null) { - return null; - } - - return GroupedTagsSelectionDto.fromModel(object).toJson(); - } -} diff --git a/catalyst_voices/packages/internal/catalyst_voices_repositories/test/src/document/schema/document_schema_dto_test.dart b/catalyst_voices/packages/internal/catalyst_voices_repositories/test/src/document/schema/document_schema_dto_test.dart new file mode 100644 index 00000000000..ef41635d018 --- /dev/null +++ b/catalyst_voices/packages/internal/catalyst_voices_repositories/test/src/document/schema/document_schema_dto_test.dart @@ -0,0 +1,32 @@ +import 'dart:convert'; + +import 'package:catalyst_voices_repositories/src/dto/document/schema/document_schema_dto.dart'; +import 'package:test/test.dart'; + +import '../../../helpers/read_json.dart'; + +void main() { + group(DocumentSchemaDto, () { + const schemaPath = + 'test/assets/0ce8ab38-9258-4fbc-a62e-7faa6e58318f.schema.json'; + + late Map schemaJson; + + setUpAll(() { + schemaJson = json.decode(readJson(schemaPath)) as Map; + }); + + test('document schema can be decoded and encoded', () { + final originalSchema = DocumentSchemaDto.fromJson(schemaJson); + final originalModel = originalSchema.toModel(); + expect(originalModel.properties, isNotEmpty); + + final encodedSchema = originalSchema.toJson(); + expect(encodedSchema, isNotEmpty); + + final redecodedSchema = DocumentSchemaDto.fromJson(encodedSchema); + final redecodedModel = redecodedSchema.toModel(); + expect(redecodedModel, equals(originalModel)); + }); + }); +}