File tree Expand file tree Collapse file tree 4 files changed +434
-411
lines changed Expand file tree Collapse file tree 4 files changed +434
-411
lines changed Original file line number Diff line number Diff line change @@ -124,3 +124,9 @@ export function tsPartial(type: string): string {
124
124
export function tsUnionOf ( types : string [ ] ) : string {
125
125
return `(${ types . join ( ") | (" ) } )` ;
126
126
}
127
+
128
+ /** Convert the components object and a 'components["parameters"]["param"]' string into the `param` object **/
129
+ export function unrefComponent ( components : any , ref : string ) {
130
+ const [ type , object ] = ref . match ( / (?< = \[ " ) ( [ ^ " ] + ) / g) as string [ ] ;
131
+ return components [ type ] [ object ] ;
132
+ }
Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ import {
18
18
tsPartial ,
19
19
tsUnionOf ,
20
20
tsTupleOf ,
21
+ unrefComponent ,
21
22
} from "./utils" ;
22
23
23
24
export const PRIMITIVES : { [ key : string ] : "boolean" | "string" | "number" } = {
@@ -193,7 +194,9 @@ export default function generateTypesV3(
193
194
output += `"${ loc } ": {\n` ;
194
195
Object . entries ( locParams ) . forEach ( ( [ paramName , paramProps ] ) => {
195
196
if ( typeof paramProps === "string" ) {
196
- output += `"${ paramName } ": ${ paramProps } \n` ;
197
+ const { required } = unrefComponent ( components , paramProps ) ;
198
+ const key = required ? `"${ paramName } "` : `"${ paramName } "?` ;
199
+ output += `${ key } : ${ paramProps } \n` ;
197
200
return ;
198
201
}
199
202
if ( paramProps . description ) output += comment ( paramProps . description ) ;
You can’t perform that action at this time.
0 commit comments