diff --git a/packages/dynamite/lib/src/models/tag.dart b/packages/dynamite/lib/src/models/tag.dart index dfc342b6..3ade793a 100644 --- a/packages/dynamite/lib/src/models/tag.dart +++ b/packages/dynamite/lib/src/models/tag.dart @@ -6,10 +6,13 @@ part 'tag.g.dart'; class Tag { Tag({ required this.name, + this.description, }); factory Tag.fromJson(final Map json) => _$TagFromJson(json); Map toJson() => _$TagToJson(this); final String name; + + final String? description; } diff --git a/packages/dynamite/lib/src/models/tag.g.dart b/packages/dynamite/lib/src/models/tag.g.dart index 5462a11d..c67937f9 100644 --- a/packages/dynamite/lib/src/models/tag.g.dart +++ b/packages/dynamite/lib/src/models/tag.g.dart @@ -9,13 +9,25 @@ part of 'tag.dart'; Tag _$TagFromJson(Map json) { $checkKeys( json, - allowedKeys: const ['name'], + allowedKeys: const ['name', 'description'], ); return Tag( name: json['name'] as String, + description: json['description'] as String?, ); } -Map _$TagToJson(Tag instance) => { - 'name': instance.name, - }; +Map _$TagToJson(Tag instance) { + final val = { + 'name': instance.name, + }; + + void writeNotNull(String key, dynamic value) { + if (value != null) { + val[key] = value; + } + } + + writeNotNull('description', instance.description); + return val; +} diff --git a/packages/dynamite/lib/src/openapi_builder.dart b/packages/dynamite/lib/src/openapi_builder.dart index fe22beca..9127eef3 100644 --- a/packages/dynamite/lib/src/openapi_builder.dart +++ b/packages/dynamite/lib/src/openapi_builder.dart @@ -536,8 +536,14 @@ class OpenAPIBuilder implements Builder { ), ); } + final matchedTags = spec.tags?.where((final t) => t.name == tag).toList(); b ..name = '$prefix${isRootClient ? 'Client' : _clientName(tag)}' + ..docs.addAll( + _descriptionToDocs( + matchedTags != null && matchedTags.isNotEmpty ? matchedTags.single.description : null, + ), + ) ..methods.addAll( [ for (final path in paths.keys) ...[