Browse Source

Merge pull request #203 from provokateurin/feature/tags-descriptions

dynamite: Output tag descriptions
pull/205/head
Kate 2 years ago committed by GitHub
parent
commit
acb9f049c0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      packages/dynamite/lib/src/models/tag.dart
  2. 16
      packages/dynamite/lib/src/models/tag.g.dart
  3. 6
      packages/dynamite/lib/src/openapi_builder.dart

3
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<String, dynamic> json) => _$TagFromJson(json);
Map<String, dynamic> toJson() => _$TagToJson(this);
final String name;
final String? description;
}

16
packages/dynamite/lib/src/models/tag.g.dart

@ -9,13 +9,25 @@ part of 'tag.dart';
Tag _$TagFromJson(Map<String, dynamic> json) {
$checkKeys(
json,
allowedKeys: const ['name'],
allowedKeys: const ['name', 'description'],
);
return Tag(
name: json['name'] as String,
description: json['description'] as String?,
);
}
Map<String, dynamic> _$TagToJson(Tag instance) => <String, dynamic>{
Map<String, dynamic> _$TagToJson(Tag instance) {
final val = <String, dynamic>{
'name': instance.name,
};
void writeNotNull(String key, dynamic value) {
if (value != null) {
val[key] = value;
}
}
writeNotNull('description', instance.description);
return val;
}

6
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) ...[

Loading…
Cancel
Save