mirror of
https://github.com/samsonjs/immich.git
synced 2026-04-27 15:07:45 +00:00
fix(mobile): omit null values from json requests (#1212)
* chore: initial template * feat: exlude null values * chore: regenerate openapi * chore: merge * feat: store changes in a patch file * feat: extract to sh script * chore: regenerate openapi * chore: remove duplicate file * feat: generate mobile by itself * Fixed number property not decorated correctly * Revert hotfix, fix test * Merge main Co-authored-by: Alex Tran <alex.tran1502@gmail.com>
This commit is contained in:
parent
bd838a71d1
commit
079ee658a5
79 changed files with 353 additions and 18 deletions
BIN
mobile/openapi/doc/APIKeyResponseDto.md
generated
BIN
mobile/openapi/doc/APIKeyResponseDto.md
generated
Binary file not shown.
BIN
mobile/openapi/lib/model/add_assets_dto.dart
generated
BIN
mobile/openapi/lib/model/add_assets_dto.dart
generated
Binary file not shown.
BIN
mobile/openapi/lib/model/add_assets_response_dto.dart
generated
BIN
mobile/openapi/lib/model/add_assets_response_dto.dart
generated
Binary file not shown.
BIN
mobile/openapi/lib/model/add_users_dto.dart
generated
BIN
mobile/openapi/lib/model/add_users_dto.dart
generated
Binary file not shown.
BIN
mobile/openapi/lib/model/admin_signup_response_dto.dart
generated
BIN
mobile/openapi/lib/model/admin_signup_response_dto.dart
generated
Binary file not shown.
BIN
mobile/openapi/lib/model/album_count_response_dto.dart
generated
BIN
mobile/openapi/lib/model/album_count_response_dto.dart
generated
Binary file not shown.
BIN
mobile/openapi/lib/model/album_response_dto.dart
generated
BIN
mobile/openapi/lib/model/album_response_dto.dart
generated
Binary file not shown.
Binary file not shown.
BIN
mobile/openapi/lib/model/api_key_create_dto.dart
generated
BIN
mobile/openapi/lib/model/api_key_create_dto.dart
generated
Binary file not shown.
Binary file not shown.
BIN
mobile/openapi/lib/model/api_key_response_dto.dart
generated
BIN
mobile/openapi/lib/model/api_key_response_dto.dart
generated
Binary file not shown.
BIN
mobile/openapi/lib/model/api_key_update_dto.dart
generated
BIN
mobile/openapi/lib/model/api_key_update_dto.dart
generated
Binary file not shown.
BIN
mobile/openapi/lib/model/asset_count_by_time_bucket.dart
generated
BIN
mobile/openapi/lib/model/asset_count_by_time_bucket.dart
generated
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
mobile/openapi/lib/model/asset_response_dto.dart
generated
BIN
mobile/openapi/lib/model/asset_response_dto.dart
generated
Binary file not shown.
BIN
mobile/openapi/lib/model/change_password_dto.dart
generated
BIN
mobile/openapi/lib/model/change_password_dto.dart
generated
Binary file not shown.
BIN
mobile/openapi/lib/model/check_duplicate_asset_dto.dart
generated
BIN
mobile/openapi/lib/model/check_duplicate_asset_dto.dart
generated
Binary file not shown.
Binary file not shown.
BIN
mobile/openapi/lib/model/check_existing_assets_dto.dart
generated
BIN
mobile/openapi/lib/model/check_existing_assets_dto.dart
generated
Binary file not shown.
Binary file not shown.
BIN
mobile/openapi/lib/model/create_album_dto.dart
generated
BIN
mobile/openapi/lib/model/create_album_dto.dart
generated
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
mobile/openapi/lib/model/create_tag_dto.dart
generated
BIN
mobile/openapi/lib/model/create_tag_dto.dart
generated
Binary file not shown.
BIN
mobile/openapi/lib/model/create_user_dto.dart
generated
BIN
mobile/openapi/lib/model/create_user_dto.dart
generated
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
mobile/openapi/lib/model/delete_asset_dto.dart
generated
BIN
mobile/openapi/lib/model/delete_asset_dto.dart
generated
Binary file not shown.
BIN
mobile/openapi/lib/model/delete_asset_response_dto.dart
generated
BIN
mobile/openapi/lib/model/delete_asset_response_dto.dart
generated
Binary file not shown.
BIN
mobile/openapi/lib/model/device_info_response_dto.dart
generated
BIN
mobile/openapi/lib/model/device_info_response_dto.dart
generated
Binary file not shown.
BIN
mobile/openapi/lib/model/download_files_dto.dart
generated
BIN
mobile/openapi/lib/model/download_files_dto.dart
generated
Binary file not shown.
BIN
mobile/openapi/lib/model/edit_shared_link_dto.dart
generated
BIN
mobile/openapi/lib/model/edit_shared_link_dto.dart
generated
Binary file not shown.
BIN
mobile/openapi/lib/model/exif_response_dto.dart
generated
BIN
mobile/openapi/lib/model/exif_response_dto.dart
generated
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
mobile/openapi/lib/model/job_command_dto.dart
generated
BIN
mobile/openapi/lib/model/job_command_dto.dart
generated
Binary file not shown.
BIN
mobile/openapi/lib/model/job_counts.dart
generated
BIN
mobile/openapi/lib/model/job_counts.dart
generated
Binary file not shown.
BIN
mobile/openapi/lib/model/job_status_response_dto.dart
generated
BIN
mobile/openapi/lib/model/job_status_response_dto.dart
generated
Binary file not shown.
BIN
mobile/openapi/lib/model/login_credential_dto.dart
generated
BIN
mobile/openapi/lib/model/login_credential_dto.dart
generated
Binary file not shown.
BIN
mobile/openapi/lib/model/login_response_dto.dart
generated
BIN
mobile/openapi/lib/model/login_response_dto.dart
generated
Binary file not shown.
BIN
mobile/openapi/lib/model/logout_response_dto.dart
generated
BIN
mobile/openapi/lib/model/logout_response_dto.dart
generated
Binary file not shown.
BIN
mobile/openapi/lib/model/o_auth_callback_dto.dart
generated
BIN
mobile/openapi/lib/model/o_auth_callback_dto.dart
generated
Binary file not shown.
BIN
mobile/openapi/lib/model/o_auth_config_dto.dart
generated
BIN
mobile/openapi/lib/model/o_auth_config_dto.dart
generated
Binary file not shown.
BIN
mobile/openapi/lib/model/o_auth_config_response_dto.dart
generated
BIN
mobile/openapi/lib/model/o_auth_config_response_dto.dart
generated
Binary file not shown.
BIN
mobile/openapi/lib/model/remove_assets_dto.dart
generated
BIN
mobile/openapi/lib/model/remove_assets_dto.dart
generated
Binary file not shown.
BIN
mobile/openapi/lib/model/search_asset_dto.dart
generated
BIN
mobile/openapi/lib/model/search_asset_dto.dart
generated
Binary file not shown.
BIN
mobile/openapi/lib/model/server_info_response_dto.dart
generated
BIN
mobile/openapi/lib/model/server_info_response_dto.dart
generated
Binary file not shown.
BIN
mobile/openapi/lib/model/server_ping_response.dart
generated
BIN
mobile/openapi/lib/model/server_ping_response.dart
generated
Binary file not shown.
BIN
mobile/openapi/lib/model/server_stats_response_dto.dart
generated
BIN
mobile/openapi/lib/model/server_stats_response_dto.dart
generated
Binary file not shown.
BIN
mobile/openapi/lib/model/server_version_reponse_dto.dart
generated
BIN
mobile/openapi/lib/model/server_version_reponse_dto.dart
generated
Binary file not shown.
BIN
mobile/openapi/lib/model/shared_link_response_dto.dart
generated
BIN
mobile/openapi/lib/model/shared_link_response_dto.dart
generated
Binary file not shown.
BIN
mobile/openapi/lib/model/sign_up_dto.dart
generated
BIN
mobile/openapi/lib/model/sign_up_dto.dart
generated
Binary file not shown.
BIN
mobile/openapi/lib/model/smart_info_response_dto.dart
generated
BIN
mobile/openapi/lib/model/smart_info_response_dto.dart
generated
Binary file not shown.
BIN
mobile/openapi/lib/model/system_config_dto.dart
generated
BIN
mobile/openapi/lib/model/system_config_dto.dart
generated
Binary file not shown.
BIN
mobile/openapi/lib/model/system_config_f_fmpeg_dto.dart
generated
BIN
mobile/openapi/lib/model/system_config_f_fmpeg_dto.dart
generated
Binary file not shown.
BIN
mobile/openapi/lib/model/system_config_o_auth_dto.dart
generated
BIN
mobile/openapi/lib/model/system_config_o_auth_dto.dart
generated
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
mobile/openapi/lib/model/tag_response_dto.dart
generated
BIN
mobile/openapi/lib/model/tag_response_dto.dart
generated
Binary file not shown.
BIN
mobile/openapi/lib/model/update_album_dto.dart
generated
BIN
mobile/openapi/lib/model/update_album_dto.dart
generated
Binary file not shown.
BIN
mobile/openapi/lib/model/update_asset_dto.dart
generated
BIN
mobile/openapi/lib/model/update_asset_dto.dart
generated
Binary file not shown.
BIN
mobile/openapi/lib/model/update_tag_dto.dart
generated
BIN
mobile/openapi/lib/model/update_tag_dto.dart
generated
Binary file not shown.
BIN
mobile/openapi/lib/model/update_user_dto.dart
generated
BIN
mobile/openapi/lib/model/update_user_dto.dart
generated
Binary file not shown.
BIN
mobile/openapi/lib/model/upsert_device_info_dto.dart
generated
BIN
mobile/openapi/lib/model/upsert_device_info_dto.dart
generated
Binary file not shown.
BIN
mobile/openapi/lib/model/usage_by_user_dto.dart
generated
BIN
mobile/openapi/lib/model/usage_by_user_dto.dart
generated
Binary file not shown.
BIN
mobile/openapi/lib/model/user_count_response_dto.dart
generated
BIN
mobile/openapi/lib/model/user_count_response_dto.dart
generated
Binary file not shown.
BIN
mobile/openapi/lib/model/user_response_dto.dart
generated
BIN
mobile/openapi/lib/model/user_response_dto.dart
generated
Binary file not shown.
Binary file not shown.
BIN
mobile/openapi/test/api_key_response_dto_test.dart
generated
BIN
mobile/openapi/test/api_key_response_dto_test.dart
generated
Binary file not shown.
|
|
@ -1,6 +1,8 @@
|
||||||
import { APIKeyEntity } from '@app/database';
|
import { APIKeyEntity } from '@app/database';
|
||||||
|
import { ApiProperty } from '@nestjs/swagger';
|
||||||
|
|
||||||
export class APIKeyResponseDto {
|
export class APIKeyResponseDto {
|
||||||
|
@ApiProperty({ type: 'integer' })
|
||||||
id!: number;
|
id!: number;
|
||||||
name!: string;
|
name!: string;
|
||||||
createdAt!: string;
|
createdAt!: string;
|
||||||
|
|
|
||||||
|
|
@ -35,25 +35,12 @@ export class UserCore {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const user = await this.userRepository.get(id);
|
|
||||||
if (!user) {
|
|
||||||
throw new NotFoundException('User not found');
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (dto.password) {
|
if (dto.password) {
|
||||||
dto.password = await hash(dto.password, SALT_ROUNDS);
|
dto.password = await hash(dto.password, SALT_ROUNDS);
|
||||||
}
|
}
|
||||||
|
|
||||||
user.password = dto.password ?? user.password;
|
return this.userRepository.update(id, dto);
|
||||||
user.email = dto.email ?? user.email;
|
|
||||||
user.firstName = dto.firstName ?? user.firstName;
|
|
||||||
user.lastName = dto.lastName ?? user.lastName;
|
|
||||||
user.isAdmin = dto.isAdmin ?? user.isAdmin;
|
|
||||||
user.shouldChangePassword = dto.shouldChangePassword ?? user.shouldChangePassword;
|
|
||||||
user.profileImagePath = dto.profileImagePath ?? user.profileImagePath;
|
|
||||||
|
|
||||||
return this.userRepository.update(id, user);
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
Logger.error(e, 'Failed to update user info');
|
Logger.error(e, 'Failed to update user info');
|
||||||
throw new InternalServerErrorException('Failed to update user info');
|
throw new InternalServerErrorException('Failed to update user info');
|
||||||
|
|
|
||||||
24
server/bin/generate-open-api.sh
Executable file
24
server/bin/generate-open-api.sh
Executable file
|
|
@ -0,0 +1,24 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
function mobile {
|
||||||
|
rm -rf ../mobile/openapi
|
||||||
|
cd ./openapi-generator/templates/serialization/native
|
||||||
|
wget -O native_class.mustache https://raw.githubusercontent.com/OpenAPITools/openapi-generator/master/modules/openapi-generator/src/main/resources/dart2/serialization/native/native_class.mustache
|
||||||
|
patch -u native_class.mustache <native_class.mustache.patch
|
||||||
|
cd ../../../..
|
||||||
|
npx openapi-generator-cli generate -g dart -i ./immich-openapi-specs.json -o ../mobile/openapi -t ./openapi-generator/templates
|
||||||
|
}
|
||||||
|
|
||||||
|
function web {
|
||||||
|
rm -rf ../web/src/api/open-api
|
||||||
|
npx openapi-generator-cli generate -g typescript-axios -i ./immich-openapi-specs.json -o ../web/src/api/open-api
|
||||||
|
}
|
||||||
|
|
||||||
|
if [[ $1 == 'mobile' ]]; then
|
||||||
|
mobile
|
||||||
|
elif [[ $1 == 'web' ]]; then
|
||||||
|
web
|
||||||
|
else
|
||||||
|
mobile
|
||||||
|
web
|
||||||
|
fi
|
||||||
|
|
@ -2834,7 +2834,7 @@
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
"id": {
|
"id": {
|
||||||
"type": "number"
|
"type": "integer"
|
||||||
},
|
},
|
||||||
"name": {
|
"name": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,303 @@
|
||||||
|
class {{{classname}}} {
|
||||||
|
{{>dart_constructor}}
|
||||||
|
{{#vars}}
|
||||||
|
{{#description}}
|
||||||
|
/// {{{.}}}
|
||||||
|
{{/description}}
|
||||||
|
{{^isEnum}}
|
||||||
|
{{#minimum}}
|
||||||
|
{{#description}}
|
||||||
|
///
|
||||||
|
{{/description}}
|
||||||
|
/// Minimum value: {{{.}}}
|
||||||
|
{{/minimum}}
|
||||||
|
{{#maximum}}
|
||||||
|
{{#description}}
|
||||||
|
{{^minimum}}
|
||||||
|
///
|
||||||
|
{{/minimum}}
|
||||||
|
{{/description}}
|
||||||
|
/// Maximum value: {{{.}}}
|
||||||
|
{{/maximum}}
|
||||||
|
{{^isNullable}}
|
||||||
|
{{^required}}
|
||||||
|
{{^defaultValue}}
|
||||||
|
///
|
||||||
|
/// Please note: This property should have been non-nullable! Since the specification file
|
||||||
|
/// does not include a default value (using the "default:" property), however, the generated
|
||||||
|
/// source code must fall back to having a nullable type.
|
||||||
|
/// Consider adding a "default:" property in the specification file to hide this note.
|
||||||
|
///
|
||||||
|
{{/defaultValue}}
|
||||||
|
{{/required}}
|
||||||
|
{{/isNullable}}
|
||||||
|
{{/isEnum}}
|
||||||
|
{{{datatypeWithEnum}}}{{#isNullable}}?{{/isNullable}}{{^isNullable}}{{^required}}{{^defaultValue}}?{{/defaultValue}}{{/required}}{{/isNullable}} {{{name}}};
|
||||||
|
|
||||||
|
{{/vars}}
|
||||||
|
@override
|
||||||
|
bool operator ==(Object other) => identical(this, other) || other is {{{classname}}} &&
|
||||||
|
{{#vars}}
|
||||||
|
other.{{{name}}} == {{{name}}}{{^-last}} &&{{/-last}}{{#-last}};{{/-last}}
|
||||||
|
{{/vars}}
|
||||||
|
|
||||||
|
@override
|
||||||
|
int get hashCode =>
|
||||||
|
// ignore: unnecessary_parenthesis
|
||||||
|
{{#vars}}
|
||||||
|
({{#isNullable}}{{{name}}} == null ? 0 : {{/isNullable}}{{^isNullable}}{{^required}}{{^defaultValue}}{{{name}}} == null ? 0 : {{/defaultValue}}{{/required}}{{/isNullable}}{{{name}}}{{#isNullable}}!{{/isNullable}}{{^isNullable}}{{^required}}{{^defaultValue}}!{{/defaultValue}}{{/required}}{{/isNullable}}.hashCode){{^-last}} +{{/-last}}{{#-last}};{{/-last}}
|
||||||
|
{{/vars}}
|
||||||
|
|
||||||
|
@override
|
||||||
|
String toString() => '{{{classname}}}[{{#vars}}{{{name}}}=${{{name}}}{{^-last}}, {{/-last}}{{/vars}}]';
|
||||||
|
|
||||||
|
Map<String, dynamic> toJson() {
|
||||||
|
final json = <String, dynamic>{};
|
||||||
|
{{#vars}}
|
||||||
|
{{#isNullable}}
|
||||||
|
if (this.{{{name}}} != null) {
|
||||||
|
{{/isNullable}}
|
||||||
|
{{^isNullable}}
|
||||||
|
{{^required}}
|
||||||
|
{{^defaultValue}}
|
||||||
|
if (this.{{{name}}} != null) {
|
||||||
|
{{/defaultValue}}
|
||||||
|
{{/required}}
|
||||||
|
{{/isNullable}}
|
||||||
|
{{#isDateTime}}
|
||||||
|
{{#pattern}}
|
||||||
|
json[r'{{{baseName}}}'] = _dateEpochMarker == '{{{pattern}}}'
|
||||||
|
? this.{{{name}}}{{#isNullable}}!{{/isNullable}}{{^isNullable}}{{^required}}{{^defaultValue}}!{{/defaultValue}}{{/required}}{{/isNullable}}.millisecondsSinceEpoch
|
||||||
|
: this.{{{name}}}{{#isNullable}}!{{/isNullable}}{{^isNullable}}{{^required}}{{^defaultValue}}!{{/defaultValue}}{{/required}}{{/isNullable}}.toUtc().toIso8601String();
|
||||||
|
{{/pattern}}
|
||||||
|
{{^pattern}}
|
||||||
|
json[r'{{{baseName}}}'] = this.{{{name}}}{{#isNullable}}!{{/isNullable}}{{^isNullable}}{{^required}}{{^defaultValue}}!{{/defaultValue}}{{/required}}{{/isNullable}}.toUtc().toIso8601String();
|
||||||
|
{{/pattern}}
|
||||||
|
{{/isDateTime}}
|
||||||
|
{{#isDate}}
|
||||||
|
{{#pattern}}
|
||||||
|
json[r'{{{baseName}}}'] = _dateEpochMarker == '{{{pattern}}}'
|
||||||
|
? this.{{{name}}}{{#isNullable}}!{{/isNullable}}{{^isNullable}}{{^required}}{{^defaultValue}}!{{/defaultValue}}{{/required}}{{/isNullable}}.millisecondsSinceEpoch
|
||||||
|
: _dateFormatter.format(this.{{{name}}}{{#isNullable}}!{{/isNullable}}{{^isNullable}}{{^required}}{{^defaultValue}}!{{/defaultValue}}{{/required}}{{/isNullable}}.toUtc());
|
||||||
|
{{/pattern}}
|
||||||
|
{{^pattern}}
|
||||||
|
json[r'{{{baseName}}}'] = _dateFormatter.format(this.{{{name}}}{{#isNullable}}!{{/isNullable}}{{^isNullable}}{{^required}}{{^defaultValue}}!{{/defaultValue}}{{/required}}{{/isNullable}}.toUtc());
|
||||||
|
{{/pattern}}
|
||||||
|
{{/isDate}}
|
||||||
|
{{^isDateTime}}
|
||||||
|
{{^isDate}}
|
||||||
|
json[r'{{{baseName}}}'] = this.{{{name}}};
|
||||||
|
{{/isDate}}
|
||||||
|
{{/isDateTime}}
|
||||||
|
{{#isNullable}}
|
||||||
|
} else {
|
||||||
|
// json[r'{{{baseName}}}'] = null;
|
||||||
|
}
|
||||||
|
{{/isNullable}}
|
||||||
|
{{^isNullable}}
|
||||||
|
{{^required}}
|
||||||
|
{{^defaultValue}}
|
||||||
|
} else {
|
||||||
|
// json[r'{{{baseName}}}'] = null;
|
||||||
|
}
|
||||||
|
{{/defaultValue}}
|
||||||
|
{{/required}}
|
||||||
|
{{/isNullable}}
|
||||||
|
{{/vars}}
|
||||||
|
return json;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns a new [{{{classname}}}] instance and imports its values from
|
||||||
|
/// [value] if it's a [Map], null otherwise.
|
||||||
|
// ignore: prefer_constructors_over_static_methods
|
||||||
|
static {{{classname}}}? fromJson(dynamic value) {
|
||||||
|
if (value is Map) {
|
||||||
|
final json = value.cast<String, dynamic>();
|
||||||
|
|
||||||
|
// Ensure that the map contains the required keys.
|
||||||
|
// Note 1: the values aren't checked for validity beyond being non-null.
|
||||||
|
// Note 2: this code is stripped in release mode!
|
||||||
|
assert(() {
|
||||||
|
requiredKeys.forEach((key) {
|
||||||
|
assert(json.containsKey(key), 'Required key "{{{classname}}}[$key]" is missing from JSON.');
|
||||||
|
assert(json[key] != null, 'Required key "{{{classname}}}[$key]" has a null value in JSON.');
|
||||||
|
});
|
||||||
|
return true;
|
||||||
|
}());
|
||||||
|
|
||||||
|
return {{{classname}}}(
|
||||||
|
{{#vars}}
|
||||||
|
{{#isDateTime}}
|
||||||
|
{{{name}}}: mapDateTime(json, r'{{{baseName}}}', '{{{pattern}}}'){{#required}}{{^isNullable}}!{{/isNullable}}{{/required}}{{^required}}{{#defaultValue}} ?? {{{.}}}{{/defaultValue}}{{/required}},
|
||||||
|
{{/isDateTime}}
|
||||||
|
{{#isDate}}
|
||||||
|
{{{name}}}: mapDateTime(json, r'{{{baseName}}}', '{{{pattern}}}'){{#required}}{{^isNullable}}!{{/isNullable}}{{/required}}{{^required}}{{#defaultValue}} ?? {{{.}}}{{/defaultValue}}{{/required}},
|
||||||
|
{{/isDate}}
|
||||||
|
{{^isDateTime}}
|
||||||
|
{{^isDate}}
|
||||||
|
{{#complexType}}
|
||||||
|
{{#isArray}}
|
||||||
|
{{#items.isArray}}
|
||||||
|
{{{name}}}: json[r'{{{baseName}}}'] is List
|
||||||
|
? (json[r'{{{baseName}}}'] as List).map((e) =>
|
||||||
|
{{#items.complexType}}
|
||||||
|
{{items.complexType}}.listFromJson(json[r'{{{baseName}}}']){{#required}}{{^isNullable}}!{{/isNullable}}{{/required}}{{^required}}{{#defaultValue}} ?? {{{.}}}{{/defaultValue}}{{/required}}
|
||||||
|
{{/items.complexType}}
|
||||||
|
{{^items.complexType}}
|
||||||
|
e == null ? {{#items.isNullable}}null{{/items.isNullable}}{{^items.isNullable}}const <{{items.items.dataType}}>[]{{/items.isNullable}} : (e as List).cast<{{items.items.dataType}}>()
|
||||||
|
{{/items.complexType}}
|
||||||
|
).toList()
|
||||||
|
: {{#isNullable}}null{{/isNullable}}{{^isNullable}}const []{{/isNullable}},
|
||||||
|
{{/items.isArray}}
|
||||||
|
{{^items.isArray}}
|
||||||
|
{{{name}}}: {{{complexType}}}.listFromJson(json[r'{{{baseName}}}']){{#required}}{{^isNullable}}!{{/isNullable}}{{/required}}{{^required}}{{#defaultValue}} ?? {{{.}}}{{/defaultValue}}{{/required}},
|
||||||
|
{{/items.isArray}}
|
||||||
|
{{/isArray}}
|
||||||
|
{{^isArray}}
|
||||||
|
{{#isMap}}
|
||||||
|
{{#items.isArray}}
|
||||||
|
{{{name}}}: json[r'{{{baseName}}}'] == null
|
||||||
|
? {{#defaultValue}}{{{.}}}{{/defaultValue}}{{^defaultValue}}null{{/defaultValue}}
|
||||||
|
{{#items.complexType}}
|
||||||
|
: {{items.complexType}}.mapListFromJson(json[r'{{{baseName}}}']),
|
||||||
|
{{/items.complexType}}
|
||||||
|
{{^items.complexType}}
|
||||||
|
: mapCastOfType<String, List>(json, r'{{{baseName}}}'),
|
||||||
|
{{/items.complexType}}
|
||||||
|
{{/items.isArray}}
|
||||||
|
{{^items.isArray}}
|
||||||
|
{{#items.isMap}}
|
||||||
|
{{#items.complexType}}
|
||||||
|
{{{name}}}: {{items.complexType}}.mapFromJson(json[r'{{{baseName}}}']){{#required}}{{^isNullable}}!{{/isNullable}}{{/required}}{{^required}}{{#defaultValue}} ?? {{{.}}}{{/defaultValue}}{{/required}},
|
||||||
|
{{/items.complexType}}
|
||||||
|
{{^items.complexType}}
|
||||||
|
{{{name}}}: mapCastOfType<String, dynamic>(json, r'{{{baseName}}}'){{#required}}{{^isNullable}}!{{/isNullable}}{{/required}}{{^required}}{{#defaultValue}} ?? {{{.}}}{{/defaultValue}}{{/required}},
|
||||||
|
{{/items.complexType}}
|
||||||
|
{{/items.isMap}}
|
||||||
|
{{^items.isMap}}
|
||||||
|
{{#items.complexType}}
|
||||||
|
{{{name}}}: {{{items.complexType}}}.mapFromJson(json[r'{{{baseName}}}'{{#required}}{{^isNullable}}!{{/isNullable}}{{/required}}{{^required}}{{#defaultValue}}]) ?? {{{.}}}{{/defaultValue}}{{/required}},
|
||||||
|
{{/items.complexType}}
|
||||||
|
{{^items.complexType}}
|
||||||
|
{{{name}}}: mapCastOfType<String, {{items.dataType}}>(json, r'{{{baseName}}}'){{#required}}{{^isNullable}}!{{/isNullable}}{{/required}}{{^required}}{{#defaultValue}} ?? {{{.}}}{{/defaultValue}}{{/required}},
|
||||||
|
{{/items.complexType}}
|
||||||
|
{{/items.isMap}}
|
||||||
|
{{/items.isArray}}
|
||||||
|
{{/isMap}}
|
||||||
|
{{^isMap}}
|
||||||
|
{{#isBinary}}
|
||||||
|
{{{name}}}: null, // No support for decoding binary content from JSON
|
||||||
|
{{/isBinary}}
|
||||||
|
{{^isBinary}}
|
||||||
|
{{{name}}}: {{{complexType}}}.fromJson(json[r'{{{baseName}}}']){{#required}}{{^isNullable}}!{{/isNullable}}{{/required}}{{^required}}{{#defaultValue}} ?? {{{.}}}{{/defaultValue}}{{/required}},
|
||||||
|
{{/isBinary}}
|
||||||
|
{{/isMap}}
|
||||||
|
{{/isArray}}
|
||||||
|
{{/complexType}}
|
||||||
|
{{^complexType}}
|
||||||
|
{{#isArray}}
|
||||||
|
{{#isEnum}}
|
||||||
|
{{{name}}}: {{{items.datatypeWithEnum}}}.listFromJson(json[r'{{{baseName}}}']){{#required}}{{^isNullable}}!{{/isNullable}}{{/required}}{{^required}}{{#defaultValue}} ?? {{{.}}}{{/defaultValue}}{{/required}},
|
||||||
|
{{/isEnum}}
|
||||||
|
{{^isEnum}}
|
||||||
|
{{{name}}}: json[r'{{{baseName}}}'] is {{#uniqueItems}}Set{{/uniqueItems}}{{^uniqueItems}}List{{/uniqueItems}}
|
||||||
|
? (json[r'{{{baseName}}}'] as {{#uniqueItems}}Set{{/uniqueItems}}{{^uniqueItems}}List{{/uniqueItems}}).cast<{{{items.datatype}}}>()
|
||||||
|
: {{#defaultValue}}{{{.}}}{{/defaultValue}}{{^defaultValue}}null{{/defaultValue}},
|
||||||
|
{{/isEnum}}
|
||||||
|
{{/isArray}}
|
||||||
|
{{^isArray}}
|
||||||
|
{{#isMap}}
|
||||||
|
{{{name}}}: mapCastOfType<String, {{{items.datatype}}}>(json, r'{{{baseName}}}'){{#required}}{{^isNullable}}!{{/isNullable}}{{/required}}{{^required}}{{#defaultValue}} ?? {{{.}}}{{/defaultValue}}{{/required}},
|
||||||
|
{{/isMap}}
|
||||||
|
{{^isMap}}
|
||||||
|
{{#isNumber}}
|
||||||
|
{{{name}}}: json[r'{{{baseName}}}'] == null
|
||||||
|
? {{#defaultValue}}{{{.}}}{{/defaultValue}}{{^defaultValue}}null{{/defaultValue}}
|
||||||
|
: {{{datatypeWithEnum}}}.parse(json[r'{{{baseName}}}'].toString()),
|
||||||
|
{{/isNumber}}
|
||||||
|
{{^isNumber}}
|
||||||
|
{{^isEnum}}
|
||||||
|
{{{name}}}: mapValueOfType<{{{datatypeWithEnum}}}>(json, r'{{{baseName}}}'){{#required}}{{^isNullable}}!{{/isNullable}}{{/required}}{{^required}}{{#defaultValue}} ?? {{{.}}}{{/defaultValue}}{{/required}},
|
||||||
|
{{/isEnum}}
|
||||||
|
{{#isEnum}}
|
||||||
|
{{{name}}}: {{{enumName}}}.fromJson(json[r'{{{baseName}}}']){{#required}}{{^isNullable}}!{{/isNullable}}{{/required}}{{^required}}{{#defaultValue}} ?? {{{.}}}{{/defaultValue}}{{/required}},
|
||||||
|
{{/isEnum}}
|
||||||
|
{{/isNumber}}
|
||||||
|
{{/isMap}}
|
||||||
|
{{/isArray}}
|
||||||
|
{{/complexType}}
|
||||||
|
{{/isDate}}
|
||||||
|
{{/isDateTime}}
|
||||||
|
{{/vars}}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
static List<{{{classname}}}>? listFromJson(dynamic json, {bool growable = false,}) {
|
||||||
|
final result = <{{{classname}}}>[];
|
||||||
|
if (json is List && json.isNotEmpty) {
|
||||||
|
for (final row in json) {
|
||||||
|
final value = {{{classname}}}.fromJson(row);
|
||||||
|
if (value != null) {
|
||||||
|
result.add(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result.toList(growable: growable);
|
||||||
|
}
|
||||||
|
|
||||||
|
static Map<String, {{{classname}}}> mapFromJson(dynamic json) {
|
||||||
|
final map = <String, {{{classname}}}>{};
|
||||||
|
if (json is Map && json.isNotEmpty) {
|
||||||
|
json = json.cast<String, dynamic>(); // ignore: parameter_assignments
|
||||||
|
for (final entry in json.entries) {
|
||||||
|
final value = {{{classname}}}.fromJson(entry.value);
|
||||||
|
if (value != null) {
|
||||||
|
map[entry.key] = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
|
||||||
|
// maps a json object with a list of {{{classname}}}-objects as value to a dart map
|
||||||
|
static Map<String, List<{{{classname}}}>> mapListFromJson(dynamic json, {bool growable = false,}) {
|
||||||
|
final map = <String, List<{{{classname}}}>>{};
|
||||||
|
if (json is Map && json.isNotEmpty) {
|
||||||
|
json = json.cast<String, dynamic>(); // ignore: parameter_assignments
|
||||||
|
for (final entry in json.entries) {
|
||||||
|
final value = {{{classname}}}.listFromJson(entry.value, growable: growable,);
|
||||||
|
if (value != null) {
|
||||||
|
map[entry.key] = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The list of required keys that must be present in a JSON.
|
||||||
|
static const requiredKeys = <String>{
|
||||||
|
{{#vars}}
|
||||||
|
{{#required}}
|
||||||
|
'{{{baseName}}}',
|
||||||
|
{{/required}}
|
||||||
|
{{/vars}}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
{{#vars}}
|
||||||
|
{{^isModel}}
|
||||||
|
{{#isEnum}}
|
||||||
|
{{^isContainer}}
|
||||||
|
|
||||||
|
{{>serialization/native/native_enum_inline}}
|
||||||
|
{{/isContainer}}
|
||||||
|
{{#isContainer}}
|
||||||
|
{{#mostInnerItems}}
|
||||||
|
|
||||||
|
{{>serialization/native/native_enum_inline}}
|
||||||
|
{{/mostInnerItems}}
|
||||||
|
{{/isContainer}}
|
||||||
|
{{/isEnum}}
|
||||||
|
{{/isModel}}
|
||||||
|
{{/vars}}
|
||||||
|
|
@ -0,0 +1,19 @@
|
||||||
|
--- native_class.mustache 2023-01-04 09:58:25.683944036 -0500
|
||||||
|
+++ native_class1.mustache 2023-01-04 09:59:43.856353945 -0500
|
||||||
|
@@ -91,14 +91,14 @@
|
||||||
|
{{/isDateTime}}
|
||||||
|
{{#isNullable}}
|
||||||
|
} else {
|
||||||
|
- json[r'{{{baseName}}}'] = null;
|
||||||
|
+ // json[r'{{{baseName}}}'] = null;
|
||||||
|
}
|
||||||
|
{{/isNullable}}
|
||||||
|
{{^isNullable}}
|
||||||
|
{{^required}}
|
||||||
|
{{^defaultValue}}
|
||||||
|
} else {
|
||||||
|
- json[r'{{{baseName}}}'] = null;
|
||||||
|
+ // json[r'{{{baseName}}}'] = null;
|
||||||
|
}
|
||||||
|
{{/defaultValue}}
|
||||||
|
{{/required}}
|
||||||
|
|
@ -27,9 +27,9 @@
|
||||||
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
|
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
|
||||||
"test:e2e": "jest --config ./apps/immich/test/jest-e2e.json",
|
"test:e2e": "jest --config ./apps/immich/test/jest-e2e.json",
|
||||||
"typeorm": "node --require ts-node/register ./node_modules/typeorm/cli.js",
|
"typeorm": "node --require ts-node/register ./node_modules/typeorm/cli.js",
|
||||||
"api:typescript": "rm -rf ../web/src/api/open-api && npx openapi-generator-cli generate -g typescript-axios -i ./immich-openapi-specs.json -o ../web/src/api/open-api",
|
"api:typescript": "bash ./bin/generate-open-api.sh web",
|
||||||
"api:dart": "rm -rf ../mobile/openapi && npx openapi-generator-cli generate -g dart -i ./immich-openapi-specs.json -o ../mobile/openapi",
|
"api:dart": "bash ./bin/generate-open-api.sh mobile",
|
||||||
"api:generate": "npm run api:typescript && npm run api:dart"
|
"api:generate": "bash ./bin/generate-open-api.sh"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@nestjs/bull": "^0.5.5",
|
"@nestjs/bull": "^0.5.5",
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue