mirror of
https://github.com/fluxerapp/fluxer
synced 2026-10-07 19:22:14 +09:00
fix(api): support int53 attachment sizes (#1261)
This commit is contained in:
@@ -17,6 +17,13 @@ export const Int32TypeSchema: OpenAPISchema = {
|
||||
format: 'int32',
|
||||
};
|
||||
export const Int32TypeRef: OpenAPIRef = {$ref: '#/components/schemas/Int32Type'};
|
||||
export const NonNegativeSafeIntegerTypeSchema: OpenAPISchema = {
|
||||
type: 'integer',
|
||||
minimum: 0,
|
||||
maximum: 9007199254740991,
|
||||
format: 'int53',
|
||||
};
|
||||
export const NonNegativeSafeIntegerTypeRef: OpenAPIRef = {$ref: '#/components/schemas/NonNegativeSafeIntegerType'};
|
||||
export const Int64TypeSchema: OpenAPISchema = {
|
||||
type: 'string',
|
||||
format: 'int64',
|
||||
|
||||
@@ -371,7 +371,13 @@ export function zodToOpenAPISchema(schema: ZodTypeAny, depth = 0): OpenAPISchema
|
||||
const min = result.minimum ?? result.exclusiveMinimum;
|
||||
const max = result.maximum ?? result.exclusiveMaximum;
|
||||
if (min != null && max != null) {
|
||||
result.format = min >= -2147483648 && max <= 2147483647 ? 'int32' : 'int64';
|
||||
if (min >= -2147483648 && max <= 2147483647) {
|
||||
result.format = 'int32';
|
||||
} else if (min >= Number.MIN_SAFE_INTEGER && max <= Number.MAX_SAFE_INTEGER) {
|
||||
result.format = 'int53';
|
||||
} else {
|
||||
result.format = 'int64';
|
||||
}
|
||||
} else if (min == null && max == null) {
|
||||
result.format = 'int53';
|
||||
} else {
|
||||
|
||||
@@ -7,6 +7,7 @@ import {
|
||||
Int64StringTypeRef,
|
||||
Int64TypeRef,
|
||||
LocaleRef,
|
||||
NonNegativeSafeIntegerTypeRef,
|
||||
PasswordTypeRef,
|
||||
PhoneNumberTypeRef,
|
||||
SnowflakeTypeRef,
|
||||
@@ -51,6 +52,8 @@ function getRefForCustomTypeName(typeName: string): OpenAPISchemaOrRef | null {
|
||||
return SnowflakeTypeRef;
|
||||
case 'Int32Type':
|
||||
return Int32TypeRef;
|
||||
case 'NonNegativeSafeIntegerType':
|
||||
return NonNegativeSafeIntegerTypeRef;
|
||||
case 'Int64Type':
|
||||
return Int64TypeRef;
|
||||
case 'Int64StringType':
|
||||
@@ -217,6 +220,7 @@ const FLUXER_CUSTOM_TYPES: Record<string, OpenAPISchema> = {
|
||||
BitflagStringType: {type: 'string', format: 'int64', pattern: '^[0-9]+$'},
|
||||
ColorType: {type: 'integer', minimum: 0, maximum: 16777215, format: 'int32'},
|
||||
Int32Type: {type: 'integer', minimum: 0, maximum: 2147483647, format: 'int32'},
|
||||
NonNegativeSafeIntegerType: {type: 'integer', minimum: 0, maximum: 9007199254740991, format: 'int53'},
|
||||
EmailType: {type: 'string', format: 'email'},
|
||||
PasswordType: {type: 'string', minLength: 8, maxLength: 256},
|
||||
UsernameType: {type: 'string', minLength: 1, maxLength: 32, pattern: '^[a-zA-Z0-9_]+$'},
|
||||
|
||||
@@ -8,6 +8,7 @@ import {
|
||||
Int64StringTypeSchema,
|
||||
Int64TypeSchema,
|
||||
LocaleSchema,
|
||||
NonNegativeSafeIntegerTypeSchema,
|
||||
PasswordTypeSchema,
|
||||
PhoneNumberTypeSchema,
|
||||
SnowflakeTypeSchema,
|
||||
@@ -127,6 +128,7 @@ const BUILT_IN_SCHEMAS: ReadonlyArray<readonly [string, OpenAPISchema]> = [
|
||||
['APIErrorCode', APIErrorCodeSchema],
|
||||
['SnowflakeType', SnowflakeTypeSchema],
|
||||
['Int32Type', Int32TypeSchema],
|
||||
['NonNegativeSafeIntegerType', NonNegativeSafeIntegerTypeSchema],
|
||||
['Int64Type', Int64TypeSchema],
|
||||
['Int64StringType', Int64StringTypeSchema],
|
||||
['UnsignedInt64Type', UnsignedInt64TypeSchema],
|
||||
|
||||
@@ -253,6 +253,9 @@ export class OpenAPIOperationBuilder {
|
||||
if (typeString.includes('UnsignedInt64Type')) {
|
||||
return {type: 'string', format: 'int64', pattern: '^[0-9]+$'};
|
||||
}
|
||||
if (typeString.includes('NonNegativeSafeIntegerType')) {
|
||||
return {type: 'integer', minimum: 0, maximum: 9007199254740991, format: 'int53'};
|
||||
}
|
||||
if (typeString.includes('Int64StringType')) {
|
||||
return {type: 'string', format: 'int64', pattern: '^-?[0-9]+$'};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user