@@ -394,6 +394,24 @@ export function createValidatorForOperationInput(
394394 } ) ;
395395 }
396396
397+ // HTTP params (query, header) arrive as strings. When the schema
398+ // declares type: "integer" or "number", rewrite it to type: "string"
399+ // with an int format so the existing string→number coercion pipeline
400+ // handles parsing and validation.
401+ const asHttpParamSchema = (
402+ schema : oas30 . SchemaObject | oas31 . SchemaObject | oas31 . ReferenceObject ,
403+ ) : oas30 . SchemaObject | oas31 . SchemaObject | oas31 . ReferenceObject => {
404+ if ( "$ref" in schema ) return schema ;
405+ if ( schema . type === "integer" || schema . type === "number" ) {
406+ return {
407+ ...schema ,
408+ type : "string" ,
409+ format : schema . type === "integer" ? "int64" : "int64" ,
410+ } ;
411+ }
412+ return schema ;
413+ } ;
414+
397415 // 2. Helper for Params/Query (Strict Objects)
398416 const addParams = (
399417 type : "params" | "query" ,
@@ -403,19 +421,23 @@ export function createValidatorForOperationInput(
403421 const name = camelcase ( [ commandName , type , "schema" ] ) ;
404422 schemas [ type === "params" ? "param" : "query" ] = name ;
405423
424+ const coerce = type === "query" ;
425+
406426 const propertyMap = Object . fromEntries (
407- list . map ( ( p ) => [
408- JSON . stringify ( p . name ) ,
409- p . required
410- ? schemaToValidator ( validatorSchemas , p . schema ?? { type : "string" } )
411- : vcall (
412- "exactOptional" ,
413- schemaToValidator (
414- validatorSchemas ,
415- p . schema ?? { type : "string" } ,
427+ list . map ( ( p ) => {
428+ const paramSchema = coerce
429+ ? asHttpParamSchema ( p . schema ?? { type : "string" } )
430+ : ( p . schema ?? { type : "string" } ) ;
431+ return [
432+ JSON . stringify ( p . name ) ,
433+ p . required
434+ ? schemaToValidator ( validatorSchemas , paramSchema )
435+ : vcall (
436+ "exactOptional" ,
437+ schemaToValidator ( validatorSchemas , paramSchema ) ,
416438 ) ,
417- ) ,
418- ] ) ,
439+ ] ;
440+ } ) ,
419441 ) ;
420442
421443 valibotFile . addVariableStatement ( {
@@ -439,18 +461,20 @@ export function createValidatorForOperationInput(
439461 schemas . header = name ;
440462
441463 const propertyMap = Object . fromEntries (
442- input . header . map ( ( p ) => [
443- JSON . stringify ( p . name . toLowerCase ( ) ) ,
444- p . required
445- ? schemaToValidator ( validatorSchemas , p . schema ?? { type : "string" } )
446- : vcall (
447- "exactOptional" ,
448- schemaToValidator (
449- validatorSchemas ,
450- p . schema ?? { type : "string" } ,
464+ input . header . map ( ( p ) => {
465+ const paramSchema = asHttpParamSchema (
466+ p . schema ?? { type : "string" } ,
467+ ) ;
468+ return [
469+ JSON . stringify ( p . name . toLowerCase ( ) ) ,
470+ p . required
471+ ? schemaToValidator ( validatorSchemas , paramSchema )
472+ : vcall (
473+ "exactOptional" ,
474+ schemaToValidator ( validatorSchemas , paramSchema ) ,
451475 ) ,
452- ) ,
453- ] ) ,
476+ ] ;
477+ } ) ,
454478 ) ;
455479
456480 valibotFile . addVariableStatement ( {
0 commit comments