From 671e1b11174351d68337498e34ffe37872b6e664 Mon Sep 17 00:00:00 2001 From: Nikolas Rimikis Date: Fri, 29 Dec 2023 16:34:26 +0100 Subject: [PATCH] feat(dynamite): document generated libraries and add support for all info fields Signed-off-by: Nikolas Rimikis --- cspell.json | 1 + .../example/lib/petstore.openapi.dart | 17 +- .../lib/src/builder/generate_schemas.dart | 12 +- .../lib/src/builder/resolve_interface.dart | 5 + .../lib/src/builder/resolve_object.dart | 1 + .../dynamite/lib/src/builder/resolve_ofs.dart | 1 + .../dynamite/lib/src/helpers/docs.dart | 2 +- .../dynamite/lib/src/models/openapi.dart | 2 + .../dynamite/lib/src/models/openapi.g.dart | 1 + .../lib/src/models/openapi/contact.dart | 40 ++ .../lib/src/models/openapi/contact.g.dart | 163 +++++++ .../dynamite/lib/src/models/openapi/info.dart | 49 ++ .../lib/src/models/openapi/info.g.dart | 80 +++- .../lib/src/models/openapi/license.dart | 13 + .../dynamite/lib/src/openapi_builder.dart | 8 + packages/dynamite/dynamite/pubspec.yaml | 2 +- .../dynamite_end_to_end_test/build.yaml | 9 + .../lib/all_of.openapi.dart | 8 +- .../lib/any_of.openapi.dart | 3 +- .../lib/authentication.openapi.dart | 3 +- .../lib/documentation.openapi.dart | 448 ++++++++++++++++++ .../lib/documentation.openapi.g.dart | 348 ++++++++++++++ .../lib/documentation.openapi.json | 165 +++++++ .../lib/enum.openapi.dart | 4 +- .../lib/headers.openapi.dart | 4 +- .../lib/interfaces.openapi.dart | 3 +- .../lib/nested_ofs.openapi.dart | 3 +- .../lib/one_of.openapi.dart | 3 +- .../lib/parameters.openapi.dart | 4 +- .../lib/pattern_check.openapi.dart | 3 +- .../lib/request_body.openapi.dart | 4 +- .../lib/responses.openapi.dart | 3 +- .../lib/some_of.openapi.dart | 5 +- .../lib/tags.openapi.dart | 3 +- .../lib/type_defs.openapi.dart | 3 +- .../lib/types.openapi.dart | 4 +- .../lib/src/api/comments.openapi.dart | 10 +- .../nextcloud/lib/src/api/core.openapi.dart | 11 +- .../lib/src/api/dashboard.openapi.dart | 10 +- .../nextcloud/lib/src/api/dav.openapi.dart | 10 +- .../nextcloud/lib/src/api/files.openapi.dart | 11 +- .../lib/src/api/files_external.openapi.dart | 10 +- .../lib/src/api/files_reminders.openapi.dart | 10 +- .../lib/src/api/files_sharing.openapi.dart | 11 +- .../lib/src/api/files_trashbin.openapi.dart | 11 +- .../lib/src/api/files_versions.openapi.dart | 11 +- .../nextcloud/lib/src/api/news.openapi.dart | 8 + .../nextcloud/lib/src/api/notes.openapi.dart | 8 + .../lib/src/api/notifications.openapi.dart | 10 +- .../lib/src/api/provisioning_api.openapi.dart | 10 +- .../lib/src/api/settings.openapi.dart | 11 +- .../lib/src/api/sharebymail.openapi.dart | 10 +- .../nextcloud/lib/src/api/spreed.openapi.dart | 11 +- .../lib/src/api/theming.openapi.dart | 11 +- .../src/api/updatenotification.openapi.dart | 10 +- .../nextcloud/lib/src/api/uppush.openapi.dart | 7 + .../lib/src/api/user_status.openapi.dart | 10 +- .../lib/src/api/weather_status.openapi.dart | 10 +- 58 files changed, 1602 insertions(+), 46 deletions(-) create mode 100644 packages/dynamite/dynamite/lib/src/models/openapi/contact.dart create mode 100644 packages/dynamite/dynamite/lib/src/models/openapi/contact.g.dart create mode 100644 packages/dynamite/dynamite_end_to_end_test/lib/documentation.openapi.dart create mode 100644 packages/dynamite/dynamite_end_to_end_test/lib/documentation.openapi.g.dart create mode 100644 packages/dynamite/dynamite_end_to_end_test/lib/documentation.openapi.json diff --git a/cspell.json b/cspell.json index 05e63b1405f..688356409b0 100644 --- a/cspell.json +++ b/cspell.json @@ -12,6 +12,7 @@ "**/assets", "**/l10n/!(en.arb)", "**.openapi.dart", + "**.openapi.json", "external", "packages/dynamite/dynamite/example/lib", "packages/file_icons/lib/src/data.dart", diff --git a/packages/dynamite/dynamite/example/lib/petstore.openapi.dart b/packages/dynamite/dynamite/example/lib/petstore.openapi.dart index 71c008fff79..2170ef5e9dd 100644 --- a/packages/dynamite/dynamite/example/lib/petstore.openapi.dart +++ b/packages/dynamite/dynamite/example/lib/petstore.openapi.dart @@ -1,10 +1,25 @@ +// Use of this source code is governed by a Apache 2.0 license. It can be obtained at `https://www.apache.org/licenses/LICENSE-2.0.html`. + // OpenAPI client generated by Dynamite. Do not manually edit this file. // ignore_for_file: camel_case_types, discarded_futures // ignore_for_file: no_leading_underscores_for_local_identifiers // ignore_for_file: public_member_api_docs, unreachable_switch_case -// ignore_for_file: no_leading_underscores_for_library_prefixes +/// Swagger Petstore Version: 1.0.0. +/// +/// A sample API that uses a petstore as an example to demonstrate features in the OpenAPI 3.0 specification. +/// +/// You can contact the Swagger API Team team under: +/// Email: `apiteam@swagger.io`. +/// Website: `http://swagger.io`. +/// +/// Use of this source code is governed by a Apache 2.0 license. +/// It can be obtained at `https://www.apache.org/licenses/LICENSE-2.0.html`. +/// +/// Usage of these apis must adhere to the terms of service: `http://swagger.io/terms/`. +library; // ignore_for_file: no_leading_underscores_for_library_prefixes + import 'dart:convert'; import 'dart:typed_data'; diff --git a/packages/dynamite/dynamite/lib/src/builder/generate_schemas.dart b/packages/dynamite/dynamite/lib/src/builder/generate_schemas.dart index f7929977465..06f277c93e6 100644 --- a/packages/dynamite/dynamite/lib/src/builder/generate_schemas.dart +++ b/packages/dynamite/dynamite/lib/src/builder/generate_schemas.dart @@ -21,11 +21,15 @@ Iterable generateSchemas( // TypeDefs should only be generated for top level schemas. if (result is TypeResultBase || result.isTypeDef) { - yield TypeDef( - (b) => b + yield TypeDef((b) { + if (!(state.buildConfig.analyzerIgnores?.contains('public_member_api_docs') ?? false)) { + b.docs.add('// ignore: public_member_api_docs'); + } + + b ..name = identifier - ..definition = refer(result.dartType.name), - ); + ..definition = refer(result.dartType.name); + }); } } } diff --git a/packages/dynamite/dynamite/lib/src/builder/resolve_interface.dart b/packages/dynamite/dynamite/lib/src/builder/resolve_interface.dart index 152bca43a60..077de579331 100644 --- a/packages/dynamite/dynamite/lib/src/builder/resolve_interface.dart +++ b/packages/dynamite/dynamite/lib/src/builder/resolve_interface.dart @@ -40,11 +40,16 @@ Spec buildInterface( String identifier, { BuiltList? methods, Iterable? interfaces, + Iterable? documentation, }) { assert((interfaces == null) != (methods == null), 'Either provide an interface or methods.'); final className = '\$$identifier$interfaceSuffix'; return Class((b) { + if (documentation != null) { + b.docs.addAll(documentation); + } + b ..abstract = true ..modifier = ClassModifier.interface diff --git a/packages/dynamite/dynamite/lib/src/builder/resolve_object.dart b/packages/dynamite/dynamite/lib/src/builder/resolve_object.dart index 1b828307f7f..41de75bc20c 100644 --- a/packages/dynamite/dynamite/lib/src/builder/resolve_object.dart +++ b/packages/dynamite/dynamite/lib/src/builder/resolve_object.dart @@ -89,6 +89,7 @@ TypeResultObject resolveObject( final $interface = buildInterface( identifier, methods: methods.build(), + documentation: schema.formattedDescription, ); final $class = buildBuiltClass( identifier, diff --git a/packages/dynamite/dynamite/lib/src/builder/resolve_ofs.dart b/packages/dynamite/dynamite/lib/src/builder/resolve_ofs.dart index d005fa82771..d5f42b25e80 100644 --- a/packages/dynamite/dynamite/lib/src/builder/resolve_ofs.dart +++ b/packages/dynamite/dynamite/lib/src/builder/resolve_ofs.dart @@ -130,6 +130,7 @@ TypeResult resolveAllOf( identifier, interfaces: interfaces, methods: methods.build(), + documentation: schema.formattedDescription, ); final $class = buildBuiltClass( diff --git a/packages/dynamite/dynamite/lib/src/helpers/docs.dart b/packages/dynamite/dynamite/lib/src/helpers/docs.dart index cd8b5f2a02b..000423b4c91 100644 --- a/packages/dynamite/dynamite/lib/src/helpers/docs.dart +++ b/packages/dynamite/dynamite/lib/src/helpers/docs.dart @@ -5,7 +5,7 @@ Iterable descriptionToDocs(String? description) sync* { for (final line in description.split('\n')) { final buffer = StringBuffer('$docsSeparator ')..write(line); - if (!line.endsWith('.') && line.isNotEmpty) { + if (!line.endsWith('.') && !line.endsWith(':') && line.isNotEmpty) { buffer.write('.'); } diff --git a/packages/dynamite/dynamite/lib/src/models/openapi.dart b/packages/dynamite/dynamite/lib/src/models/openapi.dart index 7535dc10894..2ed29383b4f 100644 --- a/packages/dynamite/dynamite/lib/src/models/openapi.dart +++ b/packages/dynamite/dynamite/lib/src/models/openapi.dart @@ -3,6 +3,7 @@ import 'package:built_value/json_object.dart'; import 'package:built_value/serializer.dart'; import 'package:built_value/standard_json_plugin.dart'; import 'package:dynamite/src/models/openapi/components.dart'; +import 'package:dynamite/src/models/openapi/contact.dart'; import 'package:dynamite/src/models/openapi/discriminator.dart'; import 'package:dynamite/src/models/openapi/header.dart'; import 'package:dynamite/src/models/openapi/info.dart'; @@ -42,6 +43,7 @@ part 'openapi.g.dart'; @SerializersFor([ Components, + Contact, Discriminator, Header, Info, diff --git a/packages/dynamite/dynamite/lib/src/models/openapi.g.dart b/packages/dynamite/dynamite/lib/src/models/openapi.g.dart index ced9be1fa18..981c211e094 100644 --- a/packages/dynamite/dynamite/lib/src/models/openapi.g.dart +++ b/packages/dynamite/dynamite/lib/src/models/openapi.g.dart @@ -8,6 +8,7 @@ part of 'openapi.dart'; Serializers _$serializers = (Serializers().toBuilder() ..add(Components.serializer) + ..add(Contact.serializer) ..add(Discriminator.serializer) ..add(Header.serializer) ..add(Info.serializer) diff --git a/packages/dynamite/dynamite/lib/src/models/openapi/contact.dart b/packages/dynamite/dynamite/lib/src/models/openapi/contact.dart new file mode 100644 index 00000000000..a3663b87c3a --- /dev/null +++ b/packages/dynamite/dynamite/lib/src/models/openapi/contact.dart @@ -0,0 +1,40 @@ +import 'package:built_value/built_value.dart'; +import 'package:built_value/serializer.dart'; + +part 'contact.g.dart'; + +abstract class Contact implements Built { + factory Contact([void Function(ContactBuilder) updates]) = _$Contact; + + const Contact._(); + + static Serializer get serializer => _$contactSerializer; + + String? get name; + String? get url; + String? get email; + + String? formattedDescription() { + final name = this.name; + final url = this.url; + final email = this.email; + + if (name == null || (url ?? email) == null) { + return null; + } + + final buffer = StringBuffer('You can contact the $name team under:'); + if (email != null) { + buffer + ..write('\n') + ..write(' Email: `$email`'); + } + if (url != null) { + buffer + ..write('\n') + ..write(' Website: `$url`'); + } + + return buffer.toString(); + } +} diff --git a/packages/dynamite/dynamite/lib/src/models/openapi/contact.g.dart b/packages/dynamite/dynamite/lib/src/models/openapi/contact.g.dart new file mode 100644 index 00000000000..152414c6192 --- /dev/null +++ b/packages/dynamite/dynamite/lib/src/models/openapi/contact.g.dart @@ -0,0 +1,163 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'contact.dart'; + +// ************************************************************************** +// BuiltValueGenerator +// ************************************************************************** + +Serializer _$contactSerializer = _$ContactSerializer(); + +class _$ContactSerializer implements StructuredSerializer { + @override + final Iterable types = const [Contact, _$Contact]; + @override + final String wireName = 'Contact'; + + @override + Iterable serialize(Serializers serializers, Contact object, + {FullType specifiedType = FullType.unspecified}) { + final result = []; + Object? value; + value = object.name; + if (value != null) { + result + ..add('name') + ..add(serializers.serialize(value, specifiedType: const FullType(String))); + } + value = object.url; + if (value != null) { + result + ..add('url') + ..add(serializers.serialize(value, specifiedType: const FullType(String))); + } + value = object.email; + if (value != null) { + result + ..add('email') + ..add(serializers.serialize(value, specifiedType: const FullType(String))); + } + return result; + } + + @override + Contact deserialize(Serializers serializers, Iterable serialized, + {FullType specifiedType = FullType.unspecified}) { + final result = ContactBuilder(); + + final iterator = serialized.iterator; + while (iterator.moveNext()) { + final key = iterator.current! as String; + iterator.moveNext(); + final Object? value = iterator.current; + switch (key) { + case 'name': + result.name = serializers.deserialize(value, specifiedType: const FullType(String)) as String?; + break; + case 'url': + result.url = serializers.deserialize(value, specifiedType: const FullType(String)) as String?; + break; + case 'email': + result.email = serializers.deserialize(value, specifiedType: const FullType(String)) as String?; + break; + } + } + + return result.build(); + } +} + +class _$Contact extends Contact { + @override + final String? name; + @override + final String? url; + @override + final String? email; + + factory _$Contact([void Function(ContactBuilder)? updates]) => (ContactBuilder()..update(updates))._build(); + + _$Contact._({this.name, this.url, this.email}) : super._(); + + @override + Contact rebuild(void Function(ContactBuilder) updates) => (toBuilder()..update(updates)).build(); + + @override + ContactBuilder toBuilder() => ContactBuilder()..replace(this); + + @override + bool operator ==(Object other) { + if (identical(other, this)) return true; + return other is Contact && name == other.name && url == other.url && email == other.email; + } + + @override + int get hashCode { + var _$hash = 0; + _$hash = $jc(_$hash, name.hashCode); + _$hash = $jc(_$hash, url.hashCode); + _$hash = $jc(_$hash, email.hashCode); + _$hash = $jf(_$hash); + return _$hash; + } + + @override + String toString() { + return (newBuiltValueToStringHelper(r'Contact') + ..add('name', name) + ..add('url', url) + ..add('email', email)) + .toString(); + } +} + +class ContactBuilder implements Builder { + _$Contact? _$v; + + String? _name; + String? get name => _$this._name; + set name(String? name) => _$this._name = name; + + String? _url; + String? get url => _$this._url; + set url(String? url) => _$this._url = url; + + String? _email; + String? get email => _$this._email; + set email(String? email) => _$this._email = email; + + ContactBuilder(); + + ContactBuilder get _$this { + final $v = _$v; + if ($v != null) { + _name = $v.name; + _url = $v.url; + _email = $v.email; + _$v = null; + } + return this; + } + + @override + void replace(Contact other) { + ArgumentError.checkNotNull(other, 'other'); + _$v = other as _$Contact; + } + + @override + void update(void Function(ContactBuilder)? updates) { + if (updates != null) updates(this); + } + + @override + Contact build() => _build(); + + _$Contact _build() { + final _$result = _$v ?? _$Contact._(name: name, url: url, email: email); + replace(_$result); + return _$result; + } +} + +// ignore_for_file: deprecated_member_use_from_same_package,type=lint diff --git a/packages/dynamite/dynamite/lib/src/models/openapi/info.dart b/packages/dynamite/dynamite/lib/src/models/openapi/info.dart index d8b8d7f92ba..af6a162da29 100644 --- a/packages/dynamite/dynamite/lib/src/models/openapi/info.dart +++ b/packages/dynamite/dynamite/lib/src/models/openapi/info.dart @@ -1,5 +1,7 @@ import 'package:built_value/built_value.dart'; import 'package:built_value/serializer.dart'; +import 'package:dynamite/src/helpers/docs.dart'; +import 'package:dynamite/src/models/openapi/contact.dart'; import 'package:dynamite/src/models/openapi/license.dart'; part 'info.g.dart'; @@ -18,6 +20,53 @@ abstract class Info implements Built { License? get license; + Contact? get contact; + @BuiltValueField(compare: false) String? get description; + + String? get termsOfService; + + String? get summary; + + Iterable formattedDescription() { + final buffer = StringBuffer()..write('$title Version: $version'); + + final summary = this.summary; + if (summary != null && summary.isNotEmpty) { + buffer + ..write('\n') + ..write(summary); + } + + final description = this.description; + if (description != null && description.isNotEmpty) { + buffer + ..write('\n\n') + ..write(description); + } + + final contact = this.contact; + if (contact != null) { + buffer + ..write('\n\n') + ..write(contact.formattedDescription()); + } + + final license = this.license; + if (license != null) { + buffer + ..write('\n\n') + ..write(license.formattedDescription(singleLine: false)); + } + + final termsOfService = this.termsOfService; + if (termsOfService != null) { + buffer + ..write('\n\n') + ..write('Usage of these apis must adhere to the terms of service: `$termsOfService`'); + } + + return descriptionToDocs(buffer.toString()); + } } diff --git a/packages/dynamite/dynamite/lib/src/models/openapi/info.g.dart b/packages/dynamite/dynamite/lib/src/models/openapi/info.g.dart index e3cc0482893..df48cb5297d 100644 --- a/packages/dynamite/dynamite/lib/src/models/openapi/info.g.dart +++ b/packages/dynamite/dynamite/lib/src/models/openapi/info.g.dart @@ -29,12 +29,30 @@ class _$InfoSerializer implements StructuredSerializer { ..add('license') ..add(serializers.serialize(value, specifiedType: const FullType(License))); } + value = object.contact; + if (value != null) { + result + ..add('contact') + ..add(serializers.serialize(value, specifiedType: const FullType(Contact))); + } value = object.description; if (value != null) { result ..add('description') ..add(serializers.serialize(value, specifiedType: const FullType(String))); } + value = object.termsOfService; + if (value != null) { + result + ..add('termsOfService') + ..add(serializers.serialize(value, specifiedType: const FullType(String))); + } + value = object.summary; + if (value != null) { + result + ..add('summary') + ..add(serializers.serialize(value, specifiedType: const FullType(String))); + } return result; } @@ -58,9 +76,18 @@ class _$InfoSerializer implements StructuredSerializer { case 'license': result.license.replace(serializers.deserialize(value, specifiedType: const FullType(License))! as License); break; + case 'contact': + result.contact.replace(serializers.deserialize(value, specifiedType: const FullType(Contact))! as Contact); + break; case 'description': result.description = serializers.deserialize(value, specifiedType: const FullType(String)) as String?; break; + case 'termsOfService': + result.termsOfService = serializers.deserialize(value, specifiedType: const FullType(String)) as String?; + break; + case 'summary': + result.summary = serializers.deserialize(value, specifiedType: const FullType(String)) as String?; + break; } } @@ -76,11 +103,25 @@ class _$Info extends Info { @override final License? license; @override + final Contact? contact; + @override final String? description; + @override + final String? termsOfService; + @override + final String? summary; factory _$Info([void Function(InfoBuilder)? updates]) => (InfoBuilder()..update(updates))._build(); - _$Info._({required this.title, required this.version, this.license, this.description}) : super._() { + _$Info._( + {required this.title, + required this.version, + this.license, + this.contact, + this.description, + this.termsOfService, + this.summary}) + : super._() { BuiltValueNullFieldError.checkNotNull(title, r'Info', 'title'); BuiltValueNullFieldError.checkNotNull(version, r'Info', 'version'); } @@ -94,7 +135,12 @@ class _$Info extends Info { @override bool operator ==(Object other) { if (identical(other, this)) return true; - return other is Info && version == other.version && license == other.license; + return other is Info && + version == other.version && + license == other.license && + contact == other.contact && + termsOfService == other.termsOfService && + summary == other.summary; } @override @@ -102,6 +148,9 @@ class _$Info extends Info { var _$hash = 0; _$hash = $jc(_$hash, version.hashCode); _$hash = $jc(_$hash, license.hashCode); + _$hash = $jc(_$hash, contact.hashCode); + _$hash = $jc(_$hash, termsOfService.hashCode); + _$hash = $jc(_$hash, summary.hashCode); _$hash = $jf(_$hash); return _$hash; } @@ -112,7 +161,10 @@ class _$Info extends Info { ..add('title', title) ..add('version', version) ..add('license', license) - ..add('description', description)) + ..add('contact', contact) + ..add('description', description) + ..add('termsOfService', termsOfService) + ..add('summary', summary)) .toString(); } } @@ -132,10 +184,22 @@ class InfoBuilder implements Builder { LicenseBuilder get license => _$this._license ??= LicenseBuilder(); set license(LicenseBuilder? license) => _$this._license = license; + ContactBuilder? _contact; + ContactBuilder get contact => _$this._contact ??= ContactBuilder(); + set contact(ContactBuilder? contact) => _$this._contact = contact; + String? _description; String? get description => _$this._description; set description(String? description) => _$this._description = description; + String? _termsOfService; + String? get termsOfService => _$this._termsOfService; + set termsOfService(String? termsOfService) => _$this._termsOfService = termsOfService; + + String? _summary; + String? get summary => _$this._summary; + set summary(String? summary) => _$this._summary = summary; + InfoBuilder(); InfoBuilder get _$this { @@ -144,7 +208,10 @@ class InfoBuilder implements Builder { _title = $v.title; _version = $v.version; _license = $v.license?.toBuilder(); + _contact = $v.contact?.toBuilder(); _description = $v.description; + _termsOfService = $v.termsOfService; + _summary = $v.summary; _$v = null; } return this; @@ -172,12 +239,17 @@ class InfoBuilder implements Builder { title: BuiltValueNullFieldError.checkNotNull(title, r'Info', 'title'), version: BuiltValueNullFieldError.checkNotNull(version, r'Info', 'version'), license: _license?.build(), - description: description); + contact: _contact?.build(), + description: description, + termsOfService: termsOfService, + summary: summary); } catch (_) { late String _$failedField; try { _$failedField = 'license'; _license?.build(); + _$failedField = 'contact'; + _contact?.build(); } catch (e) { throw BuiltValueNestedFieldError(r'Info', _$failedField, e.toString()); } diff --git a/packages/dynamite/dynamite/lib/src/models/openapi/license.dart b/packages/dynamite/dynamite/lib/src/models/openapi/license.dart index f02e74659df..5003d4d18db 100644 --- a/packages/dynamite/dynamite/lib/src/models/openapi/license.dart +++ b/packages/dynamite/dynamite/lib/src/models/openapi/license.dart @@ -15,4 +15,17 @@ abstract class License implements Built { String? get identifier; String? get url; + + String formattedDescription({bool singleLine = true}) { + final buffer = StringBuffer('Use of this source code is governed by a $name license.'); + + if (url != null || identifier != null) { + final url = this.url ?? 'https://spdx.org/licenses/$identifier.html'; + buffer + ..write(singleLine ? ' ' : '\n') + ..write('It can be obtained at `$url`.'); + } + + return buffer.toString(); + } } diff --git a/packages/dynamite/dynamite/lib/src/openapi_builder.dart b/packages/dynamite/dynamite/lib/src/openapi_builder.dart index b56f9750d77..a861ee0dbeb 100644 --- a/packages/dynamite/dynamite/lib/src/openapi_builder.dart +++ b/packages/dynamite/dynamite/lib/src/openapi_builder.dart @@ -79,8 +79,16 @@ class OpenAPIBuilder implements Builder { b.ignoreForFile.addAll(analyzerIgnores); } + final comment = spec.info.license?.formattedDescription(); + if (comment != null) { + b.comments.add(comment); + } + b ..generatedByComment = 'OpenAPI client generated by Dynamite. Do not manually edit this file.' + ..docs.addAll( + spec.info.formattedDescription(), + ) ..directives.addAll([ Directive.import('dart:convert'), Directive.import('dart:typed_data'), diff --git a/packages/dynamite/dynamite/pubspec.yaml b/packages/dynamite/dynamite/pubspec.yaml index 5b3a1fefab6..bf4b911d285 100644 --- a/packages/dynamite/dynamite/pubspec.yaml +++ b/packages/dynamite/dynamite/pubspec.yaml @@ -16,7 +16,7 @@ dependencies: built_collection: ^5.0.0 built_value: ^8.0.1 checked_yaml: ^2.0.0 - code_builder: ^4.9.0 + code_builder: ^4.10.0 collection: ^1.0.0 crypto: ^3.0.0 dart_style: ^2.0.0 diff --git a/packages/dynamite/dynamite_end_to_end_test/build.yaml b/packages/dynamite/dynamite_end_to_end_test/build.yaml index 7b44fb568f7..53674610efa 100644 --- a/packages/dynamite/dynamite_end_to_end_test/build.yaml +++ b/packages/dynamite/dynamite_end_to_end_test/build.yaml @@ -14,3 +14,12 @@ targets: - unreachable_switch_case - unused_element - no_leading_underscores_for_local_identifiers + overrides: + lib/documentation.openapi.json: + analyzer_ignores: + - camel_case_types + - camel_case_extensions + - discarded_futures + - unreachable_switch_case + - unused_element + - no_leading_underscores_for_local_identifiers diff --git a/packages/dynamite/dynamite_end_to_end_test/lib/all_of.openapi.dart b/packages/dynamite/dynamite_end_to_end_test/lib/all_of.openapi.dart index 4112c8c709d..23d8b55397f 100644 --- a/packages/dynamite/dynamite_end_to_end_test/lib/all_of.openapi.dart +++ b/packages/dynamite/dynamite_end_to_end_test/lib/all_of.openapi.dart @@ -5,7 +5,8 @@ // ignore_for_file: public_member_api_docs, unreachable_switch_case // ignore_for_file: unused_element -// ignore_for_file: no_leading_underscores_for_library_prefixes +/// all of test Version: 0.0.1. +library; // ignore_for_file: no_leading_underscores_for_library_prefixes import 'package:built_value/built_value.dart'; import 'package:built_value/serializer.dart'; @@ -15,6 +16,7 @@ import 'package:meta/meta.dart' as _i1; part 'all_of.openapi.g.dart'; +/// All of with objects only. @BuiltValue(instantiable: false) abstract interface class $ObjectAllOfInterface { @BuiltValueField(wireName: 'attribute1-allOf') @@ -44,6 +46,7 @@ abstract class ObjectAllOf implements $ObjectAllOfInterface, Built get serializer => _$objectAllOfSerializer; } +/// All of with one object value. @BuiltValue(instantiable: false) abstract interface class $OneObjectAllOfInterface { @BuiltValueField(wireName: 'attribute-allOf') @@ -71,6 +74,7 @@ abstract class OneObjectAllOf implements $OneObjectAllOfInterface, Built get serializer => _$oneObjectAllOfSerializer; } +/// All of with an primitive values. @BuiltValue(instantiable: false) abstract interface class $PrimitiveAllOfInterface { @BuiltValueField(wireName: 'int') @@ -100,6 +104,7 @@ abstract class PrimitiveAllOf implements $PrimitiveAllOfInterface, Built get serializer => _$primitiveAllOfSerializer; } +/// All of with object and primitive value. @BuiltValue(instantiable: false) abstract interface class $MixedAllOfInterface { @BuiltValueField(wireName: 'String') @@ -129,6 +134,7 @@ abstract class MixedAllOf implements $MixedAllOfInterface, Built get serializer => _$mixedAllOfSerializer; } +/// All of with one primitive value. @BuiltValue(instantiable: false) abstract interface class $OneValueAllOfInterface { @BuiltValueField(wireName: 'String') diff --git a/packages/dynamite/dynamite_end_to_end_test/lib/any_of.openapi.dart b/packages/dynamite/dynamite_end_to_end_test/lib/any_of.openapi.dart index 460050b8785..6b5a8f90204 100644 --- a/packages/dynamite/dynamite_end_to_end_test/lib/any_of.openapi.dart +++ b/packages/dynamite/dynamite_end_to_end_test/lib/any_of.openapi.dart @@ -5,7 +5,8 @@ // ignore_for_file: public_member_api_docs, unreachable_switch_case // ignore_for_file: unused_element -// ignore_for_file: no_leading_underscores_for_library_prefixes +/// any of test Version: 0.0.1. +library; // ignore_for_file: no_leading_underscores_for_library_prefixes import 'package:built_value/built_value.dart'; import 'package:built_value/serializer.dart'; diff --git a/packages/dynamite/dynamite_end_to_end_test/lib/authentication.openapi.dart b/packages/dynamite/dynamite_end_to_end_test/lib/authentication.openapi.dart index da6006109d4..706e92f3f66 100644 --- a/packages/dynamite/dynamite_end_to_end_test/lib/authentication.openapi.dart +++ b/packages/dynamite/dynamite_end_to_end_test/lib/authentication.openapi.dart @@ -5,7 +5,8 @@ // ignore_for_file: public_member_api_docs, unreachable_switch_case // ignore_for_file: unused_element -// ignore_for_file: no_leading_underscores_for_library_prefixes +/// authentication test Version: 0.0.1. +library; // ignore_for_file: no_leading_underscores_for_library_prefixes import 'package:built_value/json_object.dart'; import 'package:built_value/serializer.dart'; diff --git a/packages/dynamite/dynamite_end_to_end_test/lib/documentation.openapi.dart b/packages/dynamite/dynamite_end_to_end_test/lib/documentation.openapi.dart new file mode 100644 index 00000000000..0fb2bf373f5 --- /dev/null +++ b/packages/dynamite/dynamite_end_to_end_test/lib/documentation.openapi.dart @@ -0,0 +1,448 @@ +// Use of this source code is governed by a Apache 2.0 license. It can be obtained at `https://www.apache.org/licenses/LICENSE-2.0.html`. + +// OpenAPI client generated by Dynamite. Do not manually edit this file. + +// ignore_for_file: camel_case_extensions, camel_case_types, discarded_futures +// ignore_for_file: no_leading_underscores_for_local_identifiers +// ignore_for_file: unreachable_switch_case, unused_element + +/// Documentation test. Version: 1.0.0. +/// Values are inspired by the petstore example. +/// +/// A sample API that uses a petstore as an example to demonstrate features in the OpenAPI 3.0 specification. +/// +/// You can contact the Swagger API Team team under: +/// Email: `apiteam@swagger.io`. +/// Website: `http://swagger.io`. +/// +/// Use of this source code is governed by a Apache 2.0 license. +/// It can be obtained at `https://www.apache.org/licenses/LICENSE-2.0.html`. +/// +/// Usage of these apis must adhere to the terms of service: `http://swagger.io/terms/`. +library; // ignore_for_file: no_leading_underscores_for_library_prefixes + +import 'package:built_collection/built_collection.dart'; +import 'package:built_value/built_value.dart'; +import 'package:built_value/serializer.dart'; +import 'package:built_value/standard_json_plugin.dart' as _i6; +import 'package:dynamite_runtime/built_value.dart' as _i5; +import 'package:dynamite_runtime/http_client.dart' as _i2; +import 'package:dynamite_runtime/utils.dart' as _i4; +import 'package:meta/meta.dart' as _i3; +import 'package:uri/uri.dart' as _i1; + +part 'documentation.openapi.g.dart'; + +/// the root client used for root requests. +class $Client extends _i2.DynamiteClient { + /// Creates a new `DynamiteClient` for untagged requests. + $Client( + super.baseURL, { + super.baseHeaders, + super.userAgent, + super.httpClient, + super.cookieJar, + }); + + /// Creates a new [$Client] from another [client]. + $Client.fromClient(_i2.DynamiteClient client) + : super( + client.baseURL, + baseHeaders: client.baseHeaders, + httpClient: client.httpClient, + cookieJar: client.cookieJar, + authentications: client.authentications, + ); + + /// the non root client used for other requests. + late final $NonRootClientClient nonRootClient = $NonRootClientClient(this); + + /// An optional, string summary, intended to apply to all operations in this path. + /// + /// Returns all pets from the system that the user has access to. + /// Nam sed condimentum est. Maecenas tempor sagittis sapien, nec rhoncus sem sagittis sit amet. Aenean at gravida augue, ac iaculis sem. Curabitur odio lorem, ornare eget elementum nec, cursus id lectus. Duis mi turpis, pulvinar ac eros ac, tincidunt varius justo. In hac habitasse platea dictumst. Integer at adipiscing ante, a sagittis ligula. Aenean pharetra tempor ante molestie imperdiet. Vivamus id aliquam diam. Cras quis velit non tortor eleifend sagittis. Praesent at enim pharetra urna volutpat venenatis eget eget mauris. In eleifend fermentum facilisis. Praesent enim enim, gravida ac sodales sed, placerat id erat. Suspendisse lacus dolor, consectetur non augue vel, vehicula interdum libero. Morbi euismod sagittis libero sed lacinia. + /// + /// Sed tempus felis lobortis leo pulvinar rutrum. Nam mattis velit nisl, eu condimentum ligula luctus nec. Phasellus semper velit eget aliquet faucibus. In a mattis elit. Phasellus vel urna viverra, condimentum lorem id, rhoncus nibh. Ut pellentesque posuere elementum. Sed a varius odio. Morbi rhoncus ligula libero, vel eleifend nunc tristique vitae. Fusce et sem dui. Aenean nec scelerisque tortor. Fusce malesuada accumsan magna vel tempus. Quisque mollis felis eu dolor tristique, sit amet auctor felis gravida. Sed libero lorem, molestie sed nisl in, accumsan tempor nisi. Fusce sollicitudin massa ut lacinia mattis. Sed vel eleifend lorem. Pellentesque vitae felis pretium, pulvinar elit eu, euismod sapien. + /// + /// + /// Returns a [Future] containing a `DynamiteResponse` with the status code, deserialized body and headers. + /// Throws a `DynamiteApiException` if the API call does not return an expected status code. + /// + /// Parameters: + /// * [tags] tags to filter by. + /// * [limit] maximum number of results to return. + /// + /// Status codes: + /// * default: finds an object + /// + /// See: + /// * [findValuesRaw] for an experimental operation that returns a `DynamiteRawResponse` that can be serialized. + Future<_i2.DynamiteResponse> findValues({ + BuiltList? tags, + int? limit, + }) async { + final rawResponse = findValuesRaw( + tags: tags, + limit: limit, + ); + + return rawResponse.future; + } + + /// An optional, string summary, intended to apply to all operations in this path. + /// + /// Returns all pets from the system that the user has access to. + /// Nam sed condimentum est. Maecenas tempor sagittis sapien, nec rhoncus sem sagittis sit amet. Aenean at gravida augue, ac iaculis sem. Curabitur odio lorem, ornare eget elementum nec, cursus id lectus. Duis mi turpis, pulvinar ac eros ac, tincidunt varius justo. In hac habitasse platea dictumst. Integer at adipiscing ante, a sagittis ligula. Aenean pharetra tempor ante molestie imperdiet. Vivamus id aliquam diam. Cras quis velit non tortor eleifend sagittis. Praesent at enim pharetra urna volutpat venenatis eget eget mauris. In eleifend fermentum facilisis. Praesent enim enim, gravida ac sodales sed, placerat id erat. Suspendisse lacus dolor, consectetur non augue vel, vehicula interdum libero. Morbi euismod sagittis libero sed lacinia. + /// + /// Sed tempus felis lobortis leo pulvinar rutrum. Nam mattis velit nisl, eu condimentum ligula luctus nec. Phasellus semper velit eget aliquet faucibus. In a mattis elit. Phasellus vel urna viverra, condimentum lorem id, rhoncus nibh. Ut pellentesque posuere elementum. Sed a varius odio. Morbi rhoncus ligula libero, vel eleifend nunc tristique vitae. Fusce et sem dui. Aenean nec scelerisque tortor. Fusce malesuada accumsan magna vel tempus. Quisque mollis felis eu dolor tristique, sit amet auctor felis gravida. Sed libero lorem, molestie sed nisl in, accumsan tempor nisi. Fusce sollicitudin massa ut lacinia mattis. Sed vel eleifend lorem. Pellentesque vitae felis pretium, pulvinar elit eu, euismod sapien. + /// + /// + /// This method and the response it returns is experimental. The API might change without a major version bump. + /// + /// Returns a [Future] containing a `DynamiteRawResponse` with the raw `HttpClientResponse` and serialization helpers. + /// Throws a `DynamiteApiException` if the API call does not return an expected status code. + /// + /// Parameters: + /// * [tags] tags to filter by. + /// * [limit] maximum number of results to return. + /// + /// Status codes: + /// * default: finds an object + /// + /// See: + /// * [findValues] for an operation that returns a `DynamiteResponse` with a stable API. + @_i3.experimental + _i2.DynamiteRawResponse findValuesRaw({ + BuiltList? tags, + int? limit, + }) { + final _parameters = {}; + const _headers = { + 'Accept': 'application/json', + }; + + final $tags = _$jsonSerializers.serialize(tags, specifiedType: const FullType(BuiltList, [FullType(String)])); + _parameters['tags'] = $tags; + + final $limit = _$jsonSerializers.serialize(limit, specifiedType: const FullType(int)); + _parameters['limit'] = $limit; + + final _path = _i1.UriTemplate('/{?tags*,limit*}').expand(_parameters); + return _i2.DynamiteRawResponse( + response: executeRequest( + 'get', + _path, + _headers, + null, + null, + ), + bodyType: const FullType(Object1), + headersType: null, + serializers: _$jsonSerializers, + ); + } +} + +/// the non root client used for other requests. +class $NonRootClientClient { + /// Creates a new `DynamiteClient` for non_root_client requests. + $NonRootClientClient(this._rootClient); + + final $Client _rootClient; + + /// Do something really cool. + /// + /// Returns a [Future] containing a `DynamiteResponse` with the status code, deserialized body and headers. + /// Throws a `DynamiteApiException` if the API call does not return an expected status code. + /// + /// Status codes: + /// * default: finds an object + /// + /// See: + /// * [setModeRaw] for an experimental operation that returns a `DynamiteRawResponse` that can be serialized. + Future<_i2.DynamiteResponse> setMode() async { + final rawResponse = setModeRaw(); + + return rawResponse.future; + } + + /// Do something really cool. + /// + /// This method and the response it returns is experimental. The API might change without a major version bump. + /// + /// Returns a [Future] containing a `DynamiteRawResponse` with the raw `HttpClientResponse` and serialization helpers. + /// Throws a `DynamiteApiException` if the API call does not return an expected status code. + /// + /// Status codes: + /// * default: finds an object + /// + /// See: + /// * [setMode] for an operation that returns a `DynamiteResponse` with a stable API. + @_i3.experimental + _i2.DynamiteRawResponse setModeRaw() { + const _headers = { + 'Accept': 'application/json', + }; + + const _path = '/other-endpoint'; + return _i2.DynamiteRawResponse( + response: _rootClient.executeRequest( + 'post', + _path, + _headers, + null, + null, + ), + bodyType: const FullType(Object1), + headersType: null, + serializers: _$jsonSerializers, + ); + } +} + +// ignore: public_member_api_docs +typedef Redirect = Object2; + +/// A representation of the second Object type. +@BuiltValue(instantiable: false) +abstract interface class $Object2Interface { + /// The name of this object. + String get name; + + /// The tag of an Object2 object. + String? get tag; +} + +/// A representation of the second Object type. +abstract class Object2 implements $Object2Interface, Built { + /// Creates a new Object2 object using the builder pattern. + factory Object2([void Function(Object2Builder)? b]) = _$Object2; + + const Object2._(); + + /// Creates a new object from the given [json] data. + /// + /// Use [toJson] to serialize it back into json. + factory Object2.fromJson(Map json) => _$jsonSerializers.deserializeWith(serializer, json)!; + + /// Parses this object into a json like map. + /// + /// Use the fromJson factory to revive it again. + Map toJson() => _$jsonSerializers.serializeWith(serializer, this)! as Map; + + /// Serializer for Object2. + static Serializer get serializer => _$object2Serializer; +} + +/// A representation of the main object. +@BuiltValue(instantiable: false) +abstract interface class $Object1Interface implements $Object2Interface { + /// The uuid in an UUIDv4 format. + int get id; +} + +/// A representation of the main object. +abstract class Object1 implements $Object1Interface, Built { + /// Creates a new Object1 object using the builder pattern. + factory Object1([void Function(Object1Builder)? b]) = _$Object1; + + const Object1._(); + + /// Creates a new object from the given [json] data. + /// + /// Use [toJson] to serialize it back into json. + factory Object1.fromJson(Map json) => _$jsonSerializers.deserializeWith(serializer, json)!; + + /// Parses this object into a json like map. + /// + /// Use the fromJson factory to revive it again. + Map toJson() => _$jsonSerializers.serializeWith(serializer, this)! as Map; + + /// Serializer for Object1. + static Serializer get serializer => _$object1Serializer; +} + +/// An Object to test the documentation of someOf extension methods and typdefs. +typedef Object3 = ({int? $int, String? string}); + +/// The measured skill for hunting. +class HuntingSkill extends EnumClass { + const HuntingSkill._(super.name); + + /// `clueless` + static const HuntingSkill clueless = _$huntingSkillClueless; + + /// `lazy` + static const HuntingSkill lazy = _$huntingSkillLazy; + + /// `adventurous` + static const HuntingSkill adventurous = _$huntingSkillAdventurous; + + /// `aggressive` + static const HuntingSkill aggressive = _$huntingSkillAggressive; + + /// Returns a set with all values this enum contains. + static BuiltSet get values => _$huntingSkillValues; + + /// Returns the enum value associated to the [name]. + static HuntingSkill valueOf(String name) => _$valueOfHuntingSkill(name); + + /// Returns the serialized value of this enum value. + dynamic get value => _$jsonSerializers.serializeWith(serializer, this)! as dynamic; + + /// Serializer for HuntingSkill. + @BuiltValueSerializer(custom: true) + static Serializer get serializer => const _$HuntingSkillSerializer(); +} + +class _$HuntingSkillSerializer implements PrimitiveSerializer { + const _$HuntingSkillSerializer(); + + static const Map _toWire = { + HuntingSkill.clueless: 'clueless', + HuntingSkill.lazy: 'lazy', + HuntingSkill.adventurous: 'adventurous', + HuntingSkill.aggressive: 'aggressive', + }; + + static const Map _fromWire = { + 'clueless': HuntingSkill.clueless, + 'lazy': HuntingSkill.lazy, + 'adventurous': HuntingSkill.adventurous, + 'aggressive': HuntingSkill.aggressive, + }; + + @override + Iterable get types => const [HuntingSkill]; + + @override + String get wireName => 'HuntingSkill'; + + @override + Object serialize( + Serializers serializers, + HuntingSkill object, { + FullType specifiedType = FullType.unspecified, + }) => + _toWire[object]!; + + @override + HuntingSkill deserialize( + Serializers serializers, + Object serialized, { + FullType specifiedType = FullType.unspecified, + }) => + _fromWire[serialized]!; +} + +/// Serialization extension for `Object3`. +extension $Object3Extension on Object3 { + /// Serializer for Object3. + @BuiltValueSerializer(custom: true) + static Serializer get serializer => $b2c4857c0136baea42828d89c87c757dExtension._serializer; + + /// Creates a new object from the given [json] data. + /// + /// Use `toJson` to serialize it back into json. + static Object3 fromJson(Object? json) => $b2c4857c0136baea42828d89c87c757dExtension._fromJson(json); +} + +typedef _$b2c4857c0136baea42828d89c87c757d = ({int? $int, String? string}); + +/// @nodoc +// ignore: library_private_types_in_public_api +extension $b2c4857c0136baea42828d89c87c757dExtension on _$b2c4857c0136baea42828d89c87c757d { + List get _values => [$int, string]; + + /// {@macro Dynamite.validateOneOf} + void validateOneOf() => _i4.validateOneOf(_values); + + /// {@macro Dynamite.validateAnyOf} + void validateAnyOf() => _i4.validateAnyOf(_values); + static Serializer<_$b2c4857c0136baea42828d89c87c757d> get _serializer => + const _$b2c4857c0136baea42828d89c87c757dSerializer(); + static _$b2c4857c0136baea42828d89c87c757d _fromJson(Object? json) => + _$jsonSerializers.deserializeWith(_serializer, json)!; + + /// Parses this object into a json like map. + /// + /// Use the fromJson factory to revive it again. + Object? toJson() => _$jsonSerializers.serializeWith(_serializer, this); +} + +class _$b2c4857c0136baea42828d89c87c757dSerializer implements PrimitiveSerializer<_$b2c4857c0136baea42828d89c87c757d> { + const _$b2c4857c0136baea42828d89c87c757dSerializer(); + + @override + Iterable get types => const [_$b2c4857c0136baea42828d89c87c757d]; + + @override + String get wireName => r'_$b2c4857c0136baea42828d89c87c757d'; + + @override + Object serialize( + Serializers serializers, + _$b2c4857c0136baea42828d89c87c757d object, { + FullType specifiedType = FullType.unspecified, + }) { + dynamic value; + value = object.$int; + if (value != null) { + return serializers.serialize(value, specifiedType: const FullType(int))!; + } + value = object.string; + if (value != null) { + return serializers.serialize(value, specifiedType: const FullType(String))!; + } +// Should not be possible after validation. + throw StateError('Tried to serialize without any value.'); + } + + @override + _$b2c4857c0136baea42828d89c87c757d deserialize( + Serializers serializers, + Object data, { + FullType specifiedType = FullType.unspecified, + }) { + int? $int; + try { + $int = serializers.deserialize(data, specifiedType: const FullType(int))! as int; + } catch (_) {} + String? string; + try { + string = serializers.deserialize(data, specifiedType: const FullType(String))! as String; + } catch (_) {} + return ($int: $int, string: string); + } +} + +// coverage:ignore-start +/// Serializer for all values in this library. +/// +/// Serializes values into the `built_value` wire format. +/// See: [$jsonSerializers] for serializing into json. +@_i3.visibleForTesting +final Serializers $serializers = _$serializers; +final Serializers _$serializers = (Serializers().toBuilder() + ..addBuilderFactory(const FullType(BuiltList, [FullType(String)]), ListBuilder.new) + ..addBuilderFactory(const FullType(Object1), Object1Builder.new) + ..add(Object1.serializer) + ..addBuilderFactory(const FullType(Object2), Object2Builder.new) + ..add(Object2.serializer) + ..add($b2c4857c0136baea42828d89c87c757dExtension._serializer) + ..add(HuntingSkill.serializer)) + .build(); + +/// Serializer for all values in this library. +/// +/// Serializes values into the json. Json serialization is more expensive than the built_value wire format. +/// See: [$serializers] for serializing into the `built_value` wire format. +@_i3.visibleForTesting +final Serializers $jsonSerializers = _$jsonSerializers; +final Serializers _$jsonSerializers = (_$serializers.toBuilder() + ..add(_i5.DynamiteDoubleSerializer()) + ..addPlugin(_i6.StandardJsonPlugin()) + ..addPlugin(const _i5.HeaderPlugin()) + ..addPlugin(const _i5.ContentStringPlugin())) + .build(); +// coverage:ignore-end diff --git a/packages/dynamite/dynamite_end_to_end_test/lib/documentation.openapi.g.dart b/packages/dynamite/dynamite_end_to_end_test/lib/documentation.openapi.g.dart new file mode 100644 index 00000000000..aceb80188ed --- /dev/null +++ b/packages/dynamite/dynamite_end_to_end_test/lib/documentation.openapi.g.dart @@ -0,0 +1,348 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'documentation.openapi.dart'; + +// ************************************************************************** +// BuiltValueGenerator +// ************************************************************************** + +const HuntingSkill _$huntingSkillClueless = HuntingSkill._('clueless'); +const HuntingSkill _$huntingSkillLazy = HuntingSkill._('lazy'); +const HuntingSkill _$huntingSkillAdventurous = HuntingSkill._('adventurous'); +const HuntingSkill _$huntingSkillAggressive = HuntingSkill._('aggressive'); + +HuntingSkill _$valueOfHuntingSkill(String name) { + switch (name) { + case 'clueless': + return _$huntingSkillClueless; + case 'lazy': + return _$huntingSkillLazy; + case 'adventurous': + return _$huntingSkillAdventurous; + case 'aggressive': + return _$huntingSkillAggressive; + default: + throw ArgumentError(name); + } +} + +final BuiltSet _$huntingSkillValues = BuiltSet(const [ + _$huntingSkillClueless, + _$huntingSkillLazy, + _$huntingSkillAdventurous, + _$huntingSkillAggressive, +]); + +Serializer _$object2Serializer = _$Object2Serializer(); +Serializer _$object1Serializer = _$Object1Serializer(); + +class _$Object2Serializer implements StructuredSerializer { + @override + final Iterable types = const [Object2, _$Object2]; + @override + final String wireName = 'Object2'; + + @override + Iterable serialize(Serializers serializers, Object2 object, + {FullType specifiedType = FullType.unspecified}) { + final result = [ + 'name', + serializers.serialize(object.name, specifiedType: const FullType(String)), + ]; + Object? value; + value = object.tag; + if (value != null) { + result + ..add('tag') + ..add(serializers.serialize(value, specifiedType: const FullType(String))); + } + return result; + } + + @override + Object2 deserialize(Serializers serializers, Iterable serialized, + {FullType specifiedType = FullType.unspecified}) { + final result = Object2Builder(); + + final iterator = serialized.iterator; + while (iterator.moveNext()) { + final key = iterator.current! as String; + iterator.moveNext(); + final Object? value = iterator.current; + switch (key) { + case 'name': + result.name = serializers.deserialize(value, specifiedType: const FullType(String))! as String; + break; + case 'tag': + result.tag = serializers.deserialize(value, specifiedType: const FullType(String)) as String?; + break; + } + } + + return result.build(); + } +} + +class _$Object1Serializer implements StructuredSerializer { + @override + final Iterable types = const [Object1, _$Object1]; + @override + final String wireName = 'Object1'; + + @override + Iterable serialize(Serializers serializers, Object1 object, + {FullType specifiedType = FullType.unspecified}) { + final result = [ + 'id', + serializers.serialize(object.id, specifiedType: const FullType(int)), + 'name', + serializers.serialize(object.name, specifiedType: const FullType(String)), + ]; + Object? value; + value = object.tag; + if (value != null) { + result + ..add('tag') + ..add(serializers.serialize(value, specifiedType: const FullType(String))); + } + return result; + } + + @override + Object1 deserialize(Serializers serializers, Iterable serialized, + {FullType specifiedType = FullType.unspecified}) { + final result = Object1Builder(); + + final iterator = serialized.iterator; + while (iterator.moveNext()) { + final key = iterator.current! as String; + iterator.moveNext(); + final Object? value = iterator.current; + switch (key) { + case 'id': + result.id = serializers.deserialize(value, specifiedType: const FullType(int))! as int; + break; + case 'name': + result.name = serializers.deserialize(value, specifiedType: const FullType(String))! as String; + break; + case 'tag': + result.tag = serializers.deserialize(value, specifiedType: const FullType(String)) as String?; + break; + } + } + + return result.build(); + } +} + +abstract mixin class $Object2InterfaceBuilder { + void replace($Object2Interface other); + void update(void Function($Object2InterfaceBuilder) updates); + String? get name; + set name(String? name); + + String? get tag; + set tag(String? tag); +} + +class _$Object2 extends Object2 { + @override + final String name; + @override + final String? tag; + + factory _$Object2([void Function(Object2Builder)? updates]) => (Object2Builder()..update(updates))._build(); + + _$Object2._({required this.name, this.tag}) : super._() { + BuiltValueNullFieldError.checkNotNull(name, r'Object2', 'name'); + } + + @override + Object2 rebuild(void Function(Object2Builder) updates) => (toBuilder()..update(updates)).build(); + + @override + Object2Builder toBuilder() => Object2Builder()..replace(this); + + @override + bool operator ==(Object other) { + if (identical(other, this)) return true; + return other is Object2 && name == other.name && tag == other.tag; + } + + @override + int get hashCode { + var _$hash = 0; + _$hash = $jc(_$hash, name.hashCode); + _$hash = $jc(_$hash, tag.hashCode); + _$hash = $jf(_$hash); + return _$hash; + } + + @override + String toString() { + return (newBuiltValueToStringHelper(r'Object2') + ..add('name', name) + ..add('tag', tag)) + .toString(); + } +} + +class Object2Builder implements Builder, $Object2InterfaceBuilder { + _$Object2? _$v; + + String? _name; + String? get name => _$this._name; + set name(covariant String? name) => _$this._name = name; + + String? _tag; + String? get tag => _$this._tag; + set tag(covariant String? tag) => _$this._tag = tag; + + Object2Builder(); + + Object2Builder get _$this { + final $v = _$v; + if ($v != null) { + _name = $v.name; + _tag = $v.tag; + _$v = null; + } + return this; + } + + @override + void replace(covariant Object2 other) { + ArgumentError.checkNotNull(other, 'other'); + _$v = other as _$Object2; + } + + @override + void update(void Function(Object2Builder)? updates) { + if (updates != null) updates(this); + } + + @override + Object2 build() => _build(); + + _$Object2 _build() { + final _$result = + _$v ?? _$Object2._(name: BuiltValueNullFieldError.checkNotNull(name, r'Object2', 'name'), tag: tag); + replace(_$result); + return _$result; + } +} + +abstract mixin class $Object1InterfaceBuilder implements $Object2InterfaceBuilder { + void replace(covariant $Object1Interface other); + void update(void Function($Object1InterfaceBuilder) updates); + int? get id; + set id(covariant int? id); + + String? get name; + set name(covariant String? name); + + String? get tag; + set tag(covariant String? tag); +} + +class _$Object1 extends Object1 { + @override + final int id; + @override + final String name; + @override + final String? tag; + + factory _$Object1([void Function(Object1Builder)? updates]) => (Object1Builder()..update(updates))._build(); + + _$Object1._({required this.id, required this.name, this.tag}) : super._() { + BuiltValueNullFieldError.checkNotNull(id, r'Object1', 'id'); + BuiltValueNullFieldError.checkNotNull(name, r'Object1', 'name'); + } + + @override + Object1 rebuild(void Function(Object1Builder) updates) => (toBuilder()..update(updates)).build(); + + @override + Object1Builder toBuilder() => Object1Builder()..replace(this); + + @override + bool operator ==(Object other) { + if (identical(other, this)) return true; + return other is Object1 && id == other.id && name == other.name && tag == other.tag; + } + + @override + int get hashCode { + var _$hash = 0; + _$hash = $jc(_$hash, id.hashCode); + _$hash = $jc(_$hash, name.hashCode); + _$hash = $jc(_$hash, tag.hashCode); + _$hash = $jf(_$hash); + return _$hash; + } + + @override + String toString() { + return (newBuiltValueToStringHelper(r'Object1') + ..add('id', id) + ..add('name', name) + ..add('tag', tag)) + .toString(); + } +} + +class Object1Builder implements Builder, $Object1InterfaceBuilder { + _$Object1? _$v; + + int? _id; + int? get id => _$this._id; + set id(covariant int? id) => _$this._id = id; + + String? _name; + String? get name => _$this._name; + set name(covariant String? name) => _$this._name = name; + + String? _tag; + String? get tag => _$this._tag; + set tag(covariant String? tag) => _$this._tag = tag; + + Object1Builder(); + + Object1Builder get _$this { + final $v = _$v; + if ($v != null) { + _id = $v.id; + _name = $v.name; + _tag = $v.tag; + _$v = null; + } + return this; + } + + @override + void replace(covariant Object1 other) { + ArgumentError.checkNotNull(other, 'other'); + _$v = other as _$Object1; + } + + @override + void update(void Function(Object1Builder)? updates) { + if (updates != null) updates(this); + } + + @override + Object1 build() => _build(); + + _$Object1 _build() { + final _$result = _$v ?? + _$Object1._( + id: BuiltValueNullFieldError.checkNotNull(id, r'Object1', 'id'), + name: BuiltValueNullFieldError.checkNotNull(name, r'Object1', 'name'), + tag: tag); + replace(_$result); + return _$result; + } +} + +// ignore_for_file: deprecated_member_use_from_same_package,type=lint diff --git a/packages/dynamite/dynamite_end_to_end_test/lib/documentation.openapi.json b/packages/dynamite/dynamite_end_to_end_test/lib/documentation.openapi.json new file mode 100644 index 00000000000..cc7dcfa807c --- /dev/null +++ b/packages/dynamite/dynamite_end_to_end_test/lib/documentation.openapi.json @@ -0,0 +1,165 @@ +{ + "openapi": "3.0.0", + "info": { + "title": "Documentation test.", + "version": "1.0.0", + "summary": "Values are inspired by the petstore example.", + "description": "A sample API that uses a petstore as an example to demonstrate features in the OpenAPI 3.0 specification", + "termsOfService": "http://swagger.io/terms/", + "contact": { + "name": "Swagger API Team", + "email": "apiteam@swagger.io", + "url": "http://swagger.io" + }, + "license": { + "name": "Apache 2.0", + "url": "https://www.apache.org/licenses/LICENSE-2.0.html" + } + }, + "paths": { + "/": { + "get": { + "description": "Returns all pets from the system that the user has access to\nNam sed condimentum est. Maecenas tempor sagittis sapien, nec rhoncus sem sagittis sit amet. Aenean at gravida augue, ac iaculis sem. Curabitur odio lorem, ornare eget elementum nec, cursus id lectus. Duis mi turpis, pulvinar ac eros ac, tincidunt varius justo. In hac habitasse platea dictumst. Integer at adipiscing ante, a sagittis ligula. Aenean pharetra tempor ante molestie imperdiet. Vivamus id aliquam diam. Cras quis velit non tortor eleifend sagittis. Praesent at enim pharetra urna volutpat venenatis eget eget mauris. In eleifend fermentum facilisis. Praesent enim enim, gravida ac sodales sed, placerat id erat. Suspendisse lacus dolor, consectetur non augue vel, vehicula interdum libero. Morbi euismod sagittis libero sed lacinia.\n\nSed tempus felis lobortis leo pulvinar rutrum. Nam mattis velit nisl, eu condimentum ligula luctus nec. Phasellus semper velit eget aliquet faucibus. In a mattis elit. Phasellus vel urna viverra, condimentum lorem id, rhoncus nibh. Ut pellentesque posuere elementum. Sed a varius odio. Morbi rhoncus ligula libero, vel eleifend nunc tristique vitae. Fusce et sem dui. Aenean nec scelerisque tortor. Fusce malesuada accumsan magna vel tempus. Quisque mollis felis eu dolor tristique, sit amet auctor felis gravida. Sed libero lorem, molestie sed nisl in, accumsan tempor nisi. Fusce sollicitudin massa ut lacinia mattis. Sed vel eleifend lorem. Pellentesque vitae felis pretium, pulvinar elit eu, euismod sapien.\n", + "summary": "An optional, string summary, intended to apply to all operations in this path.", + "operationId": "findValues", + "parameters": [ + { + "name": "tags", + "in": "query", + "description": "tags to filter by", + "required": false, + "style": "form", + "schema": { + "type": "array", + "items": { + "type": "string" + } + } + }, + { + "name": "limit", + "in": "query", + "description": "maximum number of results to return", + "required": false, + "schema": { + "type": "integer", + "format": "int32" + } + } + ], + "responses": { + "default": { + "description": "finds an object", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Object1" + } + } + } + } + } + } + }, + "/other-endpoint": { + "post": { + "operationId": "non_root_client-set-mode", + "summary": "Do something really cool.", + "tags": [ + "non_root_client" + ], + "responses": { + "default": { + "description": "finds an object", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Object1" + } + } + } + } + } + } + } + }, + "components": { + "schemas": { + "Object1": { + "description": "A representation of the main object", + "allOf": [ + { + "$ref": "#/components/schemas/Object2" + }, + { + "type": "object", + "required": [ + "id" + ], + "properties": { + "id": { + "description": "The uuid in an UUIDv4 format", + "type": "integer", + "format": "int64" + } + } + } + ] + }, + "Object2": { + "description": "A representation of the second Object type", + "type": "object", + "required": [ + "name" + ], + "properties": { + "name": { + "description": "The name of this object.", + "type": "string" + }, + "tag": { + "description": "The tag of an Object2 object", + "type": "string" + } + } + }, + "Object3": { + "description": "An Object to test the documentation of someOf extension methods and typdefs.", + "oneOf": [ + { + "description": "A strings for something", + "type": "string" + }, + { + "description": "An integer for something", + "type": "integer" + } + ] + }, + "huntingSkill": { + "description": "The measured skill for hunting", + "type": "object", + "enum": [ + "clueless", + "lazy", + "adventurous", + "aggressive" + ] + }, + "Redirect": { + "description": "Redirect for the Object2", + "$ref": "#/components/schemas/Object2" + } + } + }, + "tags": [ + { + "name": "", + "description": "the root client used for root requests." + }, + { + "name": "non_root_client", + "description": "the non root client used for other requests." + } + ] +} diff --git a/packages/dynamite/dynamite_end_to_end_test/lib/enum.openapi.dart b/packages/dynamite/dynamite_end_to_end_test/lib/enum.openapi.dart index a5d49ee4fba..ec97e395d96 100644 --- a/packages/dynamite/dynamite_end_to_end_test/lib/enum.openapi.dart +++ b/packages/dynamite/dynamite_end_to_end_test/lib/enum.openapi.dart @@ -5,7 +5,8 @@ // ignore_for_file: public_member_api_docs, unreachable_switch_case // ignore_for_file: unused_element -// ignore_for_file: no_leading_underscores_for_library_prefixes +/// Enum tests Version: 0.0.1. +library; // ignore_for_file: no_leading_underscores_for_library_prefixes import 'package:built_collection/built_collection.dart'; import 'package:built_value/built_value.dart'; @@ -342,6 +343,7 @@ class _$WrappedEnum_IntegerSerializer implements PrimitiveSerializer