From 3d820057971ee652b8ef1207d7ddf3736d764421 Mon Sep 17 00:00:00 2001 From: Jason Rasmussen Date: Wed, 12 Jun 2024 12:36:24 -0400 Subject: [PATCH] fix: no floats (replace with doubles) (#10218) * fix: no floats (replace with doubles) * Update server/src/utils/misc.ts Co-authored-by: Zack Pollard --------- Co-authored-by: Zack Pollard --- .../lib/model/duplicate_detection_config.dart | Bin 3276 -> 3286 bytes .../lib/model/facial_recognition_config.dart | Bin 4068 -> 4088 bytes .../model/server_storage_response_dto.dart | Bin 4757 -> 4767 bytes open-api/immich-openapi-specs.json | 8 ++--- server/src/dtos/model-config.dto.ts | 6 ++-- server/src/dtos/server-info.dto.ts | 2 +- server/src/utils/misc.ts | 28 ++++++++++++++---- 7 files changed, 31 insertions(+), 13 deletions(-) diff --git a/mobile/openapi/lib/model/duplicate_detection_config.dart b/mobile/openapi/lib/model/duplicate_detection_config.dart index 4565a80c0e4f042265cf302c6ea31154844629b6..0bc60917848c4fb26daf2b053484323b5791e8e7 100644 GIT binary patch delta 68 zcmX>jc};SI1Dm-qF8lI7UUG&Y{Yqt4FJ$XAR7Px diff --git a/mobile/openapi/lib/model/server_storage_response_dto.dart b/mobile/openapi/lib/model/server_storage_response_dto.dart index ab0f169e4b827a74d47982b31b5fa8bc81f09f1c..89d97d32ead2d71dff0f97051d29a3eea1978e89 100644 GIT binary patch delta 49 zcmbQLI$w2z47adGZel@LVoqtQe_BXoL8?t&Y3^i0ZUr7qy^?&F{L-YHR1M9|f!r?a E0G;p;>Hq)$ delta 38 tcmbQQI#qRp47X@*VnJA9PHC!tT1aI;MS(4Fv!I diff --git a/open-api/immich-openapi-specs.json b/open-api/immich-openapi-specs.json index aa5cb33a59..78507452e8 100644 --- a/open-api/immich-openapi-specs.json +++ b/open-api/immich-openapi-specs.json @@ -8146,7 +8146,7 @@ "type": "boolean" }, "maxDistance": { - "format": "float", + "format": "double", "maximum": 0.1, "minimum": 0.001, "type": "number" @@ -8347,7 +8347,7 @@ "type": "boolean" }, "maxDistance": { - "format": "float", + "format": "double", "maximum": 2, "minimum": 0, "type": "number" @@ -8357,7 +8357,7 @@ "type": "integer" }, "minScore": { - "format": "float", + "format": "double", "maximum": 1, "minimum": 0, "type": "number" @@ -9797,7 +9797,7 @@ "type": "integer" }, "diskUsagePercentage": { - "format": "float", + "format": "double", "type": "number" }, "diskUse": { diff --git a/server/src/dtos/model-config.dto.ts b/server/src/dtos/model-config.dto.ts index 5dc8237414..dffacc793d 100644 --- a/server/src/dtos/model-config.dto.ts +++ b/server/src/dtos/model-config.dto.ts @@ -21,7 +21,7 @@ export class DuplicateDetectionConfig extends TaskConfig { @Min(0.001) @Max(0.1) @Type(() => Number) - @ApiProperty({ type: 'number', format: 'float' }) + @ApiProperty({ type: 'number', format: 'double' }) maxDistance!: number; } @@ -30,14 +30,14 @@ export class FacialRecognitionConfig extends ModelConfig { @Min(0) @Max(1) @Type(() => Number) - @ApiProperty({ type: 'number', format: 'float' }) + @ApiProperty({ type: 'number', format: 'double' }) minScore!: number; @IsNumber() @Min(0) @Max(2) @Type(() => Number) - @ApiProperty({ type: 'number', format: 'float' }) + @ApiProperty({ type: 'number', format: 'double' }) maxDistance!: number; @IsNumber() diff --git a/server/src/dtos/server-info.dto.ts b/server/src/dtos/server-info.dto.ts index 6afe8534c7..94a5b4df6e 100644 --- a/server/src/dtos/server-info.dto.ts +++ b/server/src/dtos/server-info.dto.ts @@ -21,7 +21,7 @@ export class ServerStorageResponseDto { @ApiProperty({ type: 'integer', format: 'int64' }) diskAvailableRaw!: number; - @ApiProperty({ type: 'number', format: 'float' }) + @ApiProperty({ type: 'number', format: 'double' }) diskUsagePercentage!: number; } diff --git a/server/src/utils/misc.ts b/server/src/utils/misc.ts index f5c0105c03..e0a2ed860e 100644 --- a/server/src/utils/misc.ts +++ b/server/src/utils/misc.ts @@ -6,7 +6,7 @@ import { SwaggerDocumentOptions, SwaggerModule, } from '@nestjs/swagger'; -import { SchemaObject } from '@nestjs/swagger/dist/interfaces/open-api-spec.interface'; +import { ReferenceObject, SchemaObject } from '@nestjs/swagger/dist/interfaces/open-api-spec.interface'; import _ from 'lodash'; import { writeFileSync } from 'node:fs'; import path from 'node:path'; @@ -111,6 +111,14 @@ function sortKeys(target: T): T { export const routeToErrorMessage = (methodName: string) => 'Failed to ' + methodName.replaceAll(/[A-Z]+/g, (letter) => ` ${letter.toLowerCase()}`); +const isSchema = (schema: string | ReferenceObject | SchemaObject): schema is SchemaObject => { + if (typeof schema === 'string' || '$ref' in schema) { + return false; + } + + return true; +}; + const patchOpenAPI = (document: OpenAPIObject) => { document.paths = sortKeys(document.paths); @@ -119,13 +127,23 @@ const patchOpenAPI = (document: OpenAPIObject) => { document.components.schemas = sortKeys(schemas); - for (const schema of Object.values(schemas)) { + for (const [schemaName, schema] of Object.entries(schemas)) { if (schema.properties) { schema.properties = sortKeys(schema.properties); - } - if (schema.required) { - schema.required = schema.required.sort(); + for (const [key, value] of Object.entries(schema.properties)) { + if (typeof value === 'string') { + continue; + } + + if (isSchema(value) && value.type === 'number' && value.format === 'float') { + throw new Error(`Invalid number format: ${schemaName}.${key}=float (use double instead). `); + } + } + + if (schema.required) { + schema.required = schema.required.sort(); + } } } }