Browse Source

dynamite: Fix docs generation

pull/191/head
jld3103 2 years ago
parent
commit
e66782102a
No known key found for this signature in database
GPG Key ID: 9062417B9E8EB7B3
  1. 34
      packages/dynamite/lib/src/openapi_builder.dart

34
packages/dynamite/lib/src/openapi_builder.dart

@ -552,15 +552,11 @@ class OpenAPIBuilder implements Builder {
..name = methodName ..name = methodName
..modifier = MethodModifier.async ..modifier = MethodModifier.async
..docs.addAll([ ..docs.addAll([
if (operation.summary != null) ...[ ..._descriptionToDocs(operation.summary),
operation.summary!,
],
if (operation.summary != null && operation.description != null) ...[ if (operation.summary != null && operation.description != null) ...[
'', '',
], ],
if (operation.description != null) ...[ ..._descriptionToDocs(operation.description),
operation.description!,
],
]); ]);
final code = StringBuffer(''' final code = StringBuffer('''
@ -1047,6 +1043,14 @@ bool _isParameterNullable(final bool? required, final dynamic default_) => !(req
String _valueToEscapedValue(final String type, final dynamic value) => type == 'String' ? "'$value'" : value.toString(); String _valueToEscapedValue(final String type, final dynamic value) => type == 'String' ? "'$value'" : value.toString();
List<String> _descriptionToDocs(final String? description) => [
if (description != null && description.isNotEmpty) ...[
for (final line in description.split('\n')) ...[
'/// $line',
],
],
];
class State { class State {
State(this.prefix); State(this.prefix);
@ -1073,11 +1077,7 @@ TypeResult resolveObject(
(final b) { (final b) {
b b
..name = '${state.prefix}$identifier' ..name = '${state.prefix}$identifier'
..docs.addAll([ ..docs.addAll(_descriptionToDocs(schema.description))
if (schema.description != null && schema.description!.isNotEmpty) ...[
'/// ${schema.description!}',
],
])
..annotations.add( ..annotations.add(
refer('JsonSerializable').call( refer('JsonSerializable').call(
[], [],
@ -1199,11 +1199,7 @@ TypeResult resolveObject(
), ),
) )
..modifier = FieldModifier.final$ ..modifier = FieldModifier.final$
..docs.addAll([ ..docs.addAll(_descriptionToDocs(propertySchema.description));
if (propertySchema.description != null && propertySchema.description!.isNotEmpty) ...[
'/// ${propertySchema.description!}',
],
]);
final hasDifferentName = _toDartName(propertyName) != propertyName; final hasDifferentName = _toDartName(propertyName) != propertyName;
final isContentString = propertySchema.isContentString; final isContentString = propertySchema.isContentString;
final isContentStringArray = isContentString && result is TypeResultList; final isContentStringArray = isContentString && result is TypeResultList;
@ -1357,11 +1353,7 @@ TypeResult resolveType(
..name = fields[result.name] ..name = fields[result.name]
..type = refer(_makeNullable(result.name, true)) ..type = refer(_makeNullable(result.name, true))
..modifier = FieldModifier.final$ ..modifier = FieldModifier.final$
..docs.addAll([ ..docs.addAll(_descriptionToDocs(s.description));
if (s.description != null && s.description!.isNotEmpty) ...[
'/// ${s.description!}',
],
]);
}, },
), ),
], ],

Loading…
Cancel
Save