Skip to content

Commit

Permalink
fix fromJson function types
Browse files Browse the repository at this point in the history
  • Loading branch information
dickermoshe committed Mar 12, 2024
1 parent 66292a3 commit c3a5162
Show file tree
Hide file tree
Showing 12 changed files with 127 additions and 232 deletions.
43 changes: 22 additions & 21 deletions lib/src/open_api/callback.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,28 +26,29 @@ class _ApiCallbackMapConverter
const _ApiCallbackMapConverter();

@override
Map<String, ApiCallback> fromJson(Map<String, dynamic> json) =>
fromJsonWithLogging(json, (Map<String, dynamic> json) {
Map<String, ApiCallback> out = {};

for (final key in json.keys) {
final name = key;
final expression = json[key];
if (expression is! Map) {
continue;
}
if (expression.isEmpty) {
continue;
}
out[key] = ApiCallback(
name: name,
expression: {
expression.keys.first: PathItem.fromJson(expression.values.first),
},
);
Map<String, ApiCallback> fromJson(Map<String, dynamic> json) {
return fromJsonWithLogging(json, (Map<String, dynamic> json) {
Map<String, ApiCallback> out = {};

for (final key in json.keys) {
final name = key;
final expression = json[key];
if (expression is! Map) {
continue;
}
return out;
});
if (expression.isEmpty) {
continue;
}
out[key] = ApiCallback(
name: name,
expression: {
expression.keys.first: PathItem.fromJson(expression.values.first),
},
);
}
return out;
});
}

@override
Map<String, dynamic> toJson(Map<String, ApiCallback> data) {
Expand Down
8 changes: 5 additions & 3 deletions lib/src/open_api/example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ class _ExampleRefConverter implements JsonConverter<String?, String?> {
}

@override
String? fromJson(String? ref) => fromJsonWithLogging(ref, (ref) {
return ref == null ? ref : ref.split('/').last;
});
String? fromJson(String? ref) {
return fromJsonWithLogging(ref, (ref) {
return ref == null ? ref : ref.split('/').last;
});
}
}
43 changes: 4 additions & 39 deletions lib/src/open_api/index.freezed.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11297,10 +11297,6 @@ abstract class _SchemaMap extends Schema {
throw _privateConstructorUsedError;
}

Security _$SecurityFromJson(Map<String, dynamic> json) {
return _Security.fromJson(json);
}

/// @nodoc
mixin _$Security {
/// Each name must correspond to a security scheme which is declared
Expand All @@ -11326,7 +11322,7 @@ mixin _$Security {
required TResult orElse(),
}) =>
throw _privateConstructorUsedError;
Map<String, dynamic> toJson() => throw _privateConstructorUsedError;

@JsonKey(ignore: true)
$SecurityCopyWith<Security> get copyWith =>
throw _privateConstructorUsedError;
Expand Down Expand Up @@ -11408,15 +11404,12 @@ class __$$SecurityImplCopyWithImpl<$Res>
}

/// @nodoc
@JsonSerializable()
class _$SecurityImpl extends _Security {
const _$SecurityImpl({this.name, final List<String> scopes = const []})
: _scopes = scopes,
super._();

factory _$SecurityImpl.fromJson(Map<String, dynamic> json) =>
_$$SecurityImplFromJson(json);

/// Each name must correspond to a security scheme which is declared
/// in the [Components.securitySchemes] list
@override
Expand Down Expand Up @@ -11448,7 +11441,6 @@ 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));
Expand Down Expand Up @@ -11486,23 +11478,13 @@ class _$SecurityImpl extends _Security {
}
return orElse();
}

@override
Map<String, dynamic> toJson() {
return _$$SecurityImplToJson(
this,
);
}
}

abstract class _Security extends Security {
const factory _Security({final String? name, final List<String> scopes}) =
_$SecurityImpl;
const _Security._() : super._();

factory _Security.fromJson(Map<String, dynamic> json) =
_$SecurityImpl.fromJson;

@override

/// Each name must correspond to a security scheme which is declared
Expand Down Expand Up @@ -12971,10 +12953,6 @@ abstract class _ServerVariable implements ServerVariable {
throw _privateConstructorUsedError;
}

OpenApi _$OpenApiFromJson(Map<String, dynamic> json) {
return _OpenApi.fromJson(json);
}

/// @nodoc
mixin _$OpenApi {
/// This string must be the version number of the
Expand Down Expand Up @@ -13048,7 +13026,7 @@ mixin _$OpenApi {
required TResult orElse(),
}) =>
throw _privateConstructorUsedError;
Map<String, dynamic> toJson() => throw _privateConstructorUsedError;

@JsonKey(ignore: true)
$OpenApiCopyWith<OpenApi> get copyWith => throw _privateConstructorUsedError;
}
Expand Down Expand Up @@ -13283,7 +13261,7 @@ class __$$OpenApiImplCopyWithImpl<$Res>
}

/// @nodoc
@JsonSerializable()
class _$OpenApiImpl extends _OpenApi {
const _$OpenApiImpl(
{@JsonKey(name: 'openapi') this.version = '3.0.3',
Expand All @@ -13305,9 +13283,6 @@ class _$OpenApiImpl extends _OpenApi {
_extraSchemaMapping = extraSchemaMapping,
super._();

factory _$OpenApiImpl.fromJson(Map<String, dynamic> 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.
Expand Down Expand Up @@ -13468,7 +13443,6 @@ class _$OpenApiImpl extends _OpenApi {
.equals(other._extraSchemaMapping, _extraSchemaMapping));
}

@JsonKey(ignore: true)
@override
int get hashCode => Object.hash(
runtimeType,
Expand Down Expand Up @@ -13517,13 +13491,6 @@ class _$OpenApiImpl extends _OpenApi {
}
return orElse();
}

@override
Map<String, dynamic> toJson() {
return _$$OpenApiImplToJson(
this,
);
}
}

abstract class _OpenApi extends OpenApi {
Expand All @@ -13541,8 +13508,6 @@ abstract class _OpenApi extends OpenApi {
final Map<String, List<String>> extraSchemaMapping}) = _$OpenApiImpl;
const _OpenApi._() : super._();

factory _OpenApi.fromJson(Map<String, dynamic> json) = _$OpenApiImpl.fromJson;

@override

/// This string must be the version number of the
Expand Down
82 changes: 0 additions & 82 deletions lib/src/open_api/index.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions lib/src/open_api/link.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ class _LinkRefConverter implements JsonConverter<String?, String?> {
}

@override
String? fromJson(String? ref) => fromJsonWithLogging(ref, (ref) {
return ref == null ? ref : ref.split('/').last;
});
String? fromJson(String? ref) {
return fromJsonWithLogging(ref, (ref) {
return ref == null ? ref : ref.split('/').last;
});
}
}
8 changes: 5 additions & 3 deletions lib/src/open_api/parameter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,11 @@ class _ParamRefConverter implements JsonConverter<String?, String?> {
}

@override
String? fromJson(String? ref) => fromJsonWithLogging(ref, (ref) {
return ref == null ? ref : ref.split('/').last;
});
String? fromJson(String? ref) {
return fromJsonWithLogging(ref, (ref) {
return ref == null ? ref : ref.split('/').last;
});
}
}

/// Ensure that name or ref is provided
Expand Down
8 changes: 5 additions & 3 deletions lib/src/open_api/path_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,9 @@ class _PathRefConverter implements JsonConverter<String?, String?> {
}

@override
String? fromJson(String? ref) => fromJsonWithLogging(ref, (ref) {
return ref == null ? ref : ref.split('/').last;
});
String? fromJson(String? ref) {
return fromJsonWithLogging(ref, (ref) {
return ref == null ? ref : ref.split('/').last;
});
}
}
4 changes: 2 additions & 2 deletions lib/src/open_api/request_body.dart
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class _RequestRefConverter implements JsonConverter<String?, String?> {
}

@override
String? fromJson(String? ref) => fromJsonWithLogging(ref, (ref) {
String? fromJson(String? ref) {return fromJsonWithLogging(ref, (ref) {
return ref == null ? ref : ref.split('/').last;
});
});}
}
8 changes: 5 additions & 3 deletions lib/src/open_api/response.dart
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ class _ResponseRefConverter implements JsonConverter<String?, String?> {
}

@override
String? fromJson(String? ref) => fromJsonWithLogging(ref, (ref) {
return ref == null ? ref : ref.split('/').last;
});
String? fromJson(String? ref) {
return fromJsonWithLogging(ref, (ref) {
return ref == null ? ref : ref.split('/').last;
});
}
}
8 changes: 5 additions & 3 deletions lib/src/open_api/schema.dart
Original file line number Diff line number Diff line change
Expand Up @@ -413,9 +413,11 @@ class _SchemaRefConverter implements JsonConverter<String?, String?> {
}

@override
String? fromJson(String? ref) => fromJsonWithLogging(ref, (ref) {
return ref == null ? ref : ref.split('/').last;
});
String? fromJson(String? ref) {
return fromJsonWithLogging(ref, (ref) {
return ref == null ? ref : ref.split('/').last;
});
}
}

// ==========================================
Expand Down
Loading

0 comments on commit c3a5162

Please sign in to comment.