Skip to content

Commit f1a2ca4

Browse files
authored
feat: cast date field from datetime to date string format (#3673)
1 parent 8d8f1e8 commit f1a2ca4

File tree

4 files changed

+10
-4
lines changed

4 files changed

+10
-4
lines changed

src/runtime/internal/schema.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const propertyTypes = {
55
number: 'INT',
66
boolean: 'BOOLEAN',
77
date: 'DATE',
8+
datetime: 'DATETIME',
89
enum: 'VARCHAR',
910
object: 'TEXT',
1011
}
@@ -33,10 +34,14 @@ function getPropertyType(property: Draft07DefinitionProperty | Draft07Definition
3334
const propertyType = (property as Draft07DefinitionProperty).type
3435
let type = propertyTypes[propertyType as keyof typeof propertyTypes] || 'TEXT'
3536

36-
if ((property as Draft07DefinitionProperty).format === 'date-time') {
37+
if ((property as Draft07DefinitionProperty).format === 'date') {
3738
type = 'DATE'
3839
}
3940

41+
if ((property as Draft07DefinitionProperty).format === 'date-time') {
42+
type = 'DATETIME'
43+
}
44+
4045
if ((property as Draft07DefinitionPropertyAllOf).allOf) {
4146
type = 'TEXT'
4247
}

src/utils/schema/valibot.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export function toJSONSchema(schema: unknown, name: string): Draft07 {
66
const definitions = valibotToJsonSchema(schema as any, {
77
overrideSchema(context) {
88
if (context.valibotSchema.type === 'date') {
9-
return { type: 'string', format: 'date-time' }
9+
return { type: 'string', format: 'date' }
1010
}
1111
if ((context.valibotSchema as unknown as { $content: Record<string, unknown> }).$content) {
1212
return {

src/utils/schema/zod3.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,13 @@ export const z = zod
3030

3131
export function toJSONSchema(_schema: unknown, name: string): Draft07 {
3232
const schema = _schema as zod.ZodSchema
33-
const jsonSchema = zodToJsonSchema(schema, { name, $refStrategy: 'none' }) as Draft07
33+
const jsonSchema = zodToJsonSchema(schema, { name, $refStrategy: 'none', dateStrategy: 'format:date' }) as Draft07
3434
const jsonSchemaWithEditorMeta = zodToJsonSchema(
3535
schema,
3636
{
3737
name,
3838
$refStrategy: 'none',
39+
dateStrategy: 'format:date',
3940
override: (_def) => {
4041
const def = _def as unknown as Record<string, unknown>
4142
if (def.editor) {

src/utils/schema/zod4.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export function toJSONSchema(
1414
const def = ctx.zodSchema._zod?.def as unknown as Record<string, unknown>
1515
if (def?.type === 'date') {
1616
ctx.jsonSchema.type = 'string'
17-
ctx.jsonSchema.format = 'date-time'
17+
ctx.jsonSchema.format = 'date'
1818
}
1919
if (def?.$content) {
2020
ctx.jsonSchema.$content = def.$content

0 commit comments

Comments
 (0)