From b171de8c2245a58f2685aeaa751cfe49a2e8a88c Mon Sep 17 00:00:00 2001 From: Nikolas Rimikis Date: Sat, 2 Sep 2023 20:32:45 +0200 Subject: [PATCH] refactor(dynamite): cleanup tags handling Signed-off-by: Nikolas Rimikis --- .../dynamite/lib/src/openapi_builder.dart | 44 +++++++++---------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/packages/dynamite/dynamite/lib/src/openapi_builder.dart b/packages/dynamite/dynamite/lib/src/openapi_builder.dart index 702ca640..984a742a 100644 --- a/packages/dynamite/dynamite/lib/src/openapi_builder.dart +++ b/packages/dynamite/dynamite/lib/src/openapi_builder.dart @@ -29,30 +29,30 @@ class OpenAPIBuilder implements Builder { throw Exception('Only OpenAPI ${supportedVersions.join(', ')} are supported'); } - var tags = [ - null, - if (spec.paths != null) ...{ - for (final pathItem in spec.paths!.values) ...{ - for (final operation in pathItem.operations.values) ...{ - ...?operation.tags, - }, - }, - }, - ]; - for (final tag in tags.toList()) { - final tagPart = tag?.split('/').first; - if (!tags.contains(tagPart)) { - tags.add(tagPart); + final tags = [null]; + + if (spec.paths != null) { + for (final pathItem in spec.paths!.values) { + for (final operation in pathItem.operations.values) { + if (operation.tags != null) { + for (final tag in operation.tags!) { + 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), - ); + + tags.sort( + (final a, final b) => a == null + ? -1 + : b == null + ? 1 + : a.compareTo(b), + ); final hasAnySecurity = spec.components?.securitySchemes?.isNotEmpty ?? false;