Add support for "topics" field (dart-lang/pubspec_parse#93)
diff --git a/pkgs/pubspec_parse/CHANGELOG.md b/pkgs/pubspec_parse/CHANGELOG.md
index 5cf26e0..023e2a1 100644
--- a/pkgs/pubspec_parse/CHANGELOG.md
+++ b/pkgs/pubspec_parse/CHANGELOG.md
@@ -1,7 +1,8 @@
-## 1.2.2-dev
+## 1.2.2
- Require Dart SDK >= 2.18.0
- Required `json_annotation: ^4.8.0`
+- Added support for `topics` field.
## 1.2.1
diff --git a/pkgs/pubspec_parse/lib/src/pubspec.dart b/pkgs/pubspec_parse/lib/src/pubspec.dart
index 9943da8..188af31 100644
--- a/pkgs/pubspec_parse/lib/src/pubspec.dart
+++ b/pkgs/pubspec_parse/lib/src/pubspec.dart
@@ -44,6 +44,9 @@
/// support or funding.
final List<Uri>? funding;
+ /// Optional field to list the topics that this packages belongs to.
+ final List<String>? topics;
+
/// Optional field for specifying included screenshot files.
@JsonKey(fromJson: parseScreenshots)
final List<Screenshot>? screenshots;
@@ -106,6 +109,7 @@
this.repository,
this.issueTracker,
this.funding,
+ this.topics,
this.screenshots,
this.documentation,
this.description,
diff --git a/pkgs/pubspec_parse/lib/src/pubspec.g.dart b/pkgs/pubspec_parse/lib/src/pubspec.g.dart
index a1312a5..6229994 100644
--- a/pkgs/pubspec_parse/lib/src/pubspec.g.dart
+++ b/pkgs/pubspec_parse/lib/src/pubspec.g.dart
@@ -32,6 +32,8 @@
(v) => (v as List<dynamic>?)
?.map((e) => Uri.parse(e as String))
.toList()),
+ topics: $checkedConvert('topics',
+ (v) => (v as List<dynamic>?)?.map((e) => e as String).toList()),
screenshots: $checkedConvert(
'screenshots', (v) => parseScreenshots(v as List?)),
documentation: $checkedConvert('documentation', (v) => v as String?),
diff --git a/pkgs/pubspec_parse/pubspec.yaml b/pkgs/pubspec_parse/pubspec.yaml
index 9614044..6374263 100644
--- a/pkgs/pubspec_parse/pubspec.yaml
+++ b/pkgs/pubspec_parse/pubspec.yaml
@@ -2,7 +2,7 @@
description: >-
Simple package for parsing pubspec.yaml files with a type-safe API and rich
error reporting.
-version: 1.2.2-dev
+version: 1.2.2
repository: https://github.com/dart-lang/pubspec_parse
environment:
diff --git a/pkgs/pubspec_parse/test/parse_test.dart b/pkgs/pubspec_parse/test/parse_test.dart
index f3b4679..e181ca6 100644
--- a/pkgs/pubspec_parse/test/parse_test.dart
+++ b/pkgs/pubspec_parse/test/parse_test.dart
@@ -53,6 +53,7 @@
'funding': [
'https://patreon.com/example',
],
+ 'topics': ['widget', 'button'],
'screenshots': [
{'description': 'my screenshot', 'path': 'path/to/screenshot'}
],
@@ -77,6 +78,9 @@
);
expect(value.funding, hasLength(1));
expect(value.funding!.single.toString(), 'https://patreon.com/example');
+ expect(value.topics, hasLength(2));
+ expect(value.topics!.first, 'widget');
+ expect(value.topics!.last, 'button');
expect(value.screenshots, hasLength(1));
expect(value.screenshots!.first.description, 'my screenshot');
expect(value.screenshots!.first.path, 'path/to/screenshot');
@@ -386,6 +390,42 @@
);
});
});
+ group('topics', () {
+ test('not a list', () {
+ expectParseThrowsContaining(
+ {
+ ...defaultPubspec,
+ 'topics': 1,
+ },
+ "Unsupported value for \"topics\". type 'int' is not a subtype of type 'List<dynamic>?'",
+ skipTryPub: true,
+ );
+ });
+
+ test('not a string', () {
+ expectParseThrowsContaining(
+ {
+ ...defaultPubspec,
+ 'topics': [1],
+ },
+ "Unsupported value for \"topics\". type 'int' is not a subtype of type 'String'",
+ skipTryPub: true,
+ );
+ });
+
+ test('invalid data - lenient', () {
+ final value = parse(
+ {
+ ...defaultPubspec,
+ 'topics': [1],
+ },
+ skipTryPub: true,
+ lenient: true,
+ );
+ expect(value.name, 'sample');
+ expect(value.topics, isNull);
+ });
+ });
group('screenshots', () {
test('one screenshot', () {