File tree Expand file tree Collapse file tree 2 files changed +21
-7
lines changed Expand file tree Collapse file tree 2 files changed +21
-7
lines changed Original file line number Diff line number Diff line change @@ -18,6 +18,9 @@ import {
18
18
NormalizedOutputOptions ,
19
19
pascal ,
20
20
upath ,
21
+ getParamsInPath ,
22
+ sanitize ,
23
+ camel ,
21
24
} from '@orval/core' ;
22
25
import { generateZod } from '@orval/zod' ;
23
26
import fs from 'fs-extra' ;
@@ -542,11 +545,22 @@ const factory = createFactory();`;
542
545
} ;
543
546
544
547
const getContext = ( verbOption : GeneratorVerbOptions ) => {
545
- const paramType = verbOption . params . length
546
- ? `param: {\n ${ verbOption . params
547
- . map ( ( property ) => property . definition )
548
- . join ( ',\n ' ) } ,\n },`
549
- : '' ;
548
+ let paramType = '' ;
549
+ if ( verbOption . params . length ) {
550
+ const params = getParamsInPath ( verbOption . pathRoute ) . map ( ( name ) => {
551
+ const param = verbOption . params . find (
552
+ ( p ) => p . name === sanitize ( camel ( name ) , { es5keyword : true } ) ,
553
+ ) ;
554
+ const definition = param ?. definition . split ( ':' ) [ 1 ] ;
555
+ const required = param ?. required ?? false ;
556
+ return {
557
+ definition : `${ name } ${ ! required ? '?' : '' } :${ definition } ` ,
558
+ } ;
559
+ } ) ;
560
+ paramType = `param: {\n ${ params
561
+ . map ( ( property ) => property . definition )
562
+ . join ( ',\n ' ) } ,\n },`;
563
+ }
550
564
551
565
const queryType = verbOption . queryParams
552
566
? `query: ${ verbOption . queryParams ?. schema . name } ,`
Original file line number Diff line number Diff line change 1
- import { camel , sanitize } from '@orval/core' ;
1
+ import { sanitize } from '@orval/core' ;
2
2
3
3
const hasParam = ( path : string ) : boolean => / [ ^ { ] * { [ \w * _ - ] * } .* / . test ( path ) ;
4
4
@@ -7,7 +7,7 @@ const getRoutePath = (path: string): string => {
7
7
if ( ! matches ?. length ) return path ; // impossible due to regexp grouping here, but for TS
8
8
9
9
const prev = matches [ 1 ] ;
10
- const param = sanitize ( camel ( matches [ 2 ] ) , {
10
+ const param = sanitize ( matches [ 2 ] , {
11
11
es5keyword : true ,
12
12
underscore : true ,
13
13
dash : true ,
You can’t perform that action at this time.
0 commit comments