Skip to content

Commit 43766c8

Browse files
committed
fix(hono): correctly check response validator application/json
1 parent 246cf4c commit 43766c8

16 files changed

+551
-468
lines changed

.prettierignore

+1
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ node_modules
99
.husky
1010
mockServiceWorker.js
1111
yarn.lock
12+
.svelte-kit

packages/hono/src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -864,7 +864,7 @@ export const zValidator =
864864
865865
if (
866866
c.res.status !== 200 ||
867-
c.res.headers.get('Content-Type') !== 'application/json'
867+
!c.res.headers.get('Content-Type')?.includes('application/json')
868868
) {
869869
return;
870870
}

samples/basic/api/endpoints/petstoreFromFileSpec.ts

+43-54
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,13 @@
44
* Swagger Petstore
55
* OpenAPI spec version: 1.0.0
66
*/
7-
import axios from 'axios'
8-
import type {
9-
AxiosRequestConfig,
10-
AxiosResponse
11-
} from 'axios'
7+
import axios from 'axios';
8+
import type { AxiosRequestConfig, AxiosResponse } from 'axios';
129
export type ListPetsNestedArrayParams = {
13-
/**
14-
* How many items to return at one time (max 100)
15-
*/
16-
limit?: string;
10+
/**
11+
* How many items to return at one time (max 100)
12+
*/
13+
limit?: string;
1714
};
1815

1916
export type CreatePetsBody = {
@@ -22,10 +19,10 @@ export type CreatePetsBody = {
2219
};
2320

2421
export type ListPetsParams = {
25-
/**
26-
* How many items to return at one time (max 100)
27-
*/
28-
limit?: string;
22+
/**
23+
* How many items to return at one time (max 100)
24+
*/
25+
limit?: string;
2926
};
3027

3128
export interface Error {
@@ -43,17 +40,16 @@ export interface PetsNestedArray {
4340
data?: Pet[];
4441
}
4542

46-
export type PetCountry = typeof PetCountry[keyof typeof PetCountry];
47-
43+
export type PetCountry = (typeof PetCountry)[keyof typeof PetCountry];
4844

4945
// eslint-disable-next-line @typescript-eslint/no-redeclare
5046
export const PetCountry = {
51-
'People\'s_Republic_of_China': 'People\'s Republic of China',
47+
"People's_Republic_of_China": "People's Republic of China",
5248
Uruguay: 'Uruguay',
5349
} as const;
5450

55-
export type PetCallingCode = typeof PetCallingCode[keyof typeof PetCallingCode];
56-
51+
export type PetCallingCode =
52+
(typeof PetCallingCode)[keyof typeof PetCallingCode];
5753

5854
// eslint-disable-next-line @typescript-eslint/no-redeclare
5955
export const PetCallingCode = {
@@ -86,60 +82,53 @@ export interface Pet {
8682
tag?: string | null;
8783
}
8884

89-
90-
91-
92-
93-
/**
85+
/**
9486
* @summary List all pets
9587
*/
9688
export const listPets = <TData = AxiosResponse<PetsArray>>(
97-
params?: ListPetsParams, options?: AxiosRequestConfig
98-
): Promise<TData> => {
99-
return axios.get(
100-
`/pets`,{
89+
params?: ListPetsParams,
90+
options?: AxiosRequestConfig,
91+
): Promise<TData> => {
92+
return axios.get(`/pets`, {
10193
...options,
102-
params: {...params, ...options?.params},}
103-
);
104-
}
94+
params: { ...params, ...options?.params },
95+
});
96+
};
10597

10698
/**
10799
* @summary Create a pet
108100
*/
109101
export const createPets = <TData = AxiosResponse<void>>(
110-
createPetsBody: CreatePetsBody, options?: AxiosRequestConfig
111-
): Promise<TData> => {
112-
return axios.post(
113-
`/pets`,
114-
createPetsBody,options
115-
);
116-
}
102+
createPetsBody: CreatePetsBody,
103+
options?: AxiosRequestConfig,
104+
): Promise<TData> => {
105+
return axios.post(`/pets`, createPetsBody, options);
106+
};
117107

118108
/**
119109
* @summary List all pets as nested array
120110
*/
121111
export const listPetsNestedArray = <TData = AxiosResponse<PetsNestedArray>>(
122-
params?: ListPetsNestedArrayParams, options?: AxiosRequestConfig
123-
): Promise<TData> => {
124-
return axios.get(
125-
`/pets-nested-array`,{
112+
params?: ListPetsNestedArrayParams,
113+
options?: AxiosRequestConfig,
114+
): Promise<TData> => {
115+
return axios.get(`/pets-nested-array`, {
126116
...options,
127-
params: {...params, ...options?.params},}
128-
);
129-
}
117+
params: { ...params, ...options?.params },
118+
});
119+
};
130120

131121
/**
132122
* @summary Info for a specific pet
133123
*/
134124
export const showPetById = <TData = AxiosResponse<Pet>>(
135-
petId: string, options?: AxiosRequestConfig
136-
): Promise<TData> => {
137-
return axios.get(
138-
`/pets/${petId}`,options
139-
);
140-
}
125+
petId: string,
126+
options?: AxiosRequestConfig,
127+
): Promise<TData> => {
128+
return axios.get(`/pets/${petId}`, options);
129+
};
141130

142-
export type ListPetsResult = AxiosResponse<PetsArray>
143-
export type CreatePetsResult = AxiosResponse<void>
144-
export type ListPetsNestedArrayResult = AxiosResponse<PetsNestedArray>
145-
export type ShowPetByIdResult = AxiosResponse<Pet>
131+
export type ListPetsResult = AxiosResponse<PetsArray>;
132+
export type CreatePetsResult = AxiosResponse<void>;
133+
export type ListPetsNestedArrayResult = AxiosResponse<PetsNestedArray>;
134+
export type ShowPetByIdResult = AxiosResponse<Pet>;

samples/basic/api/endpoints/petstoreFromFileSpecWithConfig.ts

+43-54
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,13 @@
44
* Swagger Petstore
55
* OpenAPI spec version: 1.0.0
66
*/
7-
import axios from 'axios'
8-
import type {
9-
AxiosRequestConfig,
10-
AxiosResponse
11-
} from 'axios'
7+
import axios from 'axios';
8+
import type { AxiosRequestConfig, AxiosResponse } from 'axios';
129
export type ListPetsNestedArrayParams = {
13-
/**
14-
* How many items to return at one time (max 100)
15-
*/
16-
limit?: string;
10+
/**
11+
* How many items to return at one time (max 100)
12+
*/
13+
limit?: string;
1714
};
1815

1916
export type CreatePetsBody = {
@@ -22,10 +19,10 @@ export type CreatePetsBody = {
2219
};
2320

2421
export type ListPetsParams = {
25-
/**
26-
* How many items to return at one time (max 100)
27-
*/
28-
limit?: string;
22+
/**
23+
* How many items to return at one time (max 100)
24+
*/
25+
limit?: string;
2926
};
3027

3128
export interface Error {
@@ -43,17 +40,16 @@ export interface PetsNestedArray {
4340
data?: Pet[];
4441
}
4542

46-
export type PetCountry = typeof PetCountry[keyof typeof PetCountry];
47-
43+
export type PetCountry = (typeof PetCountry)[keyof typeof PetCountry];
4844

4945
// eslint-disable-next-line @typescript-eslint/no-redeclare
5046
export const PetCountry = {
51-
'People\'s_Republic_of_China': 'People\'s Republic of China',
47+
"People's_Republic_of_China": "People's Republic of China",
5248
Uruguay: 'Uruguay',
5349
} as const;
5450

55-
export type PetCallingCode = typeof PetCallingCode[keyof typeof PetCallingCode];
56-
51+
export type PetCallingCode =
52+
(typeof PetCallingCode)[keyof typeof PetCallingCode];
5753

5854
// eslint-disable-next-line @typescript-eslint/no-redeclare
5955
export const PetCallingCode = {
@@ -86,60 +82,53 @@ export interface Pet {
8682
tag?: string | null;
8783
}
8884

89-
90-
91-
92-
93-
/**
85+
/**
9486
* @summary List all pets
9587
*/
9688
export const listPets = <TData = AxiosResponse<PetsArray>>(
97-
params?: ListPetsParams, options?: AxiosRequestConfig
98-
): Promise<TData> => {
99-
return axios.get(
100-
`/pets`,{
89+
params?: ListPetsParams,
90+
options?: AxiosRequestConfig,
91+
): Promise<TData> => {
92+
return axios.get(`/pets`, {
10193
...options,
102-
params: {...params, ...options?.params},}
103-
);
104-
}
94+
params: { ...params, ...options?.params },
95+
});
96+
};
10597

10698
/**
10799
* @summary Create a pet
108100
*/
109101
export const createPets = <TData = AxiosResponse<void>>(
110-
createPetsBody: CreatePetsBody, options?: AxiosRequestConfig
111-
): Promise<TData> => {
112-
return axios.post(
113-
`/pets`,
114-
createPetsBody,options
115-
);
116-
}
102+
createPetsBody: CreatePetsBody,
103+
options?: AxiosRequestConfig,
104+
): Promise<TData> => {
105+
return axios.post(`/pets`, createPetsBody, options);
106+
};
117107

118108
/**
119109
* @summary List all pets as nested array
120110
*/
121111
export const listPetsNestedArray = <TData = AxiosResponse<PetsNestedArray>>(
122-
params?: ListPetsNestedArrayParams, options?: AxiosRequestConfig
123-
): Promise<TData> => {
124-
return axios.get(
125-
`/pets-nested-array`,{
112+
params?: ListPetsNestedArrayParams,
113+
options?: AxiosRequestConfig,
114+
): Promise<TData> => {
115+
return axios.get(`/pets-nested-array`, {
126116
...options,
127-
params: {...params, ...options?.params},}
128-
);
129-
}
117+
params: { ...params, ...options?.params },
118+
});
119+
};
130120

131121
/**
132122
* @summary Info for a specific pet
133123
*/
134124
export const showPetById = <TData = AxiosResponse<Pet>>(
135-
petId: string, options?: AxiosRequestConfig
136-
): Promise<TData> => {
137-
return axios.get(
138-
`/pets/${petId}`,options
139-
);
140-
}
125+
petId: string,
126+
options?: AxiosRequestConfig,
127+
): Promise<TData> => {
128+
return axios.get(`/pets/${petId}`, options);
129+
};
141130

142-
export type ListPetsResult = AxiosResponse<PetsArray>
143-
export type CreatePetsResult = AxiosResponse<void>
144-
export type ListPetsNestedArrayResult = AxiosResponse<PetsNestedArray>
145-
export type ShowPetByIdResult = AxiosResponse<Pet>
131+
export type ListPetsResult = AxiosResponse<PetsArray>;
132+
export type CreatePetsResult = AxiosResponse<void>;
133+
export type ListPetsNestedArrayResult = AxiosResponse<PetsNestedArray>;
134+
export type ShowPetByIdResult = AxiosResponse<Pet>;

0 commit comments

Comments
 (0)