Browse Source

Merge pull request #202 from provokateurin/fix/tags

Fix tags
pull/203/head
Kate 2 years ago committed by GitHub
parent
commit
f6ce6ea70c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      packages/dynamite/lib/dynamite.dart
  2. 26
      packages/dynamite/lib/src/openapi_builder.dart
  3. 20
      packages/nextcloud/lib/src/nextcloud.openapi.json
  4. 1
      packages/spec_templates/bin/generate.dart
  5. 16
      packages/spec_templates/lib/openapi_spec.dart
  6. 5
      specs/core.json
  7. 5
      specs/news.json
  8. 5
      specs/notes.json
  9. 5
      specs/notifications.json
  10. 5
      specs/provisioning_api.json
  11. 5
      specs/templates/core.json
  12. 5
      specs/templates/news.json
  13. 5
      specs/templates/notes.json
  14. 5
      specs/templates/notifications.json
  15. 5
      specs/templates/provisioning_api.json
  16. 5
      specs/templates/user_status.json
  17. 5
      specs/user_status.json
  18. 2
      tool/generate-nextcloud.sh
  19. 1
      tool/generate-specs.sh

1
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/parameter.dart' as spec_parameter;
import 'package:dynamite/src/models/path_item.dart'; import 'package:dynamite/src/models/path_item.dart';
import 'package:dynamite/src/models/schema.dart'; import 'package:dynamite/src/models/schema.dart';
import 'package:dynamite/src/models/tag.dart';
import 'package:path/path.dart' as p; import 'package:path/path.dart' as p;
part 'src/openapi_builder.dart'; part 'src/openapi_builder.dart';

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

@ -28,12 +28,18 @@ class OpenAPIBuilder implements Builder {
throw Exception('Only OpenAPI ${supportedVersions.join(', ')} are supported'); throw Exception('Only OpenAPI ${supportedVersions.join(', ')} are supported');
} }
final tags = <Tag?>[ final tags = <String?>{
null, null,
if (spec.tags != null) ...[ if (spec.paths != null) ...{
...spec.tags!, 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 hasAnySecurity = spec.security?.isNotEmpty ?? false;
final state = State(prefix); final state = State(prefix);
@ -321,7 +327,7 @@ class OpenAPIBuilder implements Builder {
final pathItem = spec.paths![path]!; final pathItem = spec.paths![path]!;
for (final method in pathItem.operations.keys) { for (final method in pathItem.operations.keys) {
final operation = pathItem.operations[method]!; 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))) { (tag == null && (operation.tags == null || operation.tags!.isEmpty))) {
if (paths[path] == null) { if (paths[path] == null) {
paths[path] = PathItem( paths[path] = PathItem(
@ -441,10 +447,10 @@ class OpenAPIBuilder implements Builder {
) )
..methods.addAll([ ..methods.addAll([
if (isRootClient) ...[ if (isRootClient) ...[
for (final tag in tags.where((final tag) => tag != null).toList().cast<Tag>()) ...[ for (final tag in tags.where((final tag) => tag != null).toList().cast<String>()) ...[
Method( Method(
(final b) => b (final b) => b
..name = _toDartName(tag.name) ..name = _toDartName(tag)
..lambda = true ..lambda = true
..type = MethodType.getter ..type = MethodType.getter
..returns = refer('$prefix${_clientName(tag)}') ..returns = refer('$prefix${_clientName(tag)}')
@ -744,7 +750,7 @@ class OpenAPIBuilder implements Builder {
String? headersValue; String? headersValue;
if (response.headers != null) { if (response.headers != null) {
final identifier = 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 = <String, String>{}; final headerParseFunctions = <String, String>{};
for (final headerName in response.headers!.keys) { for (final headerName in response.headers!.keys) {
final functionIdentifier = '_${_toDartName('${identifier}Parse$headerName')}'; 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( String _toDartName(
final String input, { final String input, {

20
packages/nextcloud/lib/src/nextcloud.openapi.json

@ -27,26 +27,6 @@
"basic_auth": [] "basic_auth": []
} }
], ],
"tags": [
{
"name": "core"
},
{
"name": "news"
},
{
"name": "notes"
},
{
"name": "notifications"
},
{
"name": "provisioning_api"
},
{
"name": "user_status"
}
],
"components": { "components": {
"schemas": { "schemas": {
"OCSMeta": { "OCSMeta": {

1
packages/spec_templates/bin/generate.dart

@ -314,7 +314,6 @@ Future main(final List<String> args) async {
identifier: spdxIdentifier, identifier: spdxIdentifier,
), ),
), ),
tags: [id],
paths: paths, paths: paths,
).toMap(), ).toMap(),
), ),

16
packages/spec_templates/lib/openapi_spec.dart

@ -4,21 +4,25 @@ class Spec {
Spec({ Spec({
required this.version, required this.version,
required this.info, required this.info,
required this.tags, this.tags,
required this.paths, this.paths,
}); });
Map<String, dynamic> toMap() => { Map<String, dynamic> toMap() => {
'openapi': version, 'openapi': version,
'info': info.toMap(), 'info': info.toMap(),
'tags': tags.map((final tag) => <String, String>{'name': tag}).toList(), if (tags != null) ...{
'paths': paths.map((final key, final value) => MapEntry(key, value.toMap())), 'tags': tags!.map((final tag) => <String, String>{'name': tag}).toList(),
},
if (paths != null) ...{
'paths': paths!.map((final key, final value) => MapEntry(key, value.toMap())),
},
}; };
final String version; final String version;
final Info info; final Info info;
final List<String> tags; final List<String>? tags;
final Map<String, Path> paths; final Map<String, Path>? paths;
} }
class Info { class Info {

5
specs/core.json

@ -27,11 +27,6 @@
"basic_auth": [] "basic_auth": []
} }
], ],
"tags": [
{
"name": "core"
}
],
"components": { "components": {
"schemas": { "schemas": {
"OCSMeta": { "OCSMeta": {

5
specs/news.json

@ -27,11 +27,6 @@
"basic_auth": [] "basic_auth": []
} }
], ],
"tags": [
{
"name": "news"
}
],
"components": { "components": {
"schemas": { "schemas": {
"OCSMeta": { "OCSMeta": {

5
specs/notes.json

@ -27,11 +27,6 @@
"basic_auth": [] "basic_auth": []
} }
], ],
"tags": [
{
"name": "notes"
}
],
"components": { "components": {
"schemas": { "schemas": {
"OCSMeta": { "OCSMeta": {

5
specs/notifications.json

@ -27,11 +27,6 @@
"basic_auth": [] "basic_auth": []
} }
], ],
"tags": [
{
"name": "notifications"
}
],
"components": { "components": {
"schemas": { "schemas": {
"OCSMeta": { "OCSMeta": {

5
specs/provisioning_api.json

@ -27,11 +27,6 @@
"basic_auth": [] "basic_auth": []
} }
], ],
"tags": [
{
"name": "provisioning_api"
}
],
"components": { "components": {
"schemas": { "schemas": {
"OCSMeta": { "OCSMeta": {

5
specs/templates/core.json

@ -9,11 +9,6 @@
"identifier": "AGPL-3.0" "identifier": "AGPL-3.0"
} }
}, },
"tags": [
{
"name": "core"
}
],
"paths": { "paths": {
"/core/lostpassword/email": { "/core/lostpassword/email": {
"post": { "post": {

5
specs/templates/news.json

@ -9,11 +9,6 @@
"identifier": "AGPL-3.0" "identifier": "AGPL-3.0"
} }
}, },
"tags": [
{
"name": "news"
}
],
"paths": { "paths": {
"/apps/news/folders": { "/apps/news/folders": {
"get": { "get": {

5
specs/templates/notes.json

@ -9,11 +9,6 @@
"identifier": "AGPL-3.0" "identifier": "AGPL-3.0"
} }
}, },
"tags": [
{
"name": "notes"
}
],
"paths": { "paths": {
"/apps/notes/notes": { "/apps/notes/notes": {
"get": { "get": {

5
specs/templates/notifications.json

@ -9,11 +9,6 @@
"identifier": "AGPL-3.0" "identifier": "AGPL-3.0"
} }
}, },
"tags": [
{
"name": "notifications"
}
],
"paths": { "paths": {
"/ocs/v2.php/apps/notifications/api/{apiVersion}/notifications": { "/ocs/v2.php/apps/notifications/api/{apiVersion}/notifications": {
"parameters": [ "parameters": [

5
specs/templates/provisioning_api.json

@ -9,11 +9,6 @@
"identifier": "AGPL-3.0" "identifier": "AGPL-3.0"
} }
}, },
"tags": [
{
"name": "provisioning_api"
}
],
"paths": { "paths": {
"/ocs/v2.php/apps/provisioning_api/apps": { "/ocs/v2.php/apps/provisioning_api/apps": {
"get": { "get": {

5
specs/templates/user_status.json

@ -9,11 +9,6 @@
"identifier": "AGPL-3.0" "identifier": "AGPL-3.0"
} }
}, },
"tags": [
{
"name": "user_status"
}
],
"paths": { "paths": {
"/ocs/v2.php/apps/user_status/api/v1/statuses": { "/ocs/v2.php/apps/user_status/api/v1/statuses": {
"get": { "get": {

5
specs/user_status.json

@ -27,11 +27,6 @@
"basic_auth": [] "basic_auth": []
} }
], ],
"tags": [
{
"name": "user_status"
}
],
"components": { "components": {
"schemas": { "schemas": {
"OCSMeta": { "OCSMeta": {

2
tool/generate-nextcloud.sh

@ -33,7 +33,6 @@ for i in $(seq 0 $((${#codenames[@]} - 1))); do
info: .[0].info, info: .[0].info,
servers: .[0].servers, servers: .[0].servers,
security: .[0].security, security: .[0].security,
tags: (.[0].tags + .[1].tags),
components: (.[0].components * .[1].components), components: (.[0].components * .[1].components),
paths: (.[0].paths * .[1].paths), paths: (.[0].paths * .[1].paths),
}' \ }' \
@ -51,7 +50,6 @@ jq \
info: .info, info: .info,
servers: .servers, servers: .servers,
security: .security, security: .security,
tags: .tags,
components: .components, components: .components,
paths: .paths, paths: .paths,
} }

1
tool/generate-specs.sh

@ -56,7 +56,6 @@ for codename in ${codenames[*]}; do
basic_auth: [] basic_auth: []
} }
], ],
tags: .[1].tags,
components: { components: {
schemas: .[1].components.schemas schemas: .[1].components.schemas
}, },

Loading…
Cancel
Save