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. 20
      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 { class Tag {
Tag({ Tag({
required this.name, required this.name,
this.description,
}); });
factory Tag.fromJson(final Map<String, dynamic> json) => _$TagFromJson(json); factory Tag.fromJson(final Map<String, dynamic> json) => _$TagFromJson(json);
Map<String, dynamic> toJson() => _$TagToJson(this); Map<String, dynamic> toJson() => _$TagToJson(this);
final String name; final String name;
final String? description;
} }

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

@ -9,13 +9,25 @@ part of 'tag.dart';
Tag _$TagFromJson(Map<String, dynamic> json) { Tag _$TagFromJson(Map<String, dynamic> json) {
$checkKeys( $checkKeys(
json, json,
allowedKeys: const ['name'], allowedKeys: const ['name', 'description'],
); );
return Tag( return Tag(
name: json['name'] as String, name: json['name'] as String,
description: json['description'] as String?,
); );
} }
Map<String, dynamic> _$TagToJson(Tag instance) => <String, dynamic>{ Map<String, dynamic> _$TagToJson(Tag instance) {
'name': instance.name, 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 b
..name = '$prefix${isRootClient ? 'Client' : _clientName(tag)}' ..name = '$prefix${isRootClient ? 'Client' : _clientName(tag)}'
..docs.addAll(
_descriptionToDocs(
matchedTags != null && matchedTags.isNotEmpty ? matchedTags.single.description : null,
),
)
..methods.addAll( ..methods.addAll(
[ [
for (final path in paths.keys) ...[ for (final path in paths.keys) ...[

Loading…
Cancel
Save