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 {
124124export function tsUnionOf ( types : string [ ] ) : string {
125125 return `(${ types . join ( ") | (" ) } )` ;
126126}
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 {
1818 tsPartial ,
1919 tsUnionOf ,
2020 tsTupleOf ,
21+ unrefComponent ,
2122} from "./utils" ;
2223
2324export const PRIMITIVES : { [ key : string ] : "boolean" | "string" | "number" } = {
@@ -193,7 +194,9 @@ export default function generateTypesV3(
193194 output += `"${ loc } ": {\n` ;
194195 Object . entries ( locParams ) . forEach ( ( [ paramName , paramProps ] ) => {
195196 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` ;
197200 return ;
198201 }
199202 if ( paramProps . description ) output += comment ( paramProps . description ) ;
You can’t perform that action at this time.
0 commit comments