Skip to content

Commit 8de50b9

Browse files
authored
remove useless header type in client headers (#315)
1 parent 2af225a commit 8de50b9

File tree

4 files changed

+110
-35
lines changed

4 files changed

+110
-35
lines changed

Diff for: __mocks__/api.yaml

+12
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,18 @@ paths:
283283
responses:
284284
"200":
285285
description: "Ok"
286+
/test-header-with-schema-ref:
287+
get:
288+
operationId: "testHeaderWithSchemaRef"
289+
parameters:
290+
- name: param
291+
in: header
292+
required: true
293+
schema:
294+
$ref: "#/definitions/CustomStringFormatTest"
295+
responses:
296+
"200":
297+
description: "Ok"
286298
definitions:
287299
Person:
288300
$ref: "definitions.yaml#/Person"

Diff for: __mocks__/openapi_v3/api.yaml

+12
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,18 @@ paths:
311311
responses:
312312
"200":
313313
description: "Ok"
314+
/test-header-with-schema-ref:
315+
get:
316+
operationId: "testHeaderWithSchemaRef"
317+
parameters:
318+
- name: param
319+
in: header
320+
required: true
321+
schema:
322+
$ref: "#/components/schemas/CustomStringFormatTest"
323+
responses:
324+
"200":
325+
description: "Ok"
314326

315327
# -------------
316328
# Components

Diff for: src/commands/gen-api-models/__tests__/__snapshots__/index.test.ts.snap

+85-33
Original file line numberDiff line numberDiff line change
@@ -934,7 +934,9 @@ import {
934934
TestWithEmptyResponseT,
935935
testWithEmptyResponseDefaultDecoder,
936936
TestParamWithSchemaRefT,
937-
testParamWithSchemaRefDefaultDecoder
937+
testParamWithSchemaRefDefaultDecoder,
938+
TestHeaderWithSchemaRefT,
939+
testHeaderWithSchemaRefDefaultDecoder
938940
} from \\"./requestTypes\\";
939941

940942
// This is a placeholder for undefined when dealing with object keys
@@ -960,7 +962,8 @@ export type ApiOperation = TypeofApiCall<TestAuthBearerT> &
960962
TypeofApiCall<TestSimplePatchT> &
961963
TypeofApiCall<TestCustomTokenHeaderT> &
962964
TypeofApiCall<TestWithEmptyResponseT> &
963-
TypeofApiCall<TestParamWithSchemaRefT>;
965+
TypeofApiCall<TestParamWithSchemaRefT> &
966+
TypeofApiCall<TestHeaderWithSchemaRefT>;
964967

965968
export type ParamKeys = keyof (TypeofApiParams<TestAuthBearerT> &
966969
TypeofApiParams<TestSimpleTokenT> &
@@ -979,7 +982,8 @@ export type ParamKeys = keyof (TypeofApiParams<TestAuthBearerT> &
979982
TypeofApiParams<TestSimplePatchT> &
980983
TypeofApiParams<TestCustomTokenHeaderT> &
981984
TypeofApiParams<TestWithEmptyResponseT> &
982-
TypeofApiParams<TestParamWithSchemaRefT>);
985+
TypeofApiParams<TestParamWithSchemaRefT> &
986+
TypeofApiParams<TestHeaderWithSchemaRefT>);
983987

984988
/**
985989
* Defines an adapter for TypeofApiCall which omit one or more parameters in the signature
@@ -1020,7 +1024,8 @@ export type WithDefaultsT<
10201024
| TestSimplePatchT
10211025
| TestCustomTokenHeaderT
10221026
| TestWithEmptyResponseT
1023-
| TestParamWithSchemaRefT,
1027+
| TestParamWithSchemaRefT
1028+
| TestHeaderWithSchemaRefT,
10241029
K
10251030
>;
10261031

@@ -1077,6 +1082,8 @@ export type Client<
10771082
readonly testWithEmptyResponse: TypeofApiCall<TestWithEmptyResponseT>;
10781083

10791084
readonly testParamWithSchemaRef: TypeofApiCall<TestParamWithSchemaRefT>;
1085+
1086+
readonly testHeaderWithSchemaRef: TypeofApiCall<TestHeaderWithSchemaRefT>;
10801087
}
10811088
: {
10821089
readonly testAuthBearer: TypeofApiCall<
@@ -1204,6 +1211,13 @@ export type Client<
12041211
Omit<RequestParams<TestParamWithSchemaRefT>, K>
12051212
>
12061213
>;
1214+
1215+
readonly testHeaderWithSchemaRef: TypeofApiCall<
1216+
ReplaceRequestParams<
1217+
TestHeaderWithSchemaRefT,
1218+
Omit<RequestParams<TestHeaderWithSchemaRefT>, K>
1219+
>
1220+
>;
12071221
};
12081222

12091223
/**
@@ -1253,7 +1267,7 @@ export function createClient<K extends ParamKeys>({
12531267
> = {
12541268
method: \\"get\\",
12551269

1256-
headers: ({ [\\"bearerToken\\"]: bearerToken }: { bearerToken: string }) => ({
1270+
headers: ({ [\\"bearerToken\\"]: bearerToken }) => ({
12571271
Authorization: \`Bearer \${bearerToken}\`
12581272
}),
12591273
response_decoder: testAuthBearerDefaultDecoder(),
@@ -1273,7 +1287,7 @@ export function createClient<K extends ParamKeys>({
12731287
> = {
12741288
method: \\"get\\",
12751289

1276-
headers: ({ [\\"simpleToken\\"]: simpleToken }: { simpleToken: string }) => ({
1290+
headers: ({ [\\"simpleToken\\"]: simpleToken }) => ({
12771291
\\"X-Functions-Key\\": simpleToken
12781292
}),
12791293
response_decoder: testSimpleTokenDefaultDecoder(),
@@ -1466,9 +1480,6 @@ export function createClient<K extends ParamKeys>({
14661480
headers: ({
14671481
[\\"headerInlineParam\\"]: headerInlineParam,
14681482
[\\"x-header-param\\"]: xHeaderParam
1469-
}: {
1470-
headerInlineParam: string;
1471-
\\"x-header-param\\": string;
14721483
}) => ({
14731484
headerInlineParam: headerInlineParam,
14741485

@@ -1495,9 +1506,6 @@ export function createClient<K extends ParamKeys>({
14951506
headers: ({
14961507
[\\"headerInlineParam\\"]: headerInlineParam,
14971508
[\\"x-header-param\\"]: xHeaderParam
1498-
}: {
1499-
headerInlineParam: string;
1500-
\\"x-header-param\\": string;
15011509
}) => ({
15021510
headerInlineParam: headerInlineParam,
15031511

@@ -1580,7 +1588,7 @@ export function createClient<K extends ParamKeys>({
15801588
> = {
15811589
method: \\"get\\",
15821590

1583-
headers: ({ [\\"customToken\\"]: customToken }: { customToken: string }) => ({
1591+
headers: ({ [\\"customToken\\"]: customToken }) => ({
15841592
\\"custom-token\\": customToken
15851593
}),
15861594
response_decoder: testCustomTokenHeaderDefaultDecoder(),
@@ -1630,6 +1638,25 @@ export function createClient<K extends ParamKeys>({
16301638
options
16311639
);
16321640

1641+
const testHeaderWithSchemaRefT: ReplaceRequestParams<
1642+
TestHeaderWithSchemaRefT,
1643+
RequestParams<TestHeaderWithSchemaRefT>
1644+
> = {
1645+
method: \\"get\\",
1646+
1647+
headers: ({ [\\"param\\"]: param }) => ({
1648+
param: param
1649+
}),
1650+
response_decoder: testHeaderWithSchemaRefDefaultDecoder(),
1651+
url: ({}) => \`\${basePath}/test-header-with-schema-ref\`,
1652+
1653+
query: () => withoutUndefinedValues({})
1654+
};
1655+
const testHeaderWithSchemaRef: TypeofApiCall<TestHeaderWithSchemaRefT> = createFetchRequestForApi(
1656+
testHeaderWithSchemaRefT,
1657+
options
1658+
);
1659+
16331660
return {
16341661
testAuthBearer: (withDefaults || identity)(testAuthBearer),
16351662
testSimpleToken: (withDefaults || identity)(testSimpleToken),
@@ -1658,7 +1685,8 @@ export function createClient<K extends ParamKeys>({
16581685
testSimplePatch: (withDefaults || identity)(testSimplePatch),
16591686
testCustomTokenHeader: (withDefaults || identity)(testCustomTokenHeader),
16601687
testWithEmptyResponse: (withDefaults || identity)(testWithEmptyResponse),
1661-
testParamWithSchemaRef: (withDefaults || identity)(testParamWithSchemaRef)
1688+
testParamWithSchemaRef: (withDefaults || identity)(testParamWithSchemaRef),
1689+
testHeaderWithSchemaRef: (withDefaults || identity)(testHeaderWithSchemaRef)
16621690
};
16631691
}
16641692
"
@@ -2732,7 +2760,9 @@ import {
27322760
TestWithEmptyResponseT,
27332761
testWithEmptyResponseDefaultDecoder,
27342762
TestParamWithSchemaRefT,
2735-
testParamWithSchemaRefDefaultDecoder
2763+
testParamWithSchemaRefDefaultDecoder,
2764+
TestHeaderWithSchemaRefT,
2765+
testHeaderWithSchemaRefDefaultDecoder
27362766
} from \\"./requestTypes\\";
27372767

27382768
// This is a placeholder for undefined when dealing with object keys
@@ -2759,7 +2789,8 @@ export type ApiOperation = TypeofApiCall<TestAuthBearerT> &
27592789
TypeofApiCall<TestSimplePatchT> &
27602790
TypeofApiCall<TestCustomTokenHeaderT> &
27612791
TypeofApiCall<TestWithEmptyResponseT> &
2762-
TypeofApiCall<TestParamWithSchemaRefT>;
2792+
TypeofApiCall<TestParamWithSchemaRefT> &
2793+
TypeofApiCall<TestHeaderWithSchemaRefT>;
27632794

27642795
export type ParamKeys = keyof (TypeofApiParams<TestAuthBearerT> &
27652796
TypeofApiParams<TestAuthBearerHttpT> &
@@ -2779,7 +2810,8 @@ export type ParamKeys = keyof (TypeofApiParams<TestAuthBearerT> &
27792810
TypeofApiParams<TestSimplePatchT> &
27802811
TypeofApiParams<TestCustomTokenHeaderT> &
27812812
TypeofApiParams<TestWithEmptyResponseT> &
2782-
TypeofApiParams<TestParamWithSchemaRefT>);
2813+
TypeofApiParams<TestParamWithSchemaRefT> &
2814+
TypeofApiParams<TestHeaderWithSchemaRefT>);
27832815

27842816
/**
27852817
* Defines an adapter for TypeofApiCall which omit one or more parameters in the signature
@@ -2821,7 +2853,8 @@ export type WithDefaultsT<
28212853
| TestSimplePatchT
28222854
| TestCustomTokenHeaderT
28232855
| TestWithEmptyResponseT
2824-
| TestParamWithSchemaRefT,
2856+
| TestParamWithSchemaRefT
2857+
| TestHeaderWithSchemaRefT,
28252858
K
28262859
>;
28272860

@@ -2880,6 +2913,8 @@ export type Client<
28802913
readonly testWithEmptyResponse: TypeofApiCall<TestWithEmptyResponseT>;
28812914

28822915
readonly testParamWithSchemaRef: TypeofApiCall<TestParamWithSchemaRefT>;
2916+
2917+
readonly testHeaderWithSchemaRef: TypeofApiCall<TestHeaderWithSchemaRefT>;
28832918
}
28842919
: {
28852920
readonly testAuthBearer: TypeofApiCall<
@@ -3014,6 +3049,13 @@ export type Client<
30143049
Omit<RequestParams<TestParamWithSchemaRefT>, K>
30153050
>
30163051
>;
3052+
3053+
readonly testHeaderWithSchemaRef: TypeofApiCall<
3054+
ReplaceRequestParams<
3055+
TestHeaderWithSchemaRefT,
3056+
Omit<RequestParams<TestHeaderWithSchemaRefT>, K>
3057+
>
3058+
>;
30173059
};
30183060

30193061
/**
@@ -3063,7 +3105,7 @@ export function createClient<K extends ParamKeys>({
30633105
> = {
30643106
method: \\"get\\",
30653107

3066-
headers: ({ [\\"bearerToken\\"]: bearerToken }: { bearerToken: string }) => ({
3108+
headers: ({ [\\"bearerToken\\"]: bearerToken }) => ({
30673109
Authorization: \`Bearer \${bearerToken}\`
30683110
}),
30693111
response_decoder: testAuthBearerDefaultDecoder(),
@@ -3083,11 +3125,7 @@ export function createClient<K extends ParamKeys>({
30833125
> = {
30843126
method: \\"get\\",
30853127

3086-
headers: ({
3087-
[\\"bearerTokenHttp\\"]: bearerTokenHttp
3088-
}: {
3089-
bearerTokenHttp: string;
3090-
}) => ({
3128+
headers: ({ [\\"bearerTokenHttp\\"]: bearerTokenHttp }) => ({
30913129
Authorization: \`Bearer \${bearerTokenHttp}\`
30923130
}),
30933131
response_decoder: testAuthBearerHttpDefaultDecoder(),
@@ -3107,7 +3145,7 @@ export function createClient<K extends ParamKeys>({
31073145
> = {
31083146
method: \\"get\\",
31093147

3110-
headers: ({ [\\"simpleToken\\"]: simpleToken }: { simpleToken: string }) => ({
3148+
headers: ({ [\\"simpleToken\\"]: simpleToken }) => ({
31113149
\\"X-Functions-Key\\": simpleToken
31123150
}),
31133151
response_decoder: testSimpleTokenDefaultDecoder(),
@@ -3310,9 +3348,6 @@ export function createClient<K extends ParamKeys>({
33103348
headers: ({
33113349
[\\"headerInlineParam\\"]: headerInlineParam,
33123350
[\\"x-header-param\\"]: xHeaderParam
3313-
}: {
3314-
headerInlineParam: string;
3315-
\\"x-header-param\\": string;
33163351
}) => ({
33173352
headerInlineParam: headerInlineParam,
33183353

@@ -3339,9 +3374,6 @@ export function createClient<K extends ParamKeys>({
33393374
headers: ({
33403375
[\\"headerInlineParam\\"]: headerInlineParam,
33413376
[\\"x-header-param\\"]: xHeaderParam
3342-
}: {
3343-
headerInlineParam: string;
3344-
\\"x-header-param\\": string;
33453377
}) => ({
33463378
headerInlineParam: headerInlineParam,
33473379

@@ -3424,7 +3456,7 @@ export function createClient<K extends ParamKeys>({
34243456
> = {
34253457
method: \\"get\\",
34263458

3427-
headers: ({ [\\"customToken\\"]: customToken }: { customToken: string }) => ({
3459+
headers: ({ [\\"customToken\\"]: customToken }) => ({
34283460
\\"custom-token\\": customToken
34293461
}),
34303462
response_decoder: testCustomTokenHeaderDefaultDecoder(),
@@ -3474,6 +3506,25 @@ export function createClient<K extends ParamKeys>({
34743506
options
34753507
);
34763508

3509+
const testHeaderWithSchemaRefT: ReplaceRequestParams<
3510+
TestHeaderWithSchemaRefT,
3511+
RequestParams<TestHeaderWithSchemaRefT>
3512+
> = {
3513+
method: \\"get\\",
3514+
3515+
headers: ({ [\\"param\\"]: param }) => ({
3516+
param: param
3517+
}),
3518+
response_decoder: testHeaderWithSchemaRefDefaultDecoder(),
3519+
url: ({}) => \`\${basePath}/test-header-with-schema-ref\`,
3520+
3521+
query: () => withoutUndefinedValues({})
3522+
};
3523+
const testHeaderWithSchemaRef: TypeofApiCall<TestHeaderWithSchemaRefT> = createFetchRequestForApi(
3524+
testHeaderWithSchemaRefT,
3525+
options
3526+
);
3527+
34773528
return {
34783529
testAuthBearer: (withDefaults || identity)(testAuthBearer),
34793530
testAuthBearerHttp: (withDefaults || identity)(testAuthBearerHttp),
@@ -3503,7 +3554,8 @@ export function createClient<K extends ParamKeys>({
35033554
testSimplePatch: (withDefaults || identity)(testSimplePatch),
35043555
testCustomTokenHeader: (withDefaults || identity)(testCustomTokenHeader),
35053556
testWithEmptyResponse: (withDefaults || identity)(testWithEmptyResponse),
3506-
testParamWithSchemaRef: (withDefaults || identity)(testParamWithSchemaRef)
3557+
testParamWithSchemaRef: (withDefaults || identity)(testParamWithSchemaRef),
3558+
testHeaderWithSchemaRef: (withDefaults || identity)(testHeaderWithSchemaRef)
35073559
};
35083560
}
35093561
"

Diff for: templates/macros.njk

+1-2
Original file line numberDiff line numberDiff line change
@@ -552,8 +552,7 @@
552552
{% macro composedHeaderProducers(headerParams, consumes) -%}
553553
(
554554
{% if headerParams.length %}
555-
{ {% for p in headerParams %}{{p.name | safeDestruct | safe }},{% endfor %} }:
556-
{ {% for p in headerParams %}"{{p.name | safe }}":{{p.type}};{% endfor %} }
555+
{ {% for p in headerParams %}{{p.name | safeDestruct | safe }},{% endfor %} }
557556
{% endif %}
558557
) => ({
559558
{% for p in headerParams %}"{{p.headerName}}": {{ tokenize(p) }},{% endfor %}

0 commit comments

Comments
 (0)