这是indexloc提供的服务,不要输入任何密码
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
5 changes: 5 additions & 0 deletions .changeset/brown-bags-matter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@hey-api/openapi-ts": patch
---

fix(valibot): handle `time` string format
8 changes: 8 additions & 0 deletions packages/openapi-ts-tests/main/test/3.1.x.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -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.isoTimeSecond())),
end_time: v.pipe(v.string(), v.isoTimeSecond())
})
});

/**
* Success
*/
export const vGetSearchResponse = v.object({
result: v.optional(v.string()),
scheduled_time: v.optional(v.pipe(v.string(), v.isoTimeSecond()))
});
11 changes: 10 additions & 1 deletion packages/openapi-ts/src/plugins/valibot/v1/toAst/string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,16 @@ export const stringToAst = ({
}),
);
break;
case 'time':
pipes.push(
tsc.callExpression({
functionName: tsc.propertyAccessExpression({
expression: v.placeholder,
name: identifiers.actions.isoTimeSecond,
}),
}),
);
break;
case 'uri':
pipes.push(
tsc.callExpression({
Expand All @@ -83,7 +93,6 @@ export const stringToAst = ({
);
break;
case 'email':
case 'time':
case 'uuid':
pipes.push(
tsc.callExpression({
Expand Down
35 changes: 35 additions & 0 deletions specs/3.1.x/time-format.yaml
Original file line number Diff line number Diff line change
@@ -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
Loading