Browse Source

feat(dynamite): make models immutable

Signed-off-by: Nikolas Rimikis <leptopoda@users.noreply.github.com>
pull/694/head
Nikolas Rimikis 1 year ago
parent
commit
c65521f041
No known key found for this signature in database
GPG Key ID: 85ED1DE9786A4FF2
  1. 4
      packages/dynamite/dynamite/lib/src/models/components.dart
  2. 4
      packages/dynamite/dynamite/lib/src/models/discriminator.dart
  3. 4
      packages/dynamite/dynamite/lib/src/models/header.dart
  4. 4
      packages/dynamite/dynamite/lib/src/models/info.dart
  5. 4
      packages/dynamite/dynamite/lib/src/models/license.dart
  6. 4
      packages/dynamite/dynamite/lib/src/models/media_type.dart
  7. 4
      packages/dynamite/dynamite/lib/src/models/open_api.dart
  8. 4
      packages/dynamite/dynamite/lib/src/models/operation.dart
  9. 4
      packages/dynamite/dynamite/lib/src/models/parameter.dart
  10. 4
      packages/dynamite/dynamite/lib/src/models/path_item.dart
  11. 4
      packages/dynamite/dynamite/lib/src/models/request_body.dart
  12. 4
      packages/dynamite/dynamite/lib/src/models/response.dart
  13. 10
      packages/dynamite/dynamite/lib/src/models/schema.dart
  14. 4
      packages/dynamite/dynamite/lib/src/models/security_scheme.dart
  15. 4
      packages/dynamite/dynamite/lib/src/models/server.dart
  16. 4
      packages/dynamite/dynamite/lib/src/models/server_variable.dart
  17. 4
      packages/dynamite/dynamite/lib/src/models/tag.dart

4
packages/dynamite/dynamite/lib/src/models/components.dart

@ -1,12 +1,14 @@
import 'package:dynamite/src/models/schema.dart'; import 'package:dynamite/src/models/schema.dart';
import 'package:dynamite/src/models/security_scheme.dart'; import 'package:dynamite/src/models/security_scheme.dart';
import 'package:json_annotation/json_annotation.dart'; import 'package:json_annotation/json_annotation.dart';
import 'package:meta/meta.dart';
part 'components.g.dart'; part 'components.g.dart';
@JsonSerializable() @JsonSerializable()
@immutable
class Components { class Components {
Components({ const Components({
this.securitySchemes, this.securitySchemes,
this.schemas, this.schemas,
}); });

4
packages/dynamite/dynamite/lib/src/models/discriminator.dart

@ -1,10 +1,12 @@
import 'package:json_annotation/json_annotation.dart'; import 'package:json_annotation/json_annotation.dart';
import 'package:meta/meta.dart';
part 'discriminator.g.dart'; part 'discriminator.g.dart';
@JsonSerializable() @JsonSerializable()
@immutable
class Discriminator { class Discriminator {
Discriminator({ const Discriminator({
required this.propertyName, required this.propertyName,
this.mapping, this.mapping,
}); });

4
packages/dynamite/dynamite/lib/src/models/header.dart

@ -1,11 +1,13 @@
import 'package:dynamite/src/models/schema.dart'; import 'package:dynamite/src/models/schema.dart';
import 'package:json_annotation/json_annotation.dart'; import 'package:json_annotation/json_annotation.dart';
import 'package:meta/meta.dart';
part 'header.g.dart'; part 'header.g.dart';
@JsonSerializable() @JsonSerializable()
@immutable
class Header { class Header {
Header({ const Header({
this.description, this.description,
this.required, this.required,
this.schema, this.schema,

4
packages/dynamite/dynamite/lib/src/models/info.dart

@ -1,11 +1,13 @@
import 'package:dynamite/src/models/license.dart'; import 'package:dynamite/src/models/license.dart';
import 'package:json_annotation/json_annotation.dart'; import 'package:json_annotation/json_annotation.dart';
import 'package:meta/meta.dart';
part 'info.g.dart'; part 'info.g.dart';
@JsonSerializable() @JsonSerializable()
@immutable
class Info { class Info {
Info({ const Info({
required this.title, required this.title,
required this.version, required this.version,
required this.license, required this.license,

4
packages/dynamite/dynamite/lib/src/models/license.dart

@ -1,10 +1,12 @@
import 'package:json_annotation/json_annotation.dart'; import 'package:json_annotation/json_annotation.dart';
import 'package:meta/meta.dart';
part 'license.g.dart'; part 'license.g.dart';
@JsonSerializable() @JsonSerializable()
@immutable
class License { class License {
License({ const License({
required this.name, required this.name,
this.identifier, this.identifier,
this.url, this.url,

4
packages/dynamite/dynamite/lib/src/models/media_type.dart

@ -1,11 +1,13 @@
import 'package:dynamite/src/models/schema.dart'; import 'package:dynamite/src/models/schema.dart';
import 'package:json_annotation/json_annotation.dart'; import 'package:json_annotation/json_annotation.dart';
import 'package:meta/meta.dart';
part 'media_type.g.dart'; part 'media_type.g.dart';
@JsonSerializable() @JsonSerializable()
@immutable
class MediaType { class MediaType {
MediaType({ const MediaType({
this.schema, this.schema,
}); });

4
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/server.dart';
import 'package:dynamite/src/models/tag.dart'; import 'package:dynamite/src/models/tag.dart';
import 'package:json_annotation/json_annotation.dart'; import 'package:json_annotation/json_annotation.dart';
import 'package:meta/meta.dart';
part 'open_api.g.dart'; part 'open_api.g.dart';
@JsonSerializable() @JsonSerializable()
@immutable
class OpenAPI { class OpenAPI {
OpenAPI({ const OpenAPI({
required this.version, required this.version,
required this.info, required this.info,
this.servers, this.servers,

4
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/responses.dart';
import 'package:dynamite/src/models/security_requirement.dart'; import 'package:dynamite/src/models/security_requirement.dart';
import 'package:json_annotation/json_annotation.dart'; import 'package:json_annotation/json_annotation.dart';
import 'package:meta/meta.dart';
part 'operation.g.dart'; part 'operation.g.dart';
@JsonSerializable() @JsonSerializable()
@immutable
class Operation { class Operation {
Operation({ const Operation({
this.operationId, this.operationId,
this.summary, this.summary,
this.description, this.description,

4
packages/dynamite/dynamite/lib/src/models/parameter.dart

@ -1,11 +1,13 @@
import 'package:dynamite/src/models/schema.dart'; import 'package:dynamite/src/models/schema.dart';
import 'package:json_annotation/json_annotation.dart'; import 'package:json_annotation/json_annotation.dart';
import 'package:meta/meta.dart';
part 'parameter.g.dart'; part 'parameter.g.dart';
@JsonSerializable() @JsonSerializable()
@immutable
class Parameter { class Parameter {
Parameter({ const Parameter({
required this.name, required this.name,
required this.in_, required this.in_,
this.description, this.description,

4
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/operation.dart';
import 'package:dynamite/src/models/parameter.dart'; import 'package:dynamite/src/models/parameter.dart';
import 'package:json_annotation/json_annotation.dart'; import 'package:json_annotation/json_annotation.dart';
import 'package:meta/meta.dart';
part 'path_item.g.dart'; part 'path_item.g.dart';
@JsonSerializable() @JsonSerializable()
@immutable
class PathItem { class PathItem {
PathItem({ const PathItem({
this.description, this.description,
this.parameters, this.parameters,
this.get, this.get,

4
packages/dynamite/dynamite/lib/src/models/request_body.dart

@ -1,11 +1,13 @@
import 'package:dynamite/src/models/media_type.dart'; import 'package:dynamite/src/models/media_type.dart';
import 'package:json_annotation/json_annotation.dart'; import 'package:json_annotation/json_annotation.dart';
import 'package:meta/meta.dart';
part 'request_body.g.dart'; part 'request_body.g.dart';
@JsonSerializable() @JsonSerializable()
@immutable
class RequestBody { class RequestBody {
RequestBody({ const RequestBody({
this.description, this.description,
this.content, this.content,
this.required, this.required,

4
packages/dynamite/dynamite/lib/src/models/response.dart

@ -1,12 +1,14 @@
import 'package:dynamite/src/models/header.dart'; import 'package:dynamite/src/models/header.dart';
import 'package:dynamite/src/models/media_type.dart'; import 'package:dynamite/src/models/media_type.dart';
import 'package:json_annotation/json_annotation.dart'; import 'package:json_annotation/json_annotation.dart';
import 'package:meta/meta.dart';
part 'response.g.dart'; part 'response.g.dart';
@JsonSerializable() @JsonSerializable()
@immutable
class Response { class Response {
Response({ const Response({
required this.description, required this.description,
this.content, this.content,
this.headers, this.headers,

10
packages/dynamite/dynamite/lib/src/models/schema.dart

@ -1,11 +1,13 @@
import 'package:dynamite/src/models/discriminator.dart'; import 'package:dynamite/src/models/discriminator.dart';
import 'package:json_annotation/json_annotation.dart'; import 'package:json_annotation/json_annotation.dart';
import 'package:meta/meta.dart';
part 'schema.g.dart'; part 'schema.g.dart';
@JsonSerializable() @JsonSerializable()
@immutable
class Schema { class Schema {
Schema({ const Schema({
this.ref, this.ref,
this.oneOf, this.oneOf,
this.anyOf, this.anyOf,
@ -85,7 +87,9 @@ class Schema {
bool get isContentString => type == 'string' && (contentMediaType?.isNotEmpty ?? false) && contentSchema != null; 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) { Schema? _parseAdditionalProperties(final dynamic data) {
if (data == null) { if (data == null) {
@ -93,7 +97,7 @@ Schema? _parseAdditionalProperties(final dynamic data) {
} }
if (data is bool) { if (data is bool) {
return data ? EmptySchema() : null; return data ? const EmptySchema() : null;
} }
if (data is Map<String, dynamic>) { if (data is Map<String, dynamic>) {

4
packages/dynamite/dynamite/lib/src/models/security_scheme.dart

@ -1,10 +1,12 @@
import 'package:json_annotation/json_annotation.dart'; import 'package:json_annotation/json_annotation.dart';
import 'package:meta/meta.dart';
part 'security_scheme.g.dart'; part 'security_scheme.g.dart';
@JsonSerializable() @JsonSerializable()
@immutable
class SecurityScheme { class SecurityScheme {
SecurityScheme({ const SecurityScheme({
required this.type, required this.type,
this.description, this.description,
this.scheme, this.scheme,

4
packages/dynamite/dynamite/lib/src/models/server.dart

@ -1,11 +1,13 @@
import 'package:dynamite/src/models/server_variable.dart'; import 'package:dynamite/src/models/server_variable.dart';
import 'package:json_annotation/json_annotation.dart'; import 'package:json_annotation/json_annotation.dart';
import 'package:meta/meta.dart';
part 'server.g.dart'; part 'server.g.dart';
@JsonSerializable() @JsonSerializable()
@immutable
class Server { class Server {
Server({ const Server({
required this.url, required this.url,
this.variables, this.variables,
}); });

4
packages/dynamite/dynamite/lib/src/models/server_variable.dart

@ -1,10 +1,12 @@
import 'package:json_annotation/json_annotation.dart'; import 'package:json_annotation/json_annotation.dart';
import 'package:meta/meta.dart';
part 'server_variable.g.dart'; part 'server_variable.g.dart';
@JsonSerializable() @JsonSerializable()
@immutable
class ServerVariable { class ServerVariable {
ServerVariable({ const ServerVariable({
required this.default_, required this.default_,
this.enum_, this.enum_,
this.description, this.description,

4
packages/dynamite/dynamite/lib/src/models/tag.dart

@ -1,10 +1,12 @@
import 'package:json_annotation/json_annotation.dart'; import 'package:json_annotation/json_annotation.dart';
import 'package:meta/meta.dart';
part 'tag.g.dart'; part 'tag.g.dart';
@JsonSerializable() @JsonSerializable()
@immutable
class Tag { class Tag {
Tag({ const Tag({
required this.name, required this.name,
this.description, this.description,
}); });

Loading…
Cancel
Save