@@ -948,6 +948,19 @@ export async function processOpenApiDocument(
948948 ?. addTypeArgument ( queryType . getName ( ) ) ;
949949 }
950950
951+ // headers type argument (4th generic on Command)
952+ if ( headerType ) {
953+ // fill in query slot if missing
954+ if ( ! queryType ) {
955+ commandClassDeclaration
956+ . getExtends ( )
957+ ?. addTypeArgument ( neverKeyword ) ;
958+ }
959+ commandClassDeclaration
960+ . getExtends ( )
961+ ?. addTypeArgument ( headerType . getName ( ) ) ;
962+ }
963+
951964 const hasPathParams = path . includes ( "{" ) ;
952965 const pathname = hasPathParams
953966 ? `encodePath\`${ path . replaceAll ( / { / g, "${" ) } \``
@@ -967,7 +980,9 @@ export async function processOpenApiDocument(
967980 ! isUnspecifiedKeyword ( paramsType ) &&
968981 pathParameters . length > 0 ;
969982
970- if ( hasNonJsonBody || hasJsonBody || hasQuery || hasParams ) {
983+ const hasHeaders = ! ! headerType && headerParameters . length > 0 ;
984+
985+ if ( hasNonJsonBody || hasJsonBody || hasQuery || hasParams || hasHeaders ) {
971986 const ctor = commandClassDeclaration . addConstructor ( ) ;
972987
973988 const queryParameterNames = queryParameters
@@ -989,6 +1004,13 @@ export async function processOpenApiDocument(
9891004 type : inputType . getName ( ) ,
9901005 } ) ;
9911006
1007+ if ( hasHeaders ) {
1008+ ctor . addParameter ( {
1009+ name : "headers" ,
1010+ type : headerType . getName ( ) ,
1011+ } ) ;
1012+ }
1013+
9921014 ctor . addStatements ( [
9931015 {
9941016 kind : StructureKind . VariableStatement ,
@@ -1034,6 +1056,8 @@ export async function processOpenApiDocument(
10341056 SyntaxKind . CallExpression ,
10351057 ) ;
10361058
1059+ const headersArg = hasHeaders ? "headers" : undefined ;
1060+
10371061 // type narrowing
10381062 if ( Node . isCallExpression ( callExpr ) ) {
10391063 if ( hasJsonBody ) {
@@ -1042,23 +1066,35 @@ export async function processOpenApiDocument(
10421066 `jsonStringify(${ inputBodyName } )` ,
10431067 ...( hasQuery
10441068 ? [ `stripUndefined({${ queryParameterNames . join ( ", " ) } })` ]
1045- : [ ] ) ,
1069+ : hasHeaders
1070+ ? [ emptyKeyword ]
1071+ : [ ] ) ,
1072+ ...( headersArg ? [ headersArg ] : [ ] ) ,
10461073 ] ) ;
10471074 } else if ( hasNonJsonBody ) {
10481075 callExpr . addArguments ( [
10491076 pathname ,
10501077 nonJsonBodyPropName ,
10511078 ...( hasQuery
10521079 ? [ `stripUndefined({${ queryParameterNames . join ( ", " ) } })` ]
1053- : [ ] ) ,
1080+ : hasHeaders
1081+ ? [ emptyKeyword ]
1082+ : [ ] ) ,
1083+ ...( headersArg ? [ headersArg ] : [ ] ) ,
10541084 ] ) ;
10551085 } else if ( hasQuery ) {
10561086 callExpr . addArguments ( [
10571087 pathname ,
10581088 emptyKeyword ,
1059- ...( hasQuery
1060- ? [ `stripUndefined({${ queryParameterNames . join ( ", " ) } })` ]
1061- : [ ] ) ,
1089+ `stripUndefined({${ queryParameterNames . join ( ", " ) } })` ,
1090+ ...( headersArg ? [ headersArg ] : [ ] ) ,
1091+ ] ) ;
1092+ } else if ( hasHeaders && headersArg ) {
1093+ callExpr . addArguments ( [
1094+ pathname ,
1095+ emptyKeyword ,
1096+ emptyKeyword ,
1097+ headersArg ,
10621098 ] ) ;
10631099 } else {
10641100 callExpr . addArguments ( [ pathname ] ) ;
0 commit comments