mirror of
https://github.com/immich-app/immich
synced 2025-11-07 17:27:20 +00:00
fix: no floats (replace with doubles) (#10218)
* fix: no floats (replace with doubles) * Update server/src/utils/misc.ts Co-authored-by: Zack Pollard <zackpollard@ymail.com> --------- Co-authored-by: Zack Pollard <zackpollard@ymail.com>
This commit is contained in:
parent
10aa00af21
commit
3d82005797
7 changed files with 35 additions and 17 deletions
|
|
@ -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<T>(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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue