From c1011daa1acfa42b6949825dd6361520c2cf8d23 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 30 Oct 2025 14:58:37 +0000 Subject: [PATCH 1/5] Initial plan From 36155c36b412fa8afce39180a99f99bcf4a824fc Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 30 Oct 2025 15:10:37 +0000 Subject: [PATCH 2/5] Fix valibot time format to use v.isoTime() instead of v.time() Co-authored-by: mrlubos <12529395+mrlubos@users.noreply.github.com> --- .../openapi-ts-tests/main/test/3.1.x.test.ts | 8 +++++ .../src/plugins/valibot/v1/toAst/string.ts | 11 +++++- specs/3.1.x/time-format.yaml | 35 +++++++++++++++++++ 3 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 specs/3.1.x/time-format.yaml diff --git a/packages/openapi-ts-tests/main/test/3.1.x.test.ts b/packages/openapi-ts-tests/main/test/3.1.x.test.ts index 7b7d94765..84e20de05 100644 --- a/packages/openapi-ts-tests/main/test/3.1.x.test.ts +++ b/packages/openapi-ts-tests/main/test/3.1.x.test.ts @@ -994,6 +994,14 @@ describe(`OpenAPI ${version}`, () => { }), description: 'anyOf string and binary string', }, + { + config: createConfig({ + input: 'time-format.yaml', + output: 'time-format', + plugins: ['valibot'], + }), + description: 'generates correct valibot schema for time format', + }, ]; it.each(scenarios)('$description', async ({ config }) => { diff --git a/packages/openapi-ts/src/plugins/valibot/v1/toAst/string.ts b/packages/openapi-ts/src/plugins/valibot/v1/toAst/string.ts index cc7e46edb..4222aa2bb 100644 --- a/packages/openapi-ts/src/plugins/valibot/v1/toAst/string.ts +++ b/packages/openapi-ts/src/plugins/valibot/v1/toAst/string.ts @@ -72,6 +72,16 @@ export const stringToAst = ({ }), ); break; + case 'time': + pipes.push( + tsc.callExpression({ + functionName: tsc.propertyAccessExpression({ + expression: v.placeholder, + name: identifiers.actions.isoTime, + }), + }), + ); + break; case 'uri': pipes.push( tsc.callExpression({ @@ -83,7 +93,6 @@ export const stringToAst = ({ ); break; case 'email': - case 'time': case 'uuid': pipes.push( tsc.callExpression({ diff --git a/specs/3.1.x/time-format.yaml b/specs/3.1.x/time-format.yaml new file mode 100644 index 000000000..17ad9307b --- /dev/null +++ b/specs/3.1.x/time-format.yaml @@ -0,0 +1,35 @@ +openapi: 3.1.0 +info: + title: OpenAPI 3.1.0 time format example + version: '1' +paths: + /search: + get: + summary: Search with time parameter + parameters: + - name: start_time + in: query + description: Start time in HH:MM:SS format + schema: + type: string + format: time + - name: end_time + in: query + description: End time in HH:MM:SS format + required: true + schema: + type: string + format: time + responses: + '200': + description: Success + content: + application/json: + schema: + type: object + properties: + result: + type: string + scheduled_time: + type: string + format: time From 92ebb6bf1c63d438854a2e7eb8ffc9a89d4fdfcc Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 30 Oct 2025 15:16:52 +0000 Subject: [PATCH 3/5] Add test snapshot for time format fix Co-authored-by: mrlubos <12529395+mrlubos@users.noreply.github.com> --- .../3.1.x/time-format/valibot.gen.ts | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/time-format/valibot.gen.ts diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/time-format/valibot.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/time-format/valibot.gen.ts new file mode 100644 index 000000000..306ca6494 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/time-format/valibot.gen.ts @@ -0,0 +1,20 @@ +// This file is auto-generated by @hey-api/openapi-ts + +import * as v from 'valibot'; + +export const vGetSearchData = v.object({ + body: v.optional(v.never()), + path: v.optional(v.never()), + query: v.object({ + start_time: v.optional(v.pipe(v.string(), v.isoTime())), + end_time: v.pipe(v.string(), v.isoTime()) + }) +}); + +/** + * Success + */ +export const vGetSearchResponse = v.object({ + result: v.optional(v.string()), + scheduled_time: v.optional(v.pipe(v.string(), v.isoTime())) +}); From 2a0a2fda329e1af35aab6472505511e638978913 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 30 Oct 2025 15:42:55 +0000 Subject: [PATCH 4/5] Use v.isoTimeSecond() instead of v.isoTime() for time format Per feedback from @mrlubos, format: 'time' represents values like 20:20:39+00:00, and Valibot's isoTimeSecond() is a better fit than isoTime(). Co-authored-by: mrlubos <12529395+mrlubos@users.noreply.github.com> --- .../test/__snapshots__/3.1.x/time-format/valibot.gen.ts | 6 +++--- packages/openapi-ts/src/plugins/valibot/v1/toAst/string.ts | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/time-format/valibot.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/time-format/valibot.gen.ts index 306ca6494..06301e735 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/time-format/valibot.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/time-format/valibot.gen.ts @@ -6,8 +6,8 @@ export const vGetSearchData = v.object({ body: v.optional(v.never()), path: v.optional(v.never()), query: v.object({ - start_time: v.optional(v.pipe(v.string(), v.isoTime())), - end_time: v.pipe(v.string(), v.isoTime()) + start_time: v.optional(v.pipe(v.string(), v.isoTimeSecond())), + end_time: v.pipe(v.string(), v.isoTimeSecond()) }) }); @@ -16,5 +16,5 @@ export const vGetSearchData = v.object({ */ export const vGetSearchResponse = v.object({ result: v.optional(v.string()), - scheduled_time: v.optional(v.pipe(v.string(), v.isoTime())) + scheduled_time: v.optional(v.pipe(v.string(), v.isoTimeSecond())) }); diff --git a/packages/openapi-ts/src/plugins/valibot/v1/toAst/string.ts b/packages/openapi-ts/src/plugins/valibot/v1/toAst/string.ts index 4222aa2bb..bdd4493de 100644 --- a/packages/openapi-ts/src/plugins/valibot/v1/toAst/string.ts +++ b/packages/openapi-ts/src/plugins/valibot/v1/toAst/string.ts @@ -77,7 +77,7 @@ export const stringToAst = ({ tsc.callExpression({ functionName: tsc.propertyAccessExpression({ expression: v.placeholder, - name: identifiers.actions.isoTime, + name: identifiers.actions.isoTimeSecond, }), }), ); From 0db5a43b868511784cdffabbec8ea234c7841d19 Mon Sep 17 00:00:00 2001 From: Lubos Date: Thu, 30 Oct 2025 23:56:43 +0800 Subject: [PATCH 5/5] Fix Valibot time format handling --- .changeset/brown-bags-matter.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/brown-bags-matter.md diff --git a/.changeset/brown-bags-matter.md b/.changeset/brown-bags-matter.md new file mode 100644 index 000000000..e4d8cd3fd --- /dev/null +++ b/.changeset/brown-bags-matter.md @@ -0,0 +1,5 @@ +--- +"@hey-api/openapi-ts": patch +--- + +fix(valibot): handle `time` string format