From 3e5e53ffa135135193dcbfca962003e691b0ab59 Mon Sep 17 00:00:00 2001 From: jld3103 Date: Tue, 14 Nov 2023 07:02:33 +0100 Subject: [PATCH] feat(dynamite_petstore_example): Init Signed-off-by: jld3103 --- .cspell/tools.txt | 4 + .github/workflows/generate.yaml | 10 + .gitmodules | 3 + commitlint.yaml | 1 + cspell.json | 1 + external/openapi-specification | 1 + .../dynamite_petstore_example/LICENSE | 1 + .../dynamite_petstore_example/README.md | 5 + .../dynamite_petstore_example/build.yaml | 18 + .../lib/petstore.openapi.dart | 400 +++++++++++++++ .../lib/petstore.openapi.g.dart | 468 ++++++++++++++++++ .../lib/petstore.openapi.json | 242 +++++++++ .../dynamite_petstore_example/pubspec.yaml | 23 + .../pubspec_overrides.yaml | 6 + tool/generate-dynamite-petstore-example.sh | 13 + 15 files changed, 1196 insertions(+) create mode 160000 external/openapi-specification create mode 120000 packages/dynamite/dynamite_petstore_example/LICENSE create mode 100644 packages/dynamite/dynamite_petstore_example/README.md create mode 100644 packages/dynamite/dynamite_petstore_example/build.yaml create mode 100644 packages/dynamite/dynamite_petstore_example/lib/petstore.openapi.dart create mode 100644 packages/dynamite/dynamite_petstore_example/lib/petstore.openapi.g.dart create mode 100644 packages/dynamite/dynamite_petstore_example/lib/petstore.openapi.json create mode 100644 packages/dynamite/dynamite_petstore_example/pubspec.yaml create mode 100644 packages/dynamite/dynamite_petstore_example/pubspec_overrides.yaml create mode 100755 tool/generate-dynamite-petstore-example.sh diff --git a/.cspell/tools.txt b/.cspell/tools.txt index 748b8456..42c7fde6 100644 --- a/.cspell/tools.txt +++ b/.cspell/tools.txt @@ -21,6 +21,7 @@ enduml euxo exiftool extglob +fehguy freedesktop fullpath gboolean @@ -45,9 +46,12 @@ libsqlite mipmap ndebug nodoc +nonintegers nproc openrelay openrelayprojectsecret +palo +petstore plantuml precache puml diff --git a/.github/workflows/generate.yaml b/.github/workflows/generate.yaml index 9450dd01..facdf496 100644 --- a/.github/workflows/generate.yaml +++ b/.github/workflows/generate.yaml @@ -34,6 +34,8 @@ jobs: uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4 with: fetch-depth: 0 + - name: Submodules + run: git submodule update --init --depth 0 - name: Install dart uses: dart-lang/setup-dart@b64355ae6ca0b5d484f0106a033dd1388965d06d # v1 @@ -48,6 +50,14 @@ jobs: exit 1 fi + - name: Generate dynamite petstore example + run: | + ./tool/generate-dynamite-petstore-example.sh + if [ -n "$(git status --porcelain)" ]; then + git --no-pager diff + exit 1 + fi + - name: Generate nextcloud run: | ./tool/generate-nextcloud.sh diff --git a/.gitmodules b/.gitmodules index e2a2b56d..5dfd682f 100644 --- a/.gitmodules +++ b/.gitmodules @@ -19,3 +19,6 @@ [submodule "external/nextcloud-notes"] path = external/nextcloud-notes url = https://github.com/nextcloud/notes +[submodule "external/openapi-specification"] + path = external/openapi-specification + url = https://github.com/OAI/OpenAPI-Specification.git diff --git a/commitlint.yaml b/commitlint.yaml index 0efcb504..ee82dc00 100644 --- a/commitlint.yaml +++ b/commitlint.yaml @@ -13,6 +13,7 @@ rules: - tool - app - dynamite + - dynamite_petstore_example - dynamite_runtime - dynamite_end_to_end_test - file_icons diff --git a/cspell.json b/cspell.json index 13b05dd0..7ccaa88e 100644 --- a/cspell.json +++ b/cspell.json @@ -11,6 +11,7 @@ "**/assets", "**/l10n/!(en.arb)", "external", + "packages/dynamite/dynamite_petstore_example/lib", "packages/file_icons/lib/src/data.dart", "packages/neon_lints/lib", "tool/dev/static" diff --git a/external/openapi-specification b/external/openapi-specification new file mode 160000 index 00000000..f73731dd --- /dev/null +++ b/external/openapi-specification @@ -0,0 +1 @@ +Subproject commit f73731dd34ffbf68512a363b579504b294986b53 diff --git a/packages/dynamite/dynamite_petstore_example/LICENSE b/packages/dynamite/dynamite_petstore_example/LICENSE new file mode 120000 index 00000000..c50ad9ad --- /dev/null +++ b/packages/dynamite/dynamite_petstore_example/LICENSE @@ -0,0 +1 @@ +../../../assets/AGPL-3.0.txt \ No newline at end of file diff --git a/packages/dynamite/dynamite_petstore_example/README.md b/packages/dynamite/dynamite_petstore_example/README.md new file mode 100644 index 00000000..8cdf1599 --- /dev/null +++ b/packages/dynamite/dynamite_petstore_example/README.md @@ -0,0 +1,5 @@ +# dynamite petstore example + +An example showcasing the [dynamite generator](../dynamite) for OpenAPI using the [Swagger Petstore](https://github.com/swagger-api/swagger-petstore). + +Because dynamite does not support dynamic authentication yet a [patch](patch.json) is applied to the specification to make it work. It will be removed once dynamite supports API key and Oauth 2.0 authentication. diff --git a/packages/dynamite/dynamite_petstore_example/build.yaml b/packages/dynamite/dynamite_petstore_example/build.yaml new file mode 100644 index 00000000..b27024ed --- /dev/null +++ b/packages/dynamite/dynamite_petstore_example/build.yaml @@ -0,0 +1,18 @@ +targets: + $default: + builders: + built_value_generator|built_value: + enabled: true + dynamite: + options: + pageWidth: 120 + analyzer_ignores: + - camel_case_types + - discarded_futures + - public_member_api_docs + - unreachable_switch_case + coverage_ignores: + - 'const .*\._\(\);' + - 'factory .*\.fromJson\(Map json\) => _jsonSerializers\.deserializeWith\(serializer, json\)!;' + - 'Map toJson\(\) => _jsonSerializers\.serializeWith\(serializer, this\)! as Map;' + - 'static BuiltSet<.*> get values => _\$.*Values;' diff --git a/packages/dynamite/dynamite_petstore_example/lib/petstore.openapi.dart b/packages/dynamite/dynamite_petstore_example/lib/petstore.openapi.dart new file mode 100644 index 00000000..2ca87c30 --- /dev/null +++ b/packages/dynamite/dynamite_petstore_example/lib/petstore.openapi.dart @@ -0,0 +1,400 @@ +// ignore_for_file: camel_case_types +// ignore_for_file: discarded_futures +// ignore_for_file: public_member_api_docs +// ignore_for_file: unreachable_switch_case +import 'dart:convert'; +import 'dart:typed_data'; + +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'; +import 'package:dynamite_runtime/built_value.dart'; +import 'package:dynamite_runtime/http_client.dart'; +import 'package:meta/meta.dart'; +import 'package:universal_io/io.dart'; + +part 'petstore.openapi.g.dart'; + +class Client extends DynamiteClient { + Client( + super.baseURL, { + super.baseHeaders, + super.userAgent, + super.httpClient, + super.cookieJar, + }); + + Client.fromClient(DynamiteClient client) + : super( + client.baseURL, + baseHeaders: client.baseHeaders, + httpClient: client.httpClient, + cookieJar: client.cookieJar, + authentications: client.authentications, + ); + + /// 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: + /// * 200: pet response + /// * default: unexpected error + /// + /// See: + /// * [findPetsRaw] for an experimental operation that returns a [DynamiteRawResponse] that can be serialized. + Future, void>> findPets({ + List? tags, + int? limit, + }) async { + final rawResponse = findPetsRaw( + tags: tags, + limit: limit, + ); + + return rawResponse.future; + } + + /// 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: + /// * 200: pet response + /// * default: unexpected error + /// + /// See: + /// * [findPets] for an operation that returns a [DynamiteResponse] with a stable API. + @experimental + DynamiteRawResponse, void> findPetsRaw({ + List? tags, + int? limit, + }) { + final _queryParameters = {}; + final _headers = { + 'Accept': 'application/json', + }; + Uint8List? _body; + + if (tags != null) { + _queryParameters['tags'] = tags.map((final e) => e); + } + if (limit != null) { + _queryParameters['limit'] = limit.toString(); + } + final _path = '/pets'; + final _uri = Uri(path: _path, queryParameters: _queryParameters.isNotEmpty ? _queryParameters : null); + + return DynamiteRawResponse, void>( + response: this.executeRequest( + 'get', + _uri, + _headers, + _body, + const {200}, + ), + bodyType: FullType(BuiltList, [FullType(Pet)]), + headersType: null, + serializers: _jsonSerializers, + ); + } + + /// Creates a new pet in the store. Duplicates are allowed. + /// + /// 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: + /// * 200: pet response + /// * default: unexpected error + /// + /// See: + /// * [addPetRaw] for an experimental operation that returns a [DynamiteRawResponse] that can be serialized. + Future> addPet({required NewPet newPet}) async { + final rawResponse = addPetRaw( + newPet: newPet, + ); + + return rawResponse.future; + } + + /// Creates a new pet in the store. Duplicates are allowed. + /// + /// 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: + /// * 200: pet response + /// * default: unexpected error + /// + /// See: + /// * [addPet] for an operation that returns a [DynamiteResponse] with a stable API. + @experimental + DynamiteRawResponse addPetRaw({required NewPet newPet}) { + final _queryParameters = {}; + final _headers = { + 'Accept': 'application/json', + }; + Uint8List? _body; + + _headers['Content-Type'] = 'application/json'; + _body = utf8.encode(json.encode(_jsonSerializers.serialize(newPet, specifiedType: const FullType(NewPet)))); + final _path = '/pets'; + final _uri = Uri(path: _path, queryParameters: _queryParameters.isNotEmpty ? _queryParameters : null); + + return DynamiteRawResponse( + response: this.executeRequest( + 'post', + _uri, + _headers, + _body, + const {200}, + ), + bodyType: FullType(Pet), + headersType: null, + serializers: _jsonSerializers, + ); + } + + /// Returns a user based on a single ID, if the user does not have access to the pet. + /// + /// 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: + /// * [id] ID of pet to fetch. + /// + /// Status codes: + /// * 200: pet response + /// * default: unexpected error + /// + /// See: + /// * [findPetByIdRaw] for an experimental operation that returns a [DynamiteRawResponse] that can be serialized. + Future> findPetById({required int id}) async { + final rawResponse = findPetByIdRaw( + id: id, + ); + + return rawResponse.future; + } + + /// Returns a user based on a single ID, if the user does not have access to the pet. + /// + /// 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: + /// * [id] ID of pet to fetch. + /// + /// Status codes: + /// * 200: pet response + /// * default: unexpected error + /// + /// See: + /// * [findPetById] for an operation that returns a [DynamiteResponse] with a stable API. + @experimental + DynamiteRawResponse findPetByIdRaw({required int id}) { + final _queryParameters = {}; + final _headers = { + 'Accept': 'application/json', + }; + Uint8List? _body; + + final _id = Uri.encodeQueryComponent(id.toString()); + final _path = '/pets/$_id'; + final _uri = Uri(path: _path, queryParameters: _queryParameters.isNotEmpty ? _queryParameters : null); + + return DynamiteRawResponse( + response: this.executeRequest( + 'get', + _uri, + _headers, + _body, + const {200}, + ), + bodyType: FullType(Pet), + headersType: null, + serializers: _jsonSerializers, + ); + } + + /// deletes a single pet based on the ID supplied. + /// + /// 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: + /// * [id] ID of pet to delete. + /// + /// Status codes: + /// * 204: pet deleted + /// * default: unexpected error + /// + /// See: + /// * [deletePetRaw] for an experimental operation that returns a [DynamiteRawResponse] that can be serialized. + Future> deletePet({required int id}) async { + final rawResponse = deletePetRaw( + id: id, + ); + + return rawResponse.future; + } + + /// deletes a single pet based on the ID supplied. + /// + /// 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: + /// * [id] ID of pet to delete. + /// + /// Status codes: + /// * 204: pet deleted + /// * default: unexpected error + /// + /// See: + /// * [deletePet] for an operation that returns a [DynamiteResponse] with a stable API. + @experimental + DynamiteRawResponse deletePetRaw({required int id}) { + final _queryParameters = {}; + final _headers = {}; + Uint8List? _body; + + final _id = Uri.encodeQueryComponent(id.toString()); + final _path = '/pets/$_id'; + final _uri = Uri(path: _path, queryParameters: _queryParameters.isNotEmpty ? _queryParameters : null); + + return DynamiteRawResponse( + response: this.executeRequest( + 'delete', + _uri, + _headers, + _body, + const {204}, + ), + bodyType: null, + headersType: null, + serializers: _jsonSerializers, + ); + } +} + +@BuiltValue(instantiable: false) +abstract interface class NewPetInterface { + String get name; + String? get tag; +} + +abstract class NewPet implements NewPetInterface, Built { + factory NewPet([void Function(NewPetBuilder)? b]) = _$NewPet; + + // coverage:ignore-start + const NewPet._(); + // coverage:ignore-end + + // coverage:ignore-start + factory NewPet.fromJson(Map json) => _jsonSerializers.deserializeWith(serializer, json)!; + // coverage:ignore-end + + // coverage:ignore-start + Map toJson() => _jsonSerializers.serializeWith(serializer, this)! as Map; + // coverage:ignore-end + + static Serializer get serializer => _$newPetSerializer; +} + +@BuiltValue(instantiable: false) +abstract interface class Pet_1Interface { + int get id; +} + +@BuiltValue(instantiable: false) +abstract interface class PetInterface implements NewPetInterface, Pet_1Interface {} + +abstract class Pet implements PetInterface, Built { + factory Pet([void Function(PetBuilder)? b]) = _$Pet; + + // coverage:ignore-start + const Pet._(); + // coverage:ignore-end + + // coverage:ignore-start + factory Pet.fromJson(Map json) => _jsonSerializers.deserializeWith(serializer, json)!; + // coverage:ignore-end + + // coverage:ignore-start + Map toJson() => _jsonSerializers.serializeWith(serializer, this)! as Map; + // coverage:ignore-end + + static Serializer get serializer => _$petSerializer; +} + +@BuiltValue(instantiable: false) +abstract interface class ErrorInterface { + int get code; + String get message; +} + +abstract class Error implements ErrorInterface, Built { + factory Error([void Function(ErrorBuilder)? b]) = _$Error; + + // coverage:ignore-start + const Error._(); + // coverage:ignore-end + + // coverage:ignore-start + factory Error.fromJson(Map json) => _jsonSerializers.deserializeWith(serializer, json)!; + // coverage:ignore-end + + // coverage:ignore-start + Map toJson() => _jsonSerializers.serializeWith(serializer, this)! as Map; + // coverage:ignore-end + + static Serializer get serializer => _$errorSerializer; +} + +// coverage:ignore-start +final Serializers _serializers = (Serializers().toBuilder() + ..addBuilderFactory(FullType(BuiltList, [FullType(String)]), ListBuilder.new) + ..addBuilderFactory(FullType(Pet), Pet.new) + ..add(Pet.serializer) + ..addBuilderFactory(FullType(NewPet), NewPet.new) + ..add(NewPet.serializer) + ..addBuilderFactory(FullType(BuiltList, [FullType(Pet)]), ListBuilder.new) + ..addBuilderFactory(FullType(Error), Error.new) + ..add(Error.serializer)) + .build(); + +final Serializers _jsonSerializers = (_serializers.toBuilder() + ..add(DynamiteDoubleSerializer()) + ..addPlugin(StandardJsonPlugin()) + ..addPlugin(const ContentStringPlugin())) + .build(); +// coverage:ignore-end diff --git a/packages/dynamite/dynamite_petstore_example/lib/petstore.openapi.g.dart b/packages/dynamite/dynamite_petstore_example/lib/petstore.openapi.g.dart new file mode 100644 index 00000000..6786ccb0 --- /dev/null +++ b/packages/dynamite/dynamite_petstore_example/lib/petstore.openapi.g.dart @@ -0,0 +1,468 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'petstore.openapi.dart'; + +// ************************************************************************** +// BuiltValueGenerator +// ************************************************************************** + +Serializer _$newPetSerializer = _$NewPetSerializer(); +Serializer _$petSerializer = _$PetSerializer(); +Serializer _$errorSerializer = _$ErrorSerializer(); + +class _$NewPetSerializer implements StructuredSerializer { + @override + final Iterable types = const [NewPet, _$NewPet]; + @override + final String wireName = 'NewPet'; + + @override + Iterable serialize(Serializers serializers, NewPet 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 + NewPet deserialize(Serializers serializers, Iterable serialized, + {FullType specifiedType = FullType.unspecified}) { + final result = NewPetBuilder(); + + 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 _$PetSerializer implements StructuredSerializer { + @override + final Iterable types = const [Pet, _$Pet]; + @override + final String wireName = 'Pet'; + + @override + Iterable serialize(Serializers serializers, Pet object, {FullType specifiedType = FullType.unspecified}) { + final result = [ + 'name', + serializers.serialize(object.name, specifiedType: const FullType(String)), + 'id', + serializers.serialize(object.id, specifiedType: const FullType(int)), + ]; + Object? value; + value = object.tag; + if (value != null) { + result + ..add('tag') + ..add(serializers.serialize(value, specifiedType: const FullType(String))); + } + return result; + } + + @override + Pet deserialize(Serializers serializers, Iterable serialized, + {FullType specifiedType = FullType.unspecified}) { + final result = PetBuilder(); + + 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; + case 'id': + result.id = serializers.deserialize(value, specifiedType: const FullType(int))! as int; + break; + } + } + + return result.build(); + } +} + +class _$ErrorSerializer implements StructuredSerializer { + @override + final Iterable types = const [Error, _$Error]; + @override + final String wireName = 'Error'; + + @override + Iterable serialize(Serializers serializers, Error object, {FullType specifiedType = FullType.unspecified}) { + final result = [ + 'code', + serializers.serialize(object.code, specifiedType: const FullType(int)), + 'message', + serializers.serialize(object.message, specifiedType: const FullType(String)), + ]; + + return result; + } + + @override + Error deserialize(Serializers serializers, Iterable serialized, + {FullType specifiedType = FullType.unspecified}) { + final result = ErrorBuilder(); + + final iterator = serialized.iterator; + while (iterator.moveNext()) { + final key = iterator.current! as String; + iterator.moveNext(); + final Object? value = iterator.current; + switch (key) { + case 'code': + result.code = serializers.deserialize(value, specifiedType: const FullType(int))! as int; + break; + case 'message': + result.message = serializers.deserialize(value, specifiedType: const FullType(String))! as String; + break; + } + } + + return result.build(); + } +} + +abstract mixin class NewPetInterfaceBuilder { + void replace(NewPetInterface other); + void update(void Function(NewPetInterfaceBuilder) updates); + String? get name; + set name(String? name); + + String? get tag; + set tag(String? tag); +} + +class _$NewPet extends NewPet { + @override + final String name; + @override + final String? tag; + + factory _$NewPet([void Function(NewPetBuilder)? updates]) => (NewPetBuilder()..update(updates))._build(); + + _$NewPet._({required this.name, this.tag}) : super._() { + BuiltValueNullFieldError.checkNotNull(name, r'NewPet', 'name'); + } + + @override + NewPet rebuild(void Function(NewPetBuilder) updates) => (toBuilder()..update(updates)).build(); + + @override + NewPetBuilder toBuilder() => NewPetBuilder()..replace(this); + + @override + bool operator ==(Object other) { + if (identical(other, this)) return true; + return other is NewPet && 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'NewPet') + ..add('name', name) + ..add('tag', tag)) + .toString(); + } +} + +class NewPetBuilder implements Builder, NewPetInterfaceBuilder { + _$NewPet? _$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; + + NewPetBuilder(); + + NewPetBuilder get _$this { + final $v = _$v; + if ($v != null) { + _name = $v.name; + _tag = $v.tag; + _$v = null; + } + return this; + } + + @override + void replace(covariant NewPet other) { + ArgumentError.checkNotNull(other, 'other'); + _$v = other as _$NewPet; + } + + @override + void update(void Function(NewPetBuilder)? updates) { + if (updates != null) updates(this); + } + + @override + NewPet build() => _build(); + + _$NewPet _build() { + final _$result = _$v ?? _$NewPet._(name: BuiltValueNullFieldError.checkNotNull(name, r'NewPet', 'name'), tag: tag); + replace(_$result); + return _$result; + } +} + +abstract mixin class Pet_1InterfaceBuilder { + void replace(Pet_1Interface other); + void update(void Function(Pet_1InterfaceBuilder) updates); + int? get id; + set id(int? id); +} + +abstract mixin class PetInterfaceBuilder implements NewPetInterfaceBuilder, Pet_1InterfaceBuilder { + void replace(covariant PetInterface other); + void update(void Function(PetInterfaceBuilder) updates); + String? get name; + set name(covariant String? name); + + String? get tag; + set tag(covariant String? tag); + + int? get id; + set id(covariant int? id); +} + +class _$Pet extends Pet { + @override + final String name; + @override + final String? tag; + @override + final int id; + + factory _$Pet([void Function(PetBuilder)? updates]) => (PetBuilder()..update(updates))._build(); + + _$Pet._({required this.name, this.tag, required this.id}) : super._() { + BuiltValueNullFieldError.checkNotNull(name, r'Pet', 'name'); + BuiltValueNullFieldError.checkNotNull(id, r'Pet', 'id'); + } + + @override + Pet rebuild(void Function(PetBuilder) updates) => (toBuilder()..update(updates)).build(); + + @override + PetBuilder toBuilder() => PetBuilder()..replace(this); + + @override + bool operator ==(Object other) { + if (identical(other, this)) return true; + return other is Pet && name == other.name && tag == other.tag && id == other.id; + } + + @override + int get hashCode { + var _$hash = 0; + _$hash = $jc(_$hash, name.hashCode); + _$hash = $jc(_$hash, tag.hashCode); + _$hash = $jc(_$hash, id.hashCode); + _$hash = $jf(_$hash); + return _$hash; + } + + @override + String toString() { + return (newBuiltValueToStringHelper(r'Pet') + ..add('name', name) + ..add('tag', tag) + ..add('id', id)) + .toString(); + } +} + +class PetBuilder implements Builder, PetInterfaceBuilder { + _$Pet? _$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; + + int? _id; + int? get id => _$this._id; + set id(covariant int? id) => _$this._id = id; + + PetBuilder(); + + PetBuilder get _$this { + final $v = _$v; + if ($v != null) { + _name = $v.name; + _tag = $v.tag; + _id = $v.id; + _$v = null; + } + return this; + } + + @override + void replace(covariant Pet other) { + ArgumentError.checkNotNull(other, 'other'); + _$v = other as _$Pet; + } + + @override + void update(void Function(PetBuilder)? updates) { + if (updates != null) updates(this); + } + + @override + Pet build() => _build(); + + _$Pet _build() { + final _$result = _$v ?? + _$Pet._( + name: BuiltValueNullFieldError.checkNotNull(name, r'Pet', 'name'), + tag: tag, + id: BuiltValueNullFieldError.checkNotNull(id, r'Pet', 'id')); + replace(_$result); + return _$result; + } +} + +abstract mixin class ErrorInterfaceBuilder { + void replace(ErrorInterface other); + void update(void Function(ErrorInterfaceBuilder) updates); + int? get code; + set code(int? code); + + String? get message; + set message(String? message); +} + +class _$Error extends Error { + @override + final int code; + @override + final String message; + + factory _$Error([void Function(ErrorBuilder)? updates]) => (ErrorBuilder()..update(updates))._build(); + + _$Error._({required this.code, required this.message}) : super._() { + BuiltValueNullFieldError.checkNotNull(code, r'Error', 'code'); + BuiltValueNullFieldError.checkNotNull(message, r'Error', 'message'); + } + + @override + Error rebuild(void Function(ErrorBuilder) updates) => (toBuilder()..update(updates)).build(); + + @override + ErrorBuilder toBuilder() => ErrorBuilder()..replace(this); + + @override + bool operator ==(Object other) { + if (identical(other, this)) return true; + return other is Error && code == other.code && message == other.message; + } + + @override + int get hashCode { + var _$hash = 0; + _$hash = $jc(_$hash, code.hashCode); + _$hash = $jc(_$hash, message.hashCode); + _$hash = $jf(_$hash); + return _$hash; + } + + @override + String toString() { + return (newBuiltValueToStringHelper(r'Error') + ..add('code', code) + ..add('message', message)) + .toString(); + } +} + +class ErrorBuilder implements Builder, ErrorInterfaceBuilder { + _$Error? _$v; + + int? _code; + int? get code => _$this._code; + set code(covariant int? code) => _$this._code = code; + + String? _message; + String? get message => _$this._message; + set message(covariant String? message) => _$this._message = message; + + ErrorBuilder(); + + ErrorBuilder get _$this { + final $v = _$v; + if ($v != null) { + _code = $v.code; + _message = $v.message; + _$v = null; + } + return this; + } + + @override + void replace(covariant Error other) { + ArgumentError.checkNotNull(other, 'other'); + _$v = other as _$Error; + } + + @override + void update(void Function(ErrorBuilder)? updates) { + if (updates != null) updates(this); + } + + @override + Error build() => _build(); + + _$Error _build() { + final _$result = _$v ?? + _$Error._( + code: BuiltValueNullFieldError.checkNotNull(code, r'Error', 'code'), + message: BuiltValueNullFieldError.checkNotNull(message, r'Error', 'message')); + replace(_$result); + return _$result; + } +} + +// ignore_for_file: deprecated_member_use_from_same_package,type=lint diff --git a/packages/dynamite/dynamite_petstore_example/lib/petstore.openapi.json b/packages/dynamite/dynamite_petstore_example/lib/petstore.openapi.json new file mode 100644 index 00000000..420eede6 --- /dev/null +++ b/packages/dynamite/dynamite_petstore_example/lib/petstore.openapi.json @@ -0,0 +1,242 @@ +{ + "openapi": "3.0.0", + "info": { + "version": "1.0.0", + "title": "Swagger Petstore", + "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" + } + }, + "servers": [ + { + "url": "https://petstore.swagger.io/v2" + } + ], + "paths": { + "/pets": { + "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", + "operationId": "findPets", + "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": { + "200": { + "description": "pet response", + "content": { + "application/json": { + "schema": { + "type": "array", + "items": { + "$ref": "#/components/schemas/Pet" + } + } + } + } + }, + "default": { + "description": "unexpected error", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Error" + } + } + } + } + } + }, + "post": { + "description": "Creates a new pet in the store. Duplicates are allowed", + "operationId": "addPet", + "requestBody": { + "description": "Pet to add to the store", + "required": true, + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/NewPet" + } + } + } + }, + "responses": { + "200": { + "description": "pet response", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Pet" + } + } + } + }, + "default": { + "description": "unexpected error", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Error" + } + } + } + } + } + } + }, + "/pets/{id}": { + "get": { + "description": "Returns a user based on a single ID, if the user does not have access to the pet", + "operationId": "find pet by id", + "parameters": [ + { + "name": "id", + "in": "path", + "description": "ID of pet to fetch", + "required": true, + "schema": { + "type": "integer", + "format": "int64" + } + } + ], + "responses": { + "200": { + "description": "pet response", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Pet" + } + } + } + }, + "default": { + "description": "unexpected error", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Error" + } + } + } + } + } + }, + "delete": { + "description": "deletes a single pet based on the ID supplied", + "operationId": "deletePet", + "parameters": [ + { + "name": "id", + "in": "path", + "description": "ID of pet to delete", + "required": true, + "schema": { + "type": "integer", + "format": "int64" + } + } + ], + "responses": { + "204": { + "description": "pet deleted" + }, + "default": { + "description": "unexpected error", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Error" + } + } + } + } + } + } + } + }, + "components": { + "schemas": { + "Pet": { + "allOf": [ + { + "$ref": "#/components/schemas/NewPet" + }, + { + "type": "object", + "required": [ + "id" + ], + "properties": { + "id": { + "type": "integer", + "format": "int64" + } + } + } + ] + }, + "NewPet": { + "type": "object", + "required": [ + "name" + ], + "properties": { + "name": { + "type": "string" + }, + "tag": { + "type": "string" + } + } + }, + "Error": { + "type": "object", + "required": [ + "code", + "message" + ], + "properties": { + "code": { + "type": "integer", + "format": "int32" + }, + "message": { + "type": "string" + } + } + } + } + } +} \ No newline at end of file diff --git a/packages/dynamite/dynamite_petstore_example/pubspec.yaml b/packages/dynamite/dynamite_petstore_example/pubspec.yaml new file mode 100644 index 00000000..5a8d5f29 --- /dev/null +++ b/packages/dynamite/dynamite_petstore_example/pubspec.yaml @@ -0,0 +1,23 @@ +name: dynamite_petstore_example +description: An example showing how to use dynamite for the Petstore example API. +version: 1.0.0 +publish_to: none + +environment: + sdk: '>=3.1.3 <4.0.0' + +dependencies: + built_collection: ^5.0.0 + built_value: ^8.0.1 + dynamite_runtime: + git: + url: https://github.com/nextcloud/neon + path: packages/dynamite/dynamite_runtime + +dev_dependencies: + build_runner: ^2.4.6 + built_value_generator: ^8.7.0 + dynamite: + git: + url: https://github.com/nextcloud/neon + path: packages/dynamite/dynamite diff --git a/packages/dynamite/dynamite_petstore_example/pubspec_overrides.yaml b/packages/dynamite/dynamite_petstore_example/pubspec_overrides.yaml new file mode 100644 index 00000000..b0b6cc9f --- /dev/null +++ b/packages/dynamite/dynamite_petstore_example/pubspec_overrides.yaml @@ -0,0 +1,6 @@ +# melos_managed_dependency_overrides: dynamite,dynamite_runtime +dependency_overrides: + dynamite: + path: ../dynamite + dynamite_runtime: + path: ../dynamite_runtime diff --git a/tool/generate-dynamite-petstore-example.sh b/tool/generate-dynamite-petstore-example.sh new file mode 100755 index 00000000..fd9ed6ef --- /dev/null +++ b/tool/generate-dynamite-petstore-example.sh @@ -0,0 +1,13 @@ +#!/bin/bash +set -euxo pipefail +cd "$(dirname "$0")/.." + +cp external/openapi-specification/examples/v3.0/petstore-expanded.json packages/dynamite/dynamite_petstore_example/lib/petstore.openapi.json + +( + cd packages/dynamite/dynamite_petstore_example + rm -rf .dart_tool/build/generated/dynamite + fvm dart pub run build_runner build --delete-conflicting-outputs + fvm dart fix --apply lib/ + melos run format +)