Skip to content

Commit

Permalink
Merge branch 'main' into raw_Str
Browse files Browse the repository at this point in the history
  • Loading branch information
dickermoshe authored Mar 12, 2024
2 parents 1153f15 + e4bf912 commit 109cdd0
Show file tree
Hide file tree
Showing 29 changed files with 177 additions and 121 deletions.
38 changes: 20 additions & 18 deletions lib/src/open_api/callback.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,27 @@ class _ApiCallbackMapConverter

@override
Map<String, ApiCallback> fromJson(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;
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;
}
if (expression.isEmpty) {
continue;
}
out[key] = ApiCallback(
name: name,
expression: {
expression.keys.first: PathItem.fromJson(expression.values.first),
},
);
}
out[key] = ApiCallback(
name: name,
expression: {
expression.keys.first: PathItem.fromJson(expression.values.first),
},
);
}
return out;
return out;
});
}

@override
Expand Down
2 changes: 1 addition & 1 deletion lib/src/open_api/components.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,5 @@ class Components with _$Components {
// ------------------------------------------

factory Components.fromJson(Map<String, dynamic> json) =>
_$ComponentsFromJson(json);
fromJsonWithLogging(json, _$ComponentsFromJson);
}
2 changes: 1 addition & 1 deletion lib/src/open_api/contact.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ class Contact with _$Contact {
}) = _Contact;

factory Contact.fromJson(Map<String, dynamic> json) =>
_$ContactFromJson(json);
fromJsonWithLogging(json, _$ContactFromJson);
}
2 changes: 1 addition & 1 deletion lib/src/open_api/discriminator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ class Discriminator with _$Discriminator {
}) = _Discriminator;

factory Discriminator.fromJson(Map<String, dynamic> json) =>
_$DiscriminatorFromJson(json);
fromJsonWithLogging(json, _$DiscriminatorFromJson);
}
2 changes: 1 addition & 1 deletion lib/src/open_api/encoding.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ class Encoding with _$Encoding {
}) = _Encoding;

factory Encoding.fromJson(Map<String, dynamic> json) =>
_$EncodingFromJson(json);
fromJsonWithLogging(json, _$EncodingFromJson);
}
6 changes: 4 additions & 2 deletions lib/src/open_api/example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class Example with _$Example {
}) = ExampleObject;

factory Example.fromJson(Map<String, dynamic> json) =>
_$ExampleFromJson(json);
fromJsonWithLogging(json, _$ExampleFromJson);

// ------------------------------------------
// METHOD: dereference
Expand Down Expand Up @@ -75,6 +75,8 @@ class _ExampleRefConverter implements JsonConverter<String?, String?> {

@override
String? fromJson(String? ref) {
return ref == null ? ref : ref.split('/').last;
return fromJsonWithLogging(ref, (ref) {
return ref == null ? ref : ref.split('/').last;
});
}
}
2 changes: 1 addition & 1 deletion lib/src/open_api/external_docs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ class ExternalDocs with _$ExternalDocs {
}) = _ExternalDocs;

factory ExternalDocs.fromJson(Map<String, dynamic> json) =>
_$ExternalDocsFromJson(json);
fromJsonWithLogging(json, _$ExternalDocsFromJson);
}
3 changes: 2 additions & 1 deletion lib/src/open_api/header.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ class Header with _$Header {
Schema? schema,
}) = _Header;

factory Header.fromJson(Map<String, dynamic> json) => _$HeaderFromJson(json);
factory Header.fromJson(Map<String, dynamic> json) =>
fromJsonWithLogging(json, _$HeaderFromJson);
}
1 change: 1 addition & 0 deletions lib/src/open_api/index.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'dart:convert';
import 'dart:io';
import 'dart:isolate';
import 'package:collection/collection.dart';
import 'package:openapi_spec/src/utils/json_logging.dart';
import 'package:recase/recase.dart';
import 'package:yaml/yaml.dart' as yaml;
import 'package:path/path.dart' as p;
Expand Down
3 changes: 2 additions & 1 deletion lib/src/open_api/info.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,6 @@ class Info with _$Info {
required String version,
}) = _Info;

factory Info.fromJson(Map<String, dynamic> json) => _$InfoFromJson(json);
factory Info.fromJson(Map<String, dynamic> json) =>
fromJsonWithLogging(json, _$InfoFromJson);
}
2 changes: 1 addition & 1 deletion lib/src/open_api/license.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ class License with _$License {
}) = _License;

factory License.fromJson(Map<String, dynamic> json) =>
_$LicenseFromJson(json);
fromJsonWithLogging(json, _$LicenseFromJson);
}
7 changes: 5 additions & 2 deletions lib/src/open_api/link.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ class Link with _$Link {
Map<String, String>? parameters,
}) = _Link;

factory Link.fromJson(Map<String, dynamic> json) => _$LinkFromJson(json);
factory Link.fromJson(Map<String, dynamic> json) =>
fromJsonWithLogging(json, _$LinkFromJson);
}

/// Custom converter to handle schema references
Expand All @@ -38,6 +39,8 @@ class _LinkRefConverter implements JsonConverter<String?, String?> {

@override
String? fromJson(String? ref) {
return ref == null ? ref : ref.split('/').last;
return fromJsonWithLogging(ref, (ref) {
return ref == null ? ref : ref.split('/').last;
});
}
}
2 changes: 1 addition & 1 deletion lib/src/open_api/media_type.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ class MediaType with _$MediaType {
}) = _MediaType;

factory MediaType.fromJson(Map<String, dynamic> json) =>
_$MediaTypeFromJson(json);
fromJsonWithLogging(json, _$MediaTypeFromJson);
}
4 changes: 2 additions & 2 deletions lib/src/open_api/oauth_flow.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class OAuthFlows with _$OAuthFlows {
}) = _OAuthFlows;

factory OAuthFlows.fromJson(Map<String, dynamic> json) =>
_$OAuthFlowsFromJson(json);
fromJsonWithLogging(json, _$OAuthFlowsFromJson);
}

// ==========================================
Expand Down Expand Up @@ -49,5 +49,5 @@ class OAuthFlow with _$OAuthFlow {
}) = _OAuthFlowAuthorizationCode;

factory OAuthFlow.fromJson(Map<String, dynamic> json) =>
_$OAuthFlowFromJson(json);
fromJsonWithLogging(json, _$OAuthFlowFromJson);
}
3 changes: 2 additions & 1 deletion lib/src/open_api/openid_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -79,5 +79,6 @@ class OpenId with _$OpenId {
List<String>? tokenEndpointAuthSigningAlgValuesSupported,
}) = _OpenId;

factory OpenId.fromJson(Map<String, dynamic> json) => _$OpenIdFromJson(json);
factory OpenId.fromJson(Map<String, dynamic> json) =>
fromJsonWithLogging(json, _$OpenIdFromJson);
}
2 changes: 1 addition & 1 deletion lib/src/open_api/operation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,5 @@ class Operation with _$Operation {
}) = _Operation;

factory Operation.fromJson(Map<String, dynamic> json) =>
_$OperationFromJson(json);
fromJsonWithLogging(json, _$OperationFromJson);
}
6 changes: 4 additions & 2 deletions lib/src/open_api/parameter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class Parameter with _$Parameter {
// ------------------------------------------

factory Parameter.fromJson(Map<String, dynamic> json) =>
_$ParameterFromJson(json);
fromJsonWithLogging(json, _$ParameterFromJson);

// ------------------------------------------
// METHOD: dereference
Expand Down Expand Up @@ -135,7 +135,9 @@ class _ParamRefConverter implements JsonConverter<String?, String?> {

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

Expand Down
6 changes: 4 additions & 2 deletions lib/src/open_api/path_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class PathItem with _$PathItem {
}) = _PathItem;

factory PathItem.fromJson(Map<String, dynamic> json) =>
_$PathItemFromJson(json);
fromJsonWithLogging(json, _$PathItemFromJson);

// ------------------------------------------
// METHOD: dereference
Expand Down Expand Up @@ -102,6 +102,8 @@ class _PathRefConverter implements JsonConverter<String?, String?> {

@override
String? fromJson(String? ref) {
return ref == null ? ref : ref.split('/').last;
return fromJsonWithLogging(ref, (ref) {
return ref == null ? ref : ref.split('/').last;
});
}
}
6 changes: 4 additions & 2 deletions lib/src/open_api/request_body.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class RequestBody with _$RequestBody {

/// Construct an instance of [RequestBody] from a JSON map
factory RequestBody.fromJson(Map<String, dynamic> json) =>
_$RequestBodyFromJson(json);
fromJsonWithLogging(json, _$RequestBodyFromJson);

// ------------------------------------------
// METHOD: dereference
Expand Down Expand Up @@ -73,6 +73,8 @@ class _RequestRefConverter implements JsonConverter<String?, String?> {

@override
String? fromJson(String? ref) {
return ref == null ? ref : ref.split('/').last;
return fromJsonWithLogging(ref, (ref) {
return ref == null ? ref : ref.split('/').last;
});
}
}
6 changes: 4 additions & 2 deletions lib/src/open_api/response.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class Response with _$Response {
// ------------------------------------------

factory Response.fromJson(Map<String, dynamic> json) =>
_$ResponseFromJson(json);
fromJsonWithLogging(json, _$ResponseFromJson);

// ------------------------------------------
// METHOD: dereference
Expand Down Expand Up @@ -82,6 +82,8 @@ class _ResponseRefConverter implements JsonConverter<String?, String?> {

@override
String? fromJson(String? ref) {
return ref == null ? ref : ref.split('/').last;
return fromJsonWithLogging(ref, (ref) {
return ref == null ? ref : ref.split('/').last;
});
}
}
34 changes: 21 additions & 13 deletions lib/src/open_api/schema.dart
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,8 @@ class Schema with _$Schema {
// ------------------------------------------

/// Convert from JSON representation
factory Schema.fromJson(Map<String, dynamic> json) => _$SchemaFromJson(json);
factory Schema.fromJson(Map<String, dynamic> json) =>
fromJsonWithLogging(json, _$SchemaFromJson);

// ------------------------------------------
// METHOD: dereference
Expand Down Expand Up @@ -413,7 +414,9 @@ class _SchemaRefConverter implements JsonConverter<String?, String?> {

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

Expand Down Expand Up @@ -449,11 +452,13 @@ class _SchemaConverter implements JsonConverter<Schema, Map<String, dynamic>> {

@override
Schema fromJson(Map<String, dynamic> json) {
if (json.containsKey('enum') && json['enum'].isNotEmpty) {
return _SchemaEnum.fromJson(json);
} else {
return Schema.fromJson(json);
}
return fromJsonWithLogging(json, (json) {
if (json.containsKey('enum') && json['enum'].isNotEmpty) {
return _SchemaEnum.fromJson(json);
} else {
return Schema.fromJson(json);
}
});
}
}

Expand All @@ -468,11 +473,13 @@ class _SchemaMapConverter

@override
Map<String, Schema> fromJson(Map<String, dynamic> json) {
Map<String, Schema> out = {};
for (final key in json.keys) {
out[key] = _SchemaConverter().fromJson(json[key]);
}
return out;
return fromJsonWithLogging(json, (json) {
Map<String, Schema> out = {};
for (final key in json.keys) {
out[key] = _SchemaConverter().fromJson(json[key]);
}
return out;
});
}

@override
Expand All @@ -497,7 +504,8 @@ class _SchemaListConverter
@override
List<Schema> fromJson(List<dynamic> json) {
return json
.map((e) => _SchemaConverter().fromJson(Map<String, dynamic>.from(e)))
.map((e) => fromJsonWithLogging(
Map<String, dynamic>.from(e), _SchemaConverter().fromJson))
.toList();
}

Expand Down
20 changes: 11 additions & 9 deletions lib/src/open_api/security.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,17 @@ class Security with _$Security {
}) = _Security;

factory Security.fromJson(Map<String, dynamic> json) {
if (json.isEmpty) {
return const Security();
} else {
final name = json.keys.first;
return Security(
name: name,
scopes: List<String>.from(json[name] ?? []),
);
}
return fromJsonWithLogging(json, (json) {
if (json.isEmpty) {
return const Security();
} else {
final name = json.keys.first;
return Security(
name: name,
scopes: List<String>.from(json[name] ?? []),
);
}
});
}

Map<String, dynamic> toJson() {
Expand Down
2 changes: 1 addition & 1 deletion lib/src/open_api/security_scheme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -95,5 +95,5 @@ class SecurityScheme with _$SecurityScheme {
// ------------------------------------------

factory SecurityScheme.fromJson(Map<String, dynamic> json) =>
_$SecuritySchemeFromJson(json);
fromJsonWithLogging(json, _$SecuritySchemeFromJson);
}
3 changes: 2 additions & 1 deletion lib/src/open_api/server.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@ class Server with _$Server {
final Map<String, ServerVariable>? variables,
}) = _Server;

factory Server.fromJson(Map<String, dynamic> json) => _$ServerFromJson(json);
factory Server.fromJson(Map<String, dynamic> json) =>
fromJsonWithLogging(json, _$ServerFromJson);
}
2 changes: 1 addition & 1 deletion lib/src/open_api/server_variable.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ class ServerVariable with _$ServerVariable {
}) = _ServerVariable;

factory ServerVariable.fromJson(Map<String, dynamic> json) =>
_$ServerVariableFromJson(json);
fromJsonWithLogging(json, _$ServerVariableFromJson);
}
Loading

0 comments on commit 109cdd0

Please sign in to comment.