Browse Source

dynamite: Support nested tags

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

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

@ -28,7 +28,7 @@ class OpenAPIBuilder implements Builder {
throw Exception('Only OpenAPI ${supportedVersions.join(', ')} are supported');
}
final tags = <String?>{
var tags = <String?>[
null,
if (spec.paths != null) ...{
for (final pathItem in spec.paths!.values) ...{
@ -39,7 +39,22 @@ class OpenAPIBuilder implements Builder {
},
},
},
};
];
for (final tag in tags.toList()) {
final tagPart = tag?.split('/').first;
if (!tags.contains(tagPart)) {
tags.add(tagPart);
}
}
tags = tags
..sort(
(final a, final b) => a == null
? -1
: b == null
? 1
: a.compareTo(b),
);
final hasAnySecurity = spec.security?.isNotEmpty ?? false;
final state = State(prefix);
@ -341,10 +356,6 @@ class OpenAPIBuilder implements Builder {
}
}
if (paths.isEmpty && !isRootClient) {
continue;
}
output.add(
Class(
(final b) {
@ -446,18 +457,6 @@ class OpenAPIBuilder implements Builder {
),
)
..methods.addAll([
if (isRootClient) ...[
for (final tag in tags.where((final tag) => tag != null).toList().cast<String>()) ...[
Method(
(final b) => b
..name = _toDartName(tag)
..lambda = true
..type = MethodType.getter
..returns = refer('$prefix${_clientName(tag)}')
..body = Code('$prefix${_clientName(tag)}(this)'),
),
],
],
Method(
(final b) => b
..name = 'doRequest'
@ -546,6 +545,21 @@ class OpenAPIBuilder implements Builder {
)
..methods.addAll(
[
for (final t in tags
.whereType<String>()
.where(
(final t) => (tag != null && (t.startsWith('$tag/'))) || (tag == null && !t.contains('/')),
)
.toList()) ...[
Method(
(final b) => b
..name = _toDartName(tag == null ? t : t.substring('$tag/'.length))
..lambda = true
..type = MethodType.getter
..returns = refer('$prefix${_clientName(t)}')
..body = Code('$prefix${_clientName(t)}(${isRootClient ? 'this' : 'rootClient'})'),
),
],
for (final path in paths.keys) ...[
for (final httpMethod in paths[path]!.operations.keys) ...[
Method(

Loading…
Cancel
Save