mirror of
https://bitbucket.org/FransoletThomas/tablet-app.git
synced 2025-12-06 08:31:19 +00:00
339 lines
12 KiB
Dart
339 lines
12 KiB
Dart
//
|
|
// AUTO-GENERATED FILE, DO NOT MODIFY!
|
|
//
|
|
// @dart=2.12
|
|
|
|
// ignore_for_file: unused_element, unused_import
|
|
// ignore_for_file: always_put_required_named_parameters_first
|
|
// ignore_for_file: constant_identifier_names
|
|
// ignore_for_file: lines_longer_than_80_chars
|
|
|
|
part of openapi.api;
|
|
|
|
class ApiClient {
|
|
ApiClient({this.basePath = 'https://api.myinfomate.be', this.authentication,});
|
|
|
|
final String basePath;
|
|
final Authentication? authentication;
|
|
|
|
var _client = Client();
|
|
final _defaultHeaderMap = <String, String>{};
|
|
|
|
/// Returns the current HTTP [Client] instance to use in this class.
|
|
///
|
|
/// The return value is guaranteed to never be null.
|
|
Client get client => _client;
|
|
|
|
/// Requests to use a new HTTP [Client] in this class.
|
|
set client(Client newClient) {
|
|
_client = newClient;
|
|
}
|
|
|
|
Map<String, String> get defaultHeaderMap => _defaultHeaderMap;
|
|
|
|
void addDefaultHeader(String key, String value) {
|
|
_defaultHeaderMap[key] = value;
|
|
}
|
|
|
|
// We don't use a Map<String, String> for queryParams.
|
|
// If collectionFormat is 'multi', a key might appear multiple times.
|
|
Future<Response> invokeAPI(
|
|
String path,
|
|
String method,
|
|
List<QueryParam> queryParams,
|
|
Object? body,
|
|
Map<String, String> headerParams,
|
|
Map<String, String> formParams,
|
|
String? contentType,
|
|
) async {
|
|
await authentication?.applyToParams(queryParams, headerParams);
|
|
|
|
headerParams.addAll(_defaultHeaderMap);
|
|
if (contentType != null) {
|
|
headerParams['Content-Type'] = contentType;
|
|
}
|
|
|
|
final urlEncodedQueryParams = queryParams.map((param) => '$param');
|
|
final queryString = urlEncodedQueryParams.isNotEmpty ? '?${urlEncodedQueryParams.join('&')}' : '';
|
|
final uri = Uri.parse('$basePath$path$queryString');
|
|
|
|
try {
|
|
// Special case for uploading a single file which isn't a 'multipart/form-data'.
|
|
if (
|
|
body is MultipartFile && (contentType == null ||
|
|
!contentType.toLowerCase().startsWith('multipart/form-data'))
|
|
) {
|
|
final request = StreamedRequest(method, uri);
|
|
request.headers.addAll(headerParams);
|
|
request.contentLength = body.length;
|
|
body.finalize().listen(
|
|
request.sink.add,
|
|
onDone: request.sink.close,
|
|
// ignore: avoid_types_on_closure_parameters
|
|
onError: (Object error, StackTrace trace) => request.sink.close(),
|
|
cancelOnError: true,
|
|
);
|
|
final response = await _client.send(request);
|
|
return Response.fromStream(response);
|
|
}
|
|
|
|
if (body is MultipartRequest) {
|
|
final request = MultipartRequest(method, uri);
|
|
request.fields.addAll(body.fields);
|
|
request.files.addAll(body.files);
|
|
request.headers.addAll(body.headers);
|
|
request.headers.addAll(headerParams);
|
|
final response = await _client.send(request);
|
|
return Response.fromStream(response);
|
|
}
|
|
|
|
final msgBody = contentType == 'application/x-www-form-urlencoded'
|
|
? formParams
|
|
: await serializeAsync(body);
|
|
final nullableHeaderParams = headerParams.isEmpty ? null : headerParams;
|
|
|
|
switch(method) {
|
|
case 'POST': return await _client.post(uri, headers: nullableHeaderParams, body: msgBody,);
|
|
case 'PUT': return await _client.put(uri, headers: nullableHeaderParams, body: msgBody,);
|
|
case 'DELETE': return await _client.delete(uri, headers: nullableHeaderParams, body: msgBody,);
|
|
case 'PATCH': return await _client.patch(uri, headers: nullableHeaderParams, body: msgBody,);
|
|
case 'HEAD': return await _client.head(uri, headers: nullableHeaderParams,);
|
|
case 'GET': return await _client.get(uri, headers: nullableHeaderParams,);
|
|
}
|
|
} on SocketException catch (error, trace) {
|
|
throw ApiException.withInner(
|
|
HttpStatus.badRequest,
|
|
'Socket operation failed: $method $path',
|
|
error,
|
|
trace,
|
|
);
|
|
} on TlsException catch (error, trace) {
|
|
throw ApiException.withInner(
|
|
HttpStatus.badRequest,
|
|
'TLS/SSL communication failed: $method $path',
|
|
error,
|
|
trace,
|
|
);
|
|
} on IOException catch (error, trace) {
|
|
throw ApiException.withInner(
|
|
HttpStatus.badRequest,
|
|
'I/O operation failed: $method $path',
|
|
error,
|
|
trace,
|
|
);
|
|
} on ClientException catch (error, trace) {
|
|
throw ApiException.withInner(
|
|
HttpStatus.badRequest,
|
|
'HTTP connection failed: $method $path',
|
|
error,
|
|
trace,
|
|
);
|
|
} on Exception catch (error, trace) {
|
|
throw ApiException.withInner(
|
|
HttpStatus.badRequest,
|
|
'Exception occurred: $method $path',
|
|
error,
|
|
trace,
|
|
);
|
|
}
|
|
|
|
throw ApiException(
|
|
HttpStatus.badRequest,
|
|
'Invalid HTTP operation: $method $path',
|
|
);
|
|
}
|
|
|
|
Future<dynamic> deserializeAsync(String json, String targetType, {bool growable = false,}) async =>
|
|
// ignore: deprecated_member_use_from_same_package
|
|
deserialize(json, targetType, growable: growable);
|
|
|
|
@Deprecated('Scheduled for removal in OpenAPI Generator 6.x. Use deserializeAsync() instead.')
|
|
dynamic deserialize(String json, String targetType, {bool growable = false,}) {
|
|
// Remove all spaces. Necessary for regular expressions as well.
|
|
targetType = targetType.replaceAll(' ', ''); // ignore: parameter_assignments
|
|
|
|
// If the expected target type is String, nothing to do...
|
|
return targetType == 'String'
|
|
? json
|
|
: _deserialize(jsonDecode(json), targetType, growable: growable);
|
|
}
|
|
|
|
// ignore: deprecated_member_use_from_same_package
|
|
Future<String> serializeAsync(Object? value) async => serialize(value);
|
|
|
|
@Deprecated('Scheduled for removal in OpenAPI Generator 6.x. Use serializeAsync() instead.')
|
|
String serialize(Object? value) => value == null ? '' : json.encode(value);
|
|
|
|
static dynamic _deserialize(dynamic value, String targetType, {bool growable = false}) {
|
|
try {
|
|
switch (targetType) {
|
|
case 'String':
|
|
return value is String ? value : value.toString();
|
|
case 'int':
|
|
return value is int ? value : int.parse('$value');
|
|
case 'double':
|
|
return value is double ? value : double.parse('$value');
|
|
case 'bool':
|
|
if (value is bool) {
|
|
return value;
|
|
}
|
|
final valueString = '$value'.toLowerCase();
|
|
return valueString == 'true' || valueString == '1';
|
|
case 'DateTime':
|
|
return value is DateTime ? value : DateTime.tryParse(value);
|
|
case 'AgendaDTO':
|
|
return AgendaDTO.fromJson(value);
|
|
case 'ArticleDTO':
|
|
return ArticleDTO.fromJson(value);
|
|
case 'CategorieDTO':
|
|
return CategorieDTO.fromJson(value);
|
|
case 'ConfigurationDTO':
|
|
return ConfigurationDTO.fromJson(value);
|
|
case 'ContentDTO':
|
|
return ContentDTO.fromJson(value);
|
|
case 'ContentGeoPoint':
|
|
return ContentGeoPoint.fromJson(value);
|
|
case 'DeviceDTO':
|
|
return DeviceDTO.fromJson(value);
|
|
case 'DeviceDetailDTO':
|
|
return DeviceDetailDTO.fromJson(value);
|
|
case 'DeviceDetailDTOAllOf':
|
|
return DeviceDetailDTOAllOf.fromJson(value);
|
|
case 'ExportConfigurationDTO':
|
|
return ExportConfigurationDTO.fromJson(value);
|
|
case 'ExportConfigurationDTOAllOf':
|
|
return ExportConfigurationDTOAllOf.fromJson(value);
|
|
case 'GeoPointDTO':
|
|
return GeoPointDTO.fromJson(value);
|
|
case 'GeoPointDTOCategorie':
|
|
return GeoPointDTOCategorie.fromJson(value);
|
|
case 'Instance':
|
|
return Instance.fromJson(value);
|
|
case 'InstanceDTO':
|
|
return InstanceDTO.fromJson(value);
|
|
case 'LevelDTO':
|
|
return LevelDTO.fromJson(value);
|
|
case 'LoginDTO':
|
|
return LoginDTO.fromJson(value);
|
|
case 'MapDTO':
|
|
return MapDTO.fromJson(value);
|
|
case 'MapDTOMapProvider':
|
|
return MapDTOMapProvider.fromJson(value);
|
|
case 'MapDTOMapType':
|
|
return MapDTOMapType.fromJson(value);
|
|
case 'MapDTOMapTypeMapbox':
|
|
return MapDTOMapTypeMapbox.fromJson(value);
|
|
case 'MapProvider':
|
|
return MapProviderTypeTransformer().decode(value);
|
|
case 'MapTypeApp':
|
|
return MapTypeAppTypeTransformer().decode(value);
|
|
case 'MapTypeMapBox':
|
|
return MapTypeMapBoxTypeTransformer().decode(value);
|
|
case 'MenuDTO':
|
|
return MenuDTO.fromJson(value);
|
|
case 'PDFFileDTO':
|
|
return PDFFileDTO.fromJson(value);
|
|
case 'PdfDTO':
|
|
return PdfDTO.fromJson(value);
|
|
case 'PlayerMessageDTO':
|
|
return PlayerMessageDTO.fromJson(value);
|
|
case 'PuzzleDTO':
|
|
return PuzzleDTO.fromJson(value);
|
|
case 'PuzzleDTOImage':
|
|
return PuzzleDTOImage.fromJson(value);
|
|
case 'QuestionDTO':
|
|
return QuestionDTO.fromJson(value);
|
|
case 'QuizzDTO':
|
|
return QuizzDTO.fromJson(value);
|
|
case 'QuizzDTOBadLevel':
|
|
return QuizzDTOBadLevel.fromJson(value);
|
|
case 'ResourceDTO':
|
|
return ResourceDTO.fromJson(value);
|
|
case 'ResourceType':
|
|
return ResourceTypeTypeTransformer().decode(value);
|
|
case 'ResponseDTO':
|
|
return ResponseDTO.fromJson(value);
|
|
case 'SectionDTO':
|
|
return SectionDTO.fromJson(value);
|
|
case 'SectionType':
|
|
return SectionTypeTypeTransformer().decode(value);
|
|
case 'SliderDTO':
|
|
return SliderDTO.fromJson(value);
|
|
case 'TokenDTO':
|
|
return TokenDTO.fromJson(value);
|
|
case 'TranslationAndResourceDTO':
|
|
return TranslationAndResourceDTO.fromJson(value);
|
|
case 'TranslationDTO':
|
|
return TranslationDTO.fromJson(value);
|
|
case 'User':
|
|
return User.fromJson(value);
|
|
case 'UserDetailDTO':
|
|
return UserDetailDTO.fromJson(value);
|
|
case 'VideoDTO':
|
|
return VideoDTO.fromJson(value);
|
|
case 'WeatherDTO':
|
|
return WeatherDTO.fromJson(value);
|
|
case 'WebDTO':
|
|
return WebDTO.fromJson(value);
|
|
default:
|
|
dynamic match;
|
|
if (value is List && (match = _regList.firstMatch(targetType)?.group(1)) != null) {
|
|
return value
|
|
.map<dynamic>((dynamic v) => _deserialize(v, match, growable: growable,))
|
|
.toList(growable: growable);
|
|
}
|
|
if (value is Set && (match = _regSet.firstMatch(targetType)?.group(1)) != null) {
|
|
return value
|
|
.map<dynamic>((dynamic v) => _deserialize(v, match, growable: growable,))
|
|
.toSet();
|
|
}
|
|
if (value is Map && (match = _regMap.firstMatch(targetType)?.group(1)) != null) {
|
|
return Map<String, dynamic>.fromIterables(
|
|
value.keys.cast<String>(),
|
|
value.values.map<dynamic>((dynamic v) => _deserialize(v, match, growable: growable,)),
|
|
);
|
|
}
|
|
}
|
|
} on Exception catch (error, trace) {
|
|
throw ApiException.withInner(HttpStatus.internalServerError, 'Exception during deserialization.', error, trace,);
|
|
}
|
|
throw ApiException(HttpStatus.internalServerError, 'Could not find a suitable class for deserialization',);
|
|
}
|
|
}
|
|
|
|
/// Primarily intended for use in an isolate.
|
|
class DeserializationMessage {
|
|
const DeserializationMessage({
|
|
required this.json,
|
|
required this.targetType,
|
|
this.growable = false,
|
|
});
|
|
|
|
/// The JSON value to deserialize.
|
|
final String json;
|
|
|
|
/// Target type to deserialize to.
|
|
final String targetType;
|
|
|
|
/// Whether to make deserialized lists or maps growable.
|
|
final bool growable;
|
|
}
|
|
|
|
/// Primarily intended for use in an isolate.
|
|
Future<dynamic> deserializeAsync(DeserializationMessage message) async {
|
|
// Remove all spaces. Necessary for regular expressions as well.
|
|
final targetType = message.targetType.replaceAll(' ', '');
|
|
|
|
// If the expected target type is String, nothing to do...
|
|
return targetType == 'String'
|
|
? message.json
|
|
: ApiClient._deserialize(
|
|
jsonDecode(message.json),
|
|
targetType,
|
|
growable: message.growable,
|
|
);
|
|
}
|
|
|
|
/// Primarily intended for use in an isolate.
|
|
Future<String> serializeAsync(Object? value) async => value == null ? '' : json.encode(value);
|