Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/runtime/internal/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const propertyTypes = {
number: 'INT',
boolean: 'BOOLEAN',
date: 'DATE',
datetime: 'DATETIME',
enum: 'VARCHAR',
object: 'TEXT',
}
Expand Down Expand Up @@ -33,10 +34,14 @@ function getPropertyType(property: Draft07DefinitionProperty | Draft07Definition
const propertyType = (property as Draft07DefinitionProperty).type
let type = propertyTypes[propertyType as keyof typeof propertyTypes] || 'TEXT'

if ((property as Draft07DefinitionProperty).format === 'date-time') {
if ((property as Draft07DefinitionProperty).format === 'date') {
type = 'DATE'
}

if ((property as Draft07DefinitionProperty).format === 'date-time') {
type = 'DATETIME'
}

if ((property as Draft07DefinitionPropertyAllOf).allOf) {
type = 'TEXT'
}
Expand Down
2 changes: 1 addition & 1 deletion src/utils/schema/valibot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export function toJSONSchema(schema: unknown, name: string): Draft07 {
const definitions = valibotToJsonSchema(schema as any, {
overrideSchema(context) {
if (context.valibotSchema.type === 'date') {
return { type: 'string', format: 'date-time' }
return { type: 'string', format: 'date' }
}
if ((context.valibotSchema as unknown as { $content: Record<string, unknown> }).$content) {
return {
Expand Down
3 changes: 2 additions & 1 deletion src/utils/schema/zod3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,13 @@ export const z = zod

export function toJSONSchema(_schema: unknown, name: string): Draft07 {
const schema = _schema as zod.ZodSchema
const jsonSchema = zodToJsonSchema(schema, { name, $refStrategy: 'none' }) as Draft07
const jsonSchema = zodToJsonSchema(schema, { name, $refStrategy: 'none', dateStrategy: 'format:date' }) as Draft07
const jsonSchemaWithEditorMeta = zodToJsonSchema(
schema,
{
name,
$refStrategy: 'none',
dateStrategy: 'format:date',
override: (_def) => {
const def = _def as unknown as Record<string, unknown>
if (def.editor) {
Expand Down
2 changes: 1 addition & 1 deletion src/utils/schema/zod4.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export function toJSONSchema(
const def = ctx.zodSchema._zod?.def as unknown as Record<string, unknown>
if (def?.type === 'date') {
ctx.jsonSchema.type = 'string'
ctx.jsonSchema.format = 'date-time'
ctx.jsonSchema.format = 'date'
}
if (def?.$content) {
ctx.jsonSchema.$content = def.$content
Expand Down
Loading