valibot icon indicating copy to clipboard operation
valibot copied to clipboard

Support for openapi formats (int64, int32, date, date-time)

Open belgattitude opened this issue 5 months ago • 1 comments

I'm currently evaluating valibot/tojsonschema to generate openapi specs.

Currently stuck on v.bigint() and trying to generate a format spec like

const schema = v.bigint()
///
type: string
format: int64
description: Big integer as a string (int64), since JSON does not support true 64-bit integers.

https://spec.openapis.org/oas/v3.1.0#data-types

Is it something that is planned ?

I saw

More conversion options Convert schemas into JSON schema definitions Convert non JSON types to similar, yet different types (for example: Date into format: 'date-time' or format: 'unix-> time', BigInt into format: 'int64' or string, explicit undefined into null, etc.)

In the initial support PR: https://github.com/fabian-hiller/valibot/pull/802 by @gcornut

belgattitude avatar Jul 01 '25 09:07 belgattitude

Hi @belgattitude! I'm Dosu and I’m helping the valibot team.

Currently, valibot/tojsonschema does not natively generate OpenAPI-specific format fields like int64, int32, date, or date-time for types such as v.bigint() or Date. The conversion maps v.bigint() to JSON Schema type: integer and Date to type: string with format: date-time, but without explicit OpenAPI-focused adaptation or the ability to output type: string, format: int64 for bigints as you described. There is ongoing work to support OpenAPI formats for other types (like v.file() to type: string, format: binary), but nothing directly covering bigint or date types yet see PR #1119.

There are no open issues or roadmap items explicitly tracking this feature, and the documentation does not mention extension points or custom converters for OpenAPI formats see README. For now, you would need to post-process the generated schema to add the desired format fields for OpenAPI compliance.

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other  Join Discord Share on X

dosubot[bot] avatar Jul 01 '25 09:07 dosubot[bot]

Sorry for my late reply! What schemas and actions should result in these OpenAPI formats? Until this is supported you can use our overrideSchema and overrideAction config to support it.

fabian-hiller avatar Dec 03 '25 02:12 fabian-hiller