diff --git a/packages/dynamite/lib/dynamite.dart b/packages/dynamite/lib/dynamite.dart index a030c8e1..c678ebf1 100644 --- a/packages/dynamite/lib/dynamite.dart +++ b/packages/dynamite/lib/dynamite.dart @@ -9,7 +9,6 @@ import 'package:dynamite/src/models/open_api.dart'; import 'package:dynamite/src/models/parameter.dart' as spec_parameter; import 'package:dynamite/src/models/path_item.dart'; import 'package:dynamite/src/models/schema.dart'; -import 'package:dynamite/src/models/tag.dart'; import 'package:path/path.dart' as p; part 'src/openapi_builder.dart'; diff --git a/packages/dynamite/lib/src/openapi_builder.dart b/packages/dynamite/lib/src/openapi_builder.dart index a2185a2b..fe22beca 100644 --- a/packages/dynamite/lib/src/openapi_builder.dart +++ b/packages/dynamite/lib/src/openapi_builder.dart @@ -28,12 +28,18 @@ class OpenAPIBuilder implements Builder { throw Exception('Only OpenAPI ${supportedVersions.join(', ')} are supported'); } - final tags = [ + final tags = { null, - if (spec.tags != null) ...[ - ...spec.tags!, - ], - ]; + if (spec.paths != null) ...{ + for (final pathItem in spec.paths!.values) ...{ + for (final operation in pathItem.operations.values) ...{ + if (operation.tags != null) ...{ + ...operation.tags!, + }, + }, + }, + }, + }; final hasAnySecurity = spec.security?.isNotEmpty ?? false; final state = State(prefix); @@ -321,7 +327,7 @@ class OpenAPIBuilder implements Builder { final pathItem = spec.paths![path]!; for (final method in pathItem.operations.keys) { final operation = pathItem.operations[method]!; - if ((tag != null && operation.tags != null && operation.tags!.contains(tag.name)) || + if ((tag != null && operation.tags != null && operation.tags!.contains(tag)) || (tag == null && (operation.tags == null || operation.tags!.isEmpty))) { if (paths[path] == null) { paths[path] = PathItem( @@ -441,10 +447,10 @@ class OpenAPIBuilder implements Builder { ) ..methods.addAll([ if (isRootClient) ...[ - for (final tag in tags.where((final tag) => tag != null).toList().cast()) ...[ + for (final tag in tags.where((final tag) => tag != null).toList().cast()) ...[ Method( (final b) => b - ..name = _toDartName(tag.name) + ..name = _toDartName(tag) ..lambda = true ..type = MethodType.getter ..returns = refer('$prefix${_clientName(tag)}') @@ -744,7 +750,7 @@ class OpenAPIBuilder implements Builder { String? headersValue; if (response.headers != null) { final identifier = - '${tag != null ? _toDartName(tag.name, uppercaseFirstCharacter: true) : null}${_toDartName(operationId, uppercaseFirstCharacter: true)}Headers'; + '${tag != null ? _toDartName(tag, uppercaseFirstCharacter: true) : null}${_toDartName(operationId, uppercaseFirstCharacter: true)}Headers'; final headerParseFunctions = {}; for (final headerName in response.headers!.keys) { final functionIdentifier = '_${_toDartName('${identifier}Parse$headerName')}'; @@ -951,7 +957,7 @@ class OpenAPIBuilder implements Builder { } } -String _clientName(final Tag tag) => '${_toDartName(tag.name, uppercaseFirstCharacter: true)}Client'; +String _clientName(final String tag) => '${_toDartName(tag, uppercaseFirstCharacter: true)}Client'; String _toDartName( final String input, { diff --git a/packages/nextcloud/lib/src/nextcloud.openapi.json b/packages/nextcloud/lib/src/nextcloud.openapi.json index 177e7066..14c2caaf 100644 --- a/packages/nextcloud/lib/src/nextcloud.openapi.json +++ b/packages/nextcloud/lib/src/nextcloud.openapi.json @@ -27,26 +27,6 @@ "basic_auth": [] } ], - "tags": [ - { - "name": "core" - }, - { - "name": "news" - }, - { - "name": "notes" - }, - { - "name": "notifications" - }, - { - "name": "provisioning_api" - }, - { - "name": "user_status" - } - ], "components": { "schemas": { "OCSMeta": { diff --git a/packages/spec_templates/bin/generate.dart b/packages/spec_templates/bin/generate.dart index 505469b8..dee3482c 100644 --- a/packages/spec_templates/bin/generate.dart +++ b/packages/spec_templates/bin/generate.dart @@ -314,7 +314,6 @@ Future main(final List args) async { identifier: spdxIdentifier, ), ), - tags: [id], paths: paths, ).toMap(), ), diff --git a/packages/spec_templates/lib/openapi_spec.dart b/packages/spec_templates/lib/openapi_spec.dart index 5b6f07ff..e7b811f9 100644 --- a/packages/spec_templates/lib/openapi_spec.dart +++ b/packages/spec_templates/lib/openapi_spec.dart @@ -4,21 +4,25 @@ class Spec { Spec({ required this.version, required this.info, - required this.tags, - required this.paths, + this.tags, + this.paths, }); Map toMap() => { 'openapi': version, 'info': info.toMap(), - 'tags': tags.map((final tag) => {'name': tag}).toList(), - 'paths': paths.map((final key, final value) => MapEntry(key, value.toMap())), + if (tags != null) ...{ + 'tags': tags!.map((final tag) => {'name': tag}).toList(), + }, + if (paths != null) ...{ + 'paths': paths!.map((final key, final value) => MapEntry(key, value.toMap())), + }, }; final String version; final Info info; - final List tags; - final Map paths; + final List? tags; + final Map? paths; } class Info { diff --git a/specs/core.json b/specs/core.json index 79164db8..ecdda486 100644 --- a/specs/core.json +++ b/specs/core.json @@ -27,11 +27,6 @@ "basic_auth": [] } ], - "tags": [ - { - "name": "core" - } - ], "components": { "schemas": { "OCSMeta": { diff --git a/specs/news.json b/specs/news.json index 990afdc1..6debec4c 100644 --- a/specs/news.json +++ b/specs/news.json @@ -27,11 +27,6 @@ "basic_auth": [] } ], - "tags": [ - { - "name": "news" - } - ], "components": { "schemas": { "OCSMeta": { diff --git a/specs/notes.json b/specs/notes.json index 43e1c9ab..81e1561f 100644 --- a/specs/notes.json +++ b/specs/notes.json @@ -27,11 +27,6 @@ "basic_auth": [] } ], - "tags": [ - { - "name": "notes" - } - ], "components": { "schemas": { "OCSMeta": { diff --git a/specs/notifications.json b/specs/notifications.json index 08b818fe..592d03c3 100644 --- a/specs/notifications.json +++ b/specs/notifications.json @@ -27,11 +27,6 @@ "basic_auth": [] } ], - "tags": [ - { - "name": "notifications" - } - ], "components": { "schemas": { "OCSMeta": { diff --git a/specs/provisioning_api.json b/specs/provisioning_api.json index 83a0458d..4787a7ce 100644 --- a/specs/provisioning_api.json +++ b/specs/provisioning_api.json @@ -27,11 +27,6 @@ "basic_auth": [] } ], - "tags": [ - { - "name": "provisioning_api" - } - ], "components": { "schemas": { "OCSMeta": { diff --git a/specs/templates/core.json b/specs/templates/core.json index 765157f3..295da1af 100644 --- a/specs/templates/core.json +++ b/specs/templates/core.json @@ -9,11 +9,6 @@ "identifier": "AGPL-3.0" } }, - "tags": [ - { - "name": "core" - } - ], "paths": { "/core/lostpassword/email": { "post": { diff --git a/specs/templates/news.json b/specs/templates/news.json index 5868cb4c..72b1cc4a 100644 --- a/specs/templates/news.json +++ b/specs/templates/news.json @@ -9,11 +9,6 @@ "identifier": "AGPL-3.0" } }, - "tags": [ - { - "name": "news" - } - ], "paths": { "/apps/news/folders": { "get": { diff --git a/specs/templates/notes.json b/specs/templates/notes.json index 96e2a0c7..c6175b7d 100644 --- a/specs/templates/notes.json +++ b/specs/templates/notes.json @@ -9,11 +9,6 @@ "identifier": "AGPL-3.0" } }, - "tags": [ - { - "name": "notes" - } - ], "paths": { "/apps/notes/notes": { "get": { diff --git a/specs/templates/notifications.json b/specs/templates/notifications.json index 14ea2a37..25a03f66 100644 --- a/specs/templates/notifications.json +++ b/specs/templates/notifications.json @@ -9,11 +9,6 @@ "identifier": "AGPL-3.0" } }, - "tags": [ - { - "name": "notifications" - } - ], "paths": { "/ocs/v2.php/apps/notifications/api/{apiVersion}/notifications": { "parameters": [ diff --git a/specs/templates/provisioning_api.json b/specs/templates/provisioning_api.json index f9b69771..731538a4 100644 --- a/specs/templates/provisioning_api.json +++ b/specs/templates/provisioning_api.json @@ -9,11 +9,6 @@ "identifier": "AGPL-3.0" } }, - "tags": [ - { - "name": "provisioning_api" - } - ], "paths": { "/ocs/v2.php/apps/provisioning_api/apps": { "get": { diff --git a/specs/templates/user_status.json b/specs/templates/user_status.json index f79aff79..233c6705 100644 --- a/specs/templates/user_status.json +++ b/specs/templates/user_status.json @@ -9,11 +9,6 @@ "identifier": "AGPL-3.0" } }, - "tags": [ - { - "name": "user_status" - } - ], "paths": { "/ocs/v2.php/apps/user_status/api/v1/statuses": { "get": { diff --git a/specs/user_status.json b/specs/user_status.json index 9a4f0caa..d9b43311 100644 --- a/specs/user_status.json +++ b/specs/user_status.json @@ -27,11 +27,6 @@ "basic_auth": [] } ], - "tags": [ - { - "name": "user_status" - } - ], "components": { "schemas": { "OCSMeta": { diff --git a/tool/generate-nextcloud.sh b/tool/generate-nextcloud.sh index 71bec3f6..6a3a664b 100755 --- a/tool/generate-nextcloud.sh +++ b/tool/generate-nextcloud.sh @@ -33,7 +33,6 @@ for i in $(seq 0 $((${#codenames[@]} - 1))); do info: .[0].info, servers: .[0].servers, security: .[0].security, - tags: (.[0].tags + .[1].tags), components: (.[0].components * .[1].components), paths: (.[0].paths * .[1].paths), }' \ @@ -51,7 +50,6 @@ jq \ info: .info, servers: .servers, security: .security, - tags: .tags, components: .components, paths: .paths, } diff --git a/tool/generate-specs.sh b/tool/generate-specs.sh index 8bb634eb..f5255189 100755 --- a/tool/generate-specs.sh +++ b/tool/generate-specs.sh @@ -56,7 +56,6 @@ for codename in ${codenames[*]}; do basic_auth: [] } ], - tags: .[1].tags, components: { schemas: .[1].components.schemas },