From ad5710b0ac448ae695dcfb698e3a08837e531f19 Mon Sep 17 00:00:00 2001 From: Moshe Dicker Date: Tue, 12 Mar 2024 13:57:57 -0400 Subject: [PATCH] fix lints on toJson --- lib/src/open_api/index.freezed.dart | 43 +++++++++++++-- lib/src/open_api/index.g.dart | 82 +++++++++++++++++++++++++++++ lib/src/open_api/security.dart | 1 + lib/src/open_api/spec.dart | 1 + 4 files changed, 123 insertions(+), 4 deletions(-) diff --git a/lib/src/open_api/index.freezed.dart b/lib/src/open_api/index.freezed.dart index bb118a2..cd725c3 100644 --- a/lib/src/open_api/index.freezed.dart +++ b/lib/src/open_api/index.freezed.dart @@ -11297,6 +11297,10 @@ abstract class _SchemaMap extends Schema { throw _privateConstructorUsedError; } +Security _$SecurityFromJson(Map json) { + return _Security.fromJson(json); +} + /// @nodoc mixin _$Security { /// Each name must correspond to a security scheme which is declared @@ -11322,7 +11326,7 @@ mixin _$Security { required TResult orElse(), }) => throw _privateConstructorUsedError; - + Map toJson() => throw _privateConstructorUsedError; @JsonKey(ignore: true) $SecurityCopyWith get copyWith => throw _privateConstructorUsedError; @@ -11404,12 +11408,15 @@ class __$$SecurityImplCopyWithImpl<$Res> } /// @nodoc - +@JsonSerializable() class _$SecurityImpl extends _Security { const _$SecurityImpl({this.name, final List scopes = const []}) : _scopes = scopes, super._(); + factory _$SecurityImpl.fromJson(Map json) => + _$$SecurityImplFromJson(json); + /// Each name must correspond to a security scheme which is declared /// in the [Components.securitySchemes] list @override @@ -11441,6 +11448,7 @@ class _$SecurityImpl extends _Security { const DeepCollectionEquality().equals(other._scopes, _scopes)); } + @JsonKey(ignore: true) @override int get hashCode => Object.hash( runtimeType, name, const DeepCollectionEquality().hash(_scopes)); @@ -11478,6 +11486,13 @@ class _$SecurityImpl extends _Security { } return orElse(); } + + @override + Map toJson() { + return _$$SecurityImplToJson( + this, + ); + } } abstract class _Security extends Security { @@ -11485,6 +11500,9 @@ abstract class _Security extends Security { _$SecurityImpl; const _Security._() : super._(); + factory _Security.fromJson(Map json) = + _$SecurityImpl.fromJson; + @override /// Each name must correspond to a security scheme which is declared @@ -12953,6 +12971,10 @@ abstract class _ServerVariable implements ServerVariable { throw _privateConstructorUsedError; } +OpenApi _$OpenApiFromJson(Map json) { + return _OpenApi.fromJson(json); +} + /// @nodoc mixin _$OpenApi { /// This string must be the version number of the @@ -13026,7 +13048,7 @@ mixin _$OpenApi { required TResult orElse(), }) => throw _privateConstructorUsedError; - + Map toJson() => throw _privateConstructorUsedError; @JsonKey(ignore: true) $OpenApiCopyWith get copyWith => throw _privateConstructorUsedError; } @@ -13261,7 +13283,7 @@ class __$$OpenApiImplCopyWithImpl<$Res> } /// @nodoc - +@JsonSerializable() class _$OpenApiImpl extends _OpenApi { const _$OpenApiImpl( {@JsonKey(name: 'openapi') this.version = '3.0.3', @@ -13283,6 +13305,9 @@ class _$OpenApiImpl extends _OpenApi { _extraSchemaMapping = extraSchemaMapping, super._(); + factory _$OpenApiImpl.fromJson(Map json) => + _$$OpenApiImplFromJson(json); + /// This string must be the version number of the /// OpenAPI Specification that the OpenAPI document uses. /// This is not related to the API [Info.version] string. @@ -13443,6 +13468,7 @@ class _$OpenApiImpl extends _OpenApi { .equals(other._extraSchemaMapping, _extraSchemaMapping)); } + @JsonKey(ignore: true) @override int get hashCode => Object.hash( runtimeType, @@ -13491,6 +13517,13 @@ class _$OpenApiImpl extends _OpenApi { } return orElse(); } + + @override + Map toJson() { + return _$$OpenApiImplToJson( + this, + ); + } } abstract class _OpenApi extends OpenApi { @@ -13508,6 +13541,8 @@ abstract class _OpenApi extends OpenApi { final Map> extraSchemaMapping}) = _$OpenApiImpl; const _OpenApi._() : super._(); + factory _OpenApi.fromJson(Map json) = _$OpenApiImpl.fromJson; + @override /// This string must be the version number of the diff --git a/lib/src/open_api/index.g.dart b/lib/src/open_api/index.g.dart index 67b9e5f..e09db84 100644 --- a/lib/src/open_api/index.g.dart +++ b/lib/src/open_api/index.g.dart @@ -1275,6 +1275,29 @@ Map _$$SchemaMapImplToJson(_$SchemaMapImpl instance) { return val; } +_$SecurityImpl _$$SecurityImplFromJson(Map json) => + _$SecurityImpl( + name: json['name'] as String?, + scopes: (json['scopes'] as List?) + ?.map((e) => e as String) + .toList() ?? + const [], + ); + +Map _$$SecurityImplToJson(_$SecurityImpl instance) { + final val = {}; + + void writeNotNull(String key, dynamic value) { + if (value != null) { + val[key] = value; + } + } + + writeNotNull('name', instance.name); + val['scopes'] = instance.scopes; + return val; +} + _$SecuritySchemeApiKeyImpl _$$SecuritySchemeApiKeyImplFromJson( Map json) => _$SecuritySchemeApiKeyImpl( @@ -1459,6 +1482,65 @@ Map _$$ServerVariableImplToJson( return val; } +_$OpenApiImpl _$$OpenApiImplFromJson(Map json) => + _$OpenApiImpl( + version: json['openapi'] as String? ?? '3.0.3', + info: Info.fromJson(json['info'] as Map), + externalDocs: json['externalDocs'] == null + ? null + : ExternalDocs.fromJson(json['externalDocs'] as Map), + jsonSchemaDialect: json['jsonSchemaDialect'] as String?, + servers: (json['servers'] as List?) + ?.map((e) => Server.fromJson(e as Map)) + .toList(), + tags: (json['tags'] as List?) + ?.map((e) => Tag.fromJson(e as Map)) + .toList(), + paths: (json['paths'] as Map?)?.map( + (k, e) => MapEntry(k, PathItem.fromJson(e as Map)), + ), + webhooks: (json['webhooks'] as Map?)?.map( + (k, e) => MapEntry(k, PathItem.fromJson(e as Map)), + ), + components: json['components'] == null + ? null + : Components.fromJson(json['components'] as Map), + security: (json['security'] as List?) + ?.map((e) => Security.fromJson(e as Map)) + .toList(), + extraSchemaMapping: + (json['extraSchemaMapping'] as Map?)?.map( + (k, e) => MapEntry( + k, (e as List).map((e) => e as String).toList()), + ) ?? + const {}, + ); + +Map _$$OpenApiImplToJson(_$OpenApiImpl instance) { + final val = { + 'openapi': instance.version, + 'info': instance.info.toJson(), + }; + + void writeNotNull(String key, dynamic value) { + if (value != null) { + val[key] = value; + } + } + + writeNotNull('externalDocs', instance.externalDocs?.toJson()); + writeNotNull('jsonSchemaDialect', instance.jsonSchemaDialect); + writeNotNull('servers', instance.servers?.map((e) => e.toJson()).toList()); + writeNotNull('tags', instance.tags?.map((e) => e.toJson()).toList()); + writeNotNull('paths', instance.paths?.map((k, e) => MapEntry(k, e.toJson()))); + writeNotNull( + 'webhooks', instance.webhooks?.map((k, e) => MapEntry(k, e.toJson()))); + writeNotNull('components', instance.components?.toJson()); + writeNotNull('security', instance.security?.map((e) => e.toJson()).toList()); + val['extraSchemaMapping'] = instance.extraSchemaMapping; + return val; +} + _$TagImpl _$$TagImplFromJson(Map json) => _$TagImpl( name: json['name'] as String, description: json['description'] as String?, diff --git a/lib/src/open_api/security.dart b/lib/src/open_api/security.dart index a4cb0d3..6f668e7 100644 --- a/lib/src/open_api/security.dart +++ b/lib/src/open_api/security.dart @@ -33,6 +33,7 @@ class Security with _$Security { } }); + @override Map toJson() { if (name == null) { return {}; diff --git a/lib/src/open_api/spec.dart b/lib/src/open_api/spec.dart index 7ed6d51..6eadd3f 100644 --- a/lib/src/open_api/spec.dart +++ b/lib/src/open_api/spec.dart @@ -235,6 +235,7 @@ class OpenApi with _$OpenApi { // ------------------------------------------ /// Convert the [OpenApi] object to a JSON spec representation + @override Map toJson() { if (paths == null && components == null && webhooks == null) { throw Exception(