From c65521f0411b38b55a58a887dc8bd22a67c02cbe Mon Sep 17 00:00:00 2001 From: Nikolas Rimikis Date: Sat, 2 Sep 2023 20:32:44 +0200 Subject: [PATCH] feat(dynamite): make models immutable Signed-off-by: Nikolas Rimikis --- .../dynamite/dynamite/lib/src/models/components.dart | 4 +++- .../dynamite/lib/src/models/discriminator.dart | 4 +++- packages/dynamite/dynamite/lib/src/models/header.dart | 4 +++- packages/dynamite/dynamite/lib/src/models/info.dart | 4 +++- packages/dynamite/dynamite/lib/src/models/license.dart | 4 +++- .../dynamite/dynamite/lib/src/models/media_type.dart | 4 +++- .../dynamite/dynamite/lib/src/models/open_api.dart | 4 +++- .../dynamite/dynamite/lib/src/models/operation.dart | 4 +++- .../dynamite/dynamite/lib/src/models/parameter.dart | 4 +++- .../dynamite/dynamite/lib/src/models/path_item.dart | 4 +++- .../dynamite/dynamite/lib/src/models/request_body.dart | 4 +++- .../dynamite/dynamite/lib/src/models/response.dart | 4 +++- packages/dynamite/dynamite/lib/src/models/schema.dart | 10 +++++++--- .../dynamite/lib/src/models/security_scheme.dart | 4 +++- packages/dynamite/dynamite/lib/src/models/server.dart | 4 +++- .../dynamite/lib/src/models/server_variable.dart | 4 +++- packages/dynamite/dynamite/lib/src/models/tag.dart | 4 +++- 17 files changed, 55 insertions(+), 19 deletions(-) diff --git a/packages/dynamite/dynamite/lib/src/models/components.dart b/packages/dynamite/dynamite/lib/src/models/components.dart index e995236a..ab168eb1 100644 --- a/packages/dynamite/dynamite/lib/src/models/components.dart +++ b/packages/dynamite/dynamite/lib/src/models/components.dart @@ -1,12 +1,14 @@ import 'package:dynamite/src/models/schema.dart'; import 'package:dynamite/src/models/security_scheme.dart'; import 'package:json_annotation/json_annotation.dart'; +import 'package:meta/meta.dart'; part 'components.g.dart'; @JsonSerializable() +@immutable class Components { - Components({ + const Components({ this.securitySchemes, this.schemas, }); diff --git a/packages/dynamite/dynamite/lib/src/models/discriminator.dart b/packages/dynamite/dynamite/lib/src/models/discriminator.dart index 5968aeb6..f1bfe774 100644 --- a/packages/dynamite/dynamite/lib/src/models/discriminator.dart +++ b/packages/dynamite/dynamite/lib/src/models/discriminator.dart @@ -1,10 +1,12 @@ import 'package:json_annotation/json_annotation.dart'; +import 'package:meta/meta.dart'; part 'discriminator.g.dart'; @JsonSerializable() +@immutable class Discriminator { - Discriminator({ + const Discriminator({ required this.propertyName, this.mapping, }); diff --git a/packages/dynamite/dynamite/lib/src/models/header.dart b/packages/dynamite/dynamite/lib/src/models/header.dart index 9bd47efa..9e8a21e8 100644 --- a/packages/dynamite/dynamite/lib/src/models/header.dart +++ b/packages/dynamite/dynamite/lib/src/models/header.dart @@ -1,11 +1,13 @@ import 'package:dynamite/src/models/schema.dart'; import 'package:json_annotation/json_annotation.dart'; +import 'package:meta/meta.dart'; part 'header.g.dart'; @JsonSerializable() +@immutable class Header { - Header({ + const Header({ this.description, this.required, this.schema, diff --git a/packages/dynamite/dynamite/lib/src/models/info.dart b/packages/dynamite/dynamite/lib/src/models/info.dart index 59d2f97a..b648d6ba 100644 --- a/packages/dynamite/dynamite/lib/src/models/info.dart +++ b/packages/dynamite/dynamite/lib/src/models/info.dart @@ -1,11 +1,13 @@ import 'package:dynamite/src/models/license.dart'; import 'package:json_annotation/json_annotation.dart'; +import 'package:meta/meta.dart'; part 'info.g.dart'; @JsonSerializable() +@immutable class Info { - Info({ + const Info({ required this.title, required this.version, required this.license, diff --git a/packages/dynamite/dynamite/lib/src/models/license.dart b/packages/dynamite/dynamite/lib/src/models/license.dart index 3bf19718..f1a158a3 100644 --- a/packages/dynamite/dynamite/lib/src/models/license.dart +++ b/packages/dynamite/dynamite/lib/src/models/license.dart @@ -1,10 +1,12 @@ import 'package:json_annotation/json_annotation.dart'; +import 'package:meta/meta.dart'; part 'license.g.dart'; @JsonSerializable() +@immutable class License { - License({ + const License({ required this.name, this.identifier, this.url, diff --git a/packages/dynamite/dynamite/lib/src/models/media_type.dart b/packages/dynamite/dynamite/lib/src/models/media_type.dart index 4172cbae..feebad58 100644 --- a/packages/dynamite/dynamite/lib/src/models/media_type.dart +++ b/packages/dynamite/dynamite/lib/src/models/media_type.dart @@ -1,11 +1,13 @@ import 'package:dynamite/src/models/schema.dart'; import 'package:json_annotation/json_annotation.dart'; +import 'package:meta/meta.dart'; part 'media_type.g.dart'; @JsonSerializable() +@immutable class MediaType { - MediaType({ + const MediaType({ this.schema, }); diff --git a/packages/dynamite/dynamite/lib/src/models/open_api.dart b/packages/dynamite/dynamite/lib/src/models/open_api.dart index 45101099..a58ac874 100644 --- a/packages/dynamite/dynamite/lib/src/models/open_api.dart +++ b/packages/dynamite/dynamite/lib/src/models/open_api.dart @@ -6,12 +6,14 @@ import 'package:dynamite/src/models/security_requirement.dart'; import 'package:dynamite/src/models/server.dart'; import 'package:dynamite/src/models/tag.dart'; import 'package:json_annotation/json_annotation.dart'; +import 'package:meta/meta.dart'; part 'open_api.g.dart'; @JsonSerializable() +@immutable class OpenAPI { - OpenAPI({ + const OpenAPI({ required this.version, required this.info, this.servers, diff --git a/packages/dynamite/dynamite/lib/src/models/operation.dart b/packages/dynamite/dynamite/lib/src/models/operation.dart index 765deb01..95f8c57b 100644 --- a/packages/dynamite/dynamite/lib/src/models/operation.dart +++ b/packages/dynamite/dynamite/lib/src/models/operation.dart @@ -4,12 +4,14 @@ import 'package:dynamite/src/models/response.dart'; import 'package:dynamite/src/models/responses.dart'; import 'package:dynamite/src/models/security_requirement.dart'; import 'package:json_annotation/json_annotation.dart'; +import 'package:meta/meta.dart'; part 'operation.g.dart'; @JsonSerializable() +@immutable class Operation { - Operation({ + const Operation({ this.operationId, this.summary, this.description, diff --git a/packages/dynamite/dynamite/lib/src/models/parameter.dart b/packages/dynamite/dynamite/lib/src/models/parameter.dart index 86dc7340..eec63e13 100644 --- a/packages/dynamite/dynamite/lib/src/models/parameter.dart +++ b/packages/dynamite/dynamite/lib/src/models/parameter.dart @@ -1,11 +1,13 @@ import 'package:dynamite/src/models/schema.dart'; import 'package:json_annotation/json_annotation.dart'; +import 'package:meta/meta.dart'; part 'parameter.g.dart'; @JsonSerializable() +@immutable class Parameter { - Parameter({ + const Parameter({ required this.name, required this.in_, this.description, diff --git a/packages/dynamite/dynamite/lib/src/models/path_item.dart b/packages/dynamite/dynamite/lib/src/models/path_item.dart index 5d75e819..2d7d3fea 100644 --- a/packages/dynamite/dynamite/lib/src/models/path_item.dart +++ b/packages/dynamite/dynamite/lib/src/models/path_item.dart @@ -1,12 +1,14 @@ import 'package:dynamite/src/models/operation.dart'; import 'package:dynamite/src/models/parameter.dart'; import 'package:json_annotation/json_annotation.dart'; +import 'package:meta/meta.dart'; part 'path_item.g.dart'; @JsonSerializable() +@immutable class PathItem { - PathItem({ + const PathItem({ this.description, this.parameters, this.get, diff --git a/packages/dynamite/dynamite/lib/src/models/request_body.dart b/packages/dynamite/dynamite/lib/src/models/request_body.dart index 1fbe60eb..2aa631df 100644 --- a/packages/dynamite/dynamite/lib/src/models/request_body.dart +++ b/packages/dynamite/dynamite/lib/src/models/request_body.dart @@ -1,11 +1,13 @@ import 'package:dynamite/src/models/media_type.dart'; import 'package:json_annotation/json_annotation.dart'; +import 'package:meta/meta.dart'; part 'request_body.g.dart'; @JsonSerializable() +@immutable class RequestBody { - RequestBody({ + const RequestBody({ this.description, this.content, this.required, diff --git a/packages/dynamite/dynamite/lib/src/models/response.dart b/packages/dynamite/dynamite/lib/src/models/response.dart index 693e35c9..c4e3764d 100644 --- a/packages/dynamite/dynamite/lib/src/models/response.dart +++ b/packages/dynamite/dynamite/lib/src/models/response.dart @@ -1,12 +1,14 @@ import 'package:dynamite/src/models/header.dart'; import 'package:dynamite/src/models/media_type.dart'; import 'package:json_annotation/json_annotation.dart'; +import 'package:meta/meta.dart'; part 'response.g.dart'; @JsonSerializable() +@immutable class Response { - Response({ + const Response({ required this.description, this.content, this.headers, diff --git a/packages/dynamite/dynamite/lib/src/models/schema.dart b/packages/dynamite/dynamite/lib/src/models/schema.dart index 1db56028..f168eeb9 100644 --- a/packages/dynamite/dynamite/lib/src/models/schema.dart +++ b/packages/dynamite/dynamite/lib/src/models/schema.dart @@ -1,11 +1,13 @@ import 'package:dynamite/src/models/discriminator.dart'; import 'package:json_annotation/json_annotation.dart'; +import 'package:meta/meta.dart'; part 'schema.g.dart'; @JsonSerializable() +@immutable class Schema { - Schema({ + const Schema({ this.ref, this.oneOf, this.anyOf, @@ -85,7 +87,9 @@ class Schema { bool get isContentString => type == 'string' && (contentMediaType?.isNotEmpty ?? false) && contentSchema != null; } -class EmptySchema extends Schema {} +class EmptySchema extends Schema { + const EmptySchema(); +} Schema? _parseAdditionalProperties(final dynamic data) { if (data == null) { @@ -93,7 +97,7 @@ Schema? _parseAdditionalProperties(final dynamic data) { } if (data is bool) { - return data ? EmptySchema() : null; + return data ? const EmptySchema() : null; } if (data is Map) { diff --git a/packages/dynamite/dynamite/lib/src/models/security_scheme.dart b/packages/dynamite/dynamite/lib/src/models/security_scheme.dart index df8b4417..90936fc9 100644 --- a/packages/dynamite/dynamite/lib/src/models/security_scheme.dart +++ b/packages/dynamite/dynamite/lib/src/models/security_scheme.dart @@ -1,10 +1,12 @@ import 'package:json_annotation/json_annotation.dart'; +import 'package:meta/meta.dart'; part 'security_scheme.g.dart'; @JsonSerializable() +@immutable class SecurityScheme { - SecurityScheme({ + const SecurityScheme({ required this.type, this.description, this.scheme, diff --git a/packages/dynamite/dynamite/lib/src/models/server.dart b/packages/dynamite/dynamite/lib/src/models/server.dart index 7feeac49..0a3f7270 100644 --- a/packages/dynamite/dynamite/lib/src/models/server.dart +++ b/packages/dynamite/dynamite/lib/src/models/server.dart @@ -1,11 +1,13 @@ import 'package:dynamite/src/models/server_variable.dart'; import 'package:json_annotation/json_annotation.dart'; +import 'package:meta/meta.dart'; part 'server.g.dart'; @JsonSerializable() +@immutable class Server { - Server({ + const Server({ required this.url, this.variables, }); diff --git a/packages/dynamite/dynamite/lib/src/models/server_variable.dart b/packages/dynamite/dynamite/lib/src/models/server_variable.dart index 52788812..3be2f869 100644 --- a/packages/dynamite/dynamite/lib/src/models/server_variable.dart +++ b/packages/dynamite/dynamite/lib/src/models/server_variable.dart @@ -1,10 +1,12 @@ import 'package:json_annotation/json_annotation.dart'; +import 'package:meta/meta.dart'; part 'server_variable.g.dart'; @JsonSerializable() +@immutable class ServerVariable { - ServerVariable({ + const ServerVariable({ required this.default_, this.enum_, this.description, diff --git a/packages/dynamite/dynamite/lib/src/models/tag.dart b/packages/dynamite/dynamite/lib/src/models/tag.dart index 3ade793a..7943a1b2 100644 --- a/packages/dynamite/dynamite/lib/src/models/tag.dart +++ b/packages/dynamite/dynamite/lib/src/models/tag.dart @@ -1,10 +1,12 @@ import 'package:json_annotation/json_annotation.dart'; +import 'package:meta/meta.dart'; part 'tag.g.dart'; @JsonSerializable() +@immutable class Tag { - Tag({ + const Tag({ required this.name, this.description, });