Skip to content

Commit

Permalink
fix(hono): correctly check response validator application/json
Browse files Browse the repository at this point in the history
  • Loading branch information
anymaniax committed May 17, 2024
1 parent 246cf4c commit 43766c8
Show file tree
Hide file tree
Showing 16 changed files with 551 additions and 468 deletions.
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ node_modules
.husky
mockServiceWorker.js
yarn.lock
.svelte-kit
2 changes: 1 addition & 1 deletion packages/hono/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -864,7 +864,7 @@ export const zValidator =
if (
c.res.status !== 200 ||
c.res.headers.get('Content-Type') !== 'application/json'
!c.res.headers.get('Content-Type')?.includes('application/json')
) {
return;
}
Expand Down
97 changes: 43 additions & 54 deletions samples/basic/api/endpoints/petstoreFromFileSpec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,13 @@
* Swagger Petstore
* OpenAPI spec version: 1.0.0
*/
import axios from 'axios'
import type {
AxiosRequestConfig,
AxiosResponse
} from 'axios'
import axios from 'axios';
import type { AxiosRequestConfig, AxiosResponse } from 'axios';
export type ListPetsNestedArrayParams = {
/**
* How many items to return at one time (max 100)
*/
limit?: string;
/**
* How many items to return at one time (max 100)
*/
limit?: string;
};

export type CreatePetsBody = {
Expand All @@ -22,10 +19,10 @@ export type CreatePetsBody = {
};

export type ListPetsParams = {
/**
* How many items to return at one time (max 100)
*/
limit?: string;
/**
* How many items to return at one time (max 100)
*/
limit?: string;
};

export interface Error {
Expand All @@ -43,17 +40,16 @@ export interface PetsNestedArray {
data?: Pet[];
}

export type PetCountry = typeof PetCountry[keyof typeof PetCountry];

export type PetCountry = (typeof PetCountry)[keyof typeof PetCountry];

// eslint-disable-next-line @typescript-eslint/no-redeclare
export const PetCountry = {
'People\'s_Republic_of_China': 'People\'s Republic of China',
"People's_Republic_of_China": "People's Republic of China",
Uruguay: 'Uruguay',
} as const;

export type PetCallingCode = typeof PetCallingCode[keyof typeof PetCallingCode];

export type PetCallingCode =
(typeof PetCallingCode)[keyof typeof PetCallingCode];

// eslint-disable-next-line @typescript-eslint/no-redeclare
export const PetCallingCode = {
Expand Down Expand Up @@ -86,60 +82,53 @@ export interface Pet {
tag?: string | null;
}





/**
/**
* @summary List all pets
*/
export const listPets = <TData = AxiosResponse<PetsArray>>(
params?: ListPetsParams, options?: AxiosRequestConfig
): Promise<TData> => {
return axios.get(
`/pets`,{
params?: ListPetsParams,
options?: AxiosRequestConfig,
): Promise<TData> => {
return axios.get(`/pets`, {
...options,
params: {...params, ...options?.params},}
);
}
params: { ...params, ...options?.params },
});
};

/**
* @summary Create a pet
*/
export const createPets = <TData = AxiosResponse<void>>(
createPetsBody: CreatePetsBody, options?: AxiosRequestConfig
): Promise<TData> => {
return axios.post(
`/pets`,
createPetsBody,options
);
}
createPetsBody: CreatePetsBody,
options?: AxiosRequestConfig,
): Promise<TData> => {
return axios.post(`/pets`, createPetsBody, options);
};

/**
* @summary List all pets as nested array
*/
export const listPetsNestedArray = <TData = AxiosResponse<PetsNestedArray>>(
params?: ListPetsNestedArrayParams, options?: AxiosRequestConfig
): Promise<TData> => {
return axios.get(
`/pets-nested-array`,{
params?: ListPetsNestedArrayParams,
options?: AxiosRequestConfig,
): Promise<TData> => {
return axios.get(`/pets-nested-array`, {
...options,
params: {...params, ...options?.params},}
);
}
params: { ...params, ...options?.params },
});
};

/**
* @summary Info for a specific pet
*/
export const showPetById = <TData = AxiosResponse<Pet>>(
petId: string, options?: AxiosRequestConfig
): Promise<TData> => {
return axios.get(
`/pets/${petId}`,options
);
}
petId: string,
options?: AxiosRequestConfig,
): Promise<TData> => {
return axios.get(`/pets/${petId}`, options);
};

export type ListPetsResult = AxiosResponse<PetsArray>
export type CreatePetsResult = AxiosResponse<void>
export type ListPetsNestedArrayResult = AxiosResponse<PetsNestedArray>
export type ShowPetByIdResult = AxiosResponse<Pet>
export type ListPetsResult = AxiosResponse<PetsArray>;
export type CreatePetsResult = AxiosResponse<void>;
export type ListPetsNestedArrayResult = AxiosResponse<PetsNestedArray>;
export type ShowPetByIdResult = AxiosResponse<Pet>;
97 changes: 43 additions & 54 deletions samples/basic/api/endpoints/petstoreFromFileSpecWithConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,13 @@
* Swagger Petstore
* OpenAPI spec version: 1.0.0
*/
import axios from 'axios'
import type {
AxiosRequestConfig,
AxiosResponse
} from 'axios'
import axios from 'axios';
import type { AxiosRequestConfig, AxiosResponse } from 'axios';
export type ListPetsNestedArrayParams = {
/**
* How many items to return at one time (max 100)
*/
limit?: string;
/**
* How many items to return at one time (max 100)
*/
limit?: string;
};

export type CreatePetsBody = {
Expand All @@ -22,10 +19,10 @@ export type CreatePetsBody = {
};

export type ListPetsParams = {
/**
* How many items to return at one time (max 100)
*/
limit?: string;
/**
* How many items to return at one time (max 100)
*/
limit?: string;
};

export interface Error {
Expand All @@ -43,17 +40,16 @@ export interface PetsNestedArray {
data?: Pet[];
}

export type PetCountry = typeof PetCountry[keyof typeof PetCountry];

export type PetCountry = (typeof PetCountry)[keyof typeof PetCountry];

// eslint-disable-next-line @typescript-eslint/no-redeclare
export const PetCountry = {
'People\'s_Republic_of_China': 'People\'s Republic of China',
"People's_Republic_of_China": "People's Republic of China",
Uruguay: 'Uruguay',
} as const;

export type PetCallingCode = typeof PetCallingCode[keyof typeof PetCallingCode];

export type PetCallingCode =
(typeof PetCallingCode)[keyof typeof PetCallingCode];

// eslint-disable-next-line @typescript-eslint/no-redeclare
export const PetCallingCode = {
Expand Down Expand Up @@ -86,60 +82,53 @@ export interface Pet {
tag?: string | null;
}





/**
/**
* @summary List all pets
*/
export const listPets = <TData = AxiosResponse<PetsArray>>(
params?: ListPetsParams, options?: AxiosRequestConfig
): Promise<TData> => {
return axios.get(
`/pets`,{
params?: ListPetsParams,
options?: AxiosRequestConfig,
): Promise<TData> => {
return axios.get(`/pets`, {
...options,
params: {...params, ...options?.params},}
);
}
params: { ...params, ...options?.params },
});
};

/**
* @summary Create a pet
*/
export const createPets = <TData = AxiosResponse<void>>(
createPetsBody: CreatePetsBody, options?: AxiosRequestConfig
): Promise<TData> => {
return axios.post(
`/pets`,
createPetsBody,options
);
}
createPetsBody: CreatePetsBody,
options?: AxiosRequestConfig,
): Promise<TData> => {
return axios.post(`/pets`, createPetsBody, options);
};

/**
* @summary List all pets as nested array
*/
export const listPetsNestedArray = <TData = AxiosResponse<PetsNestedArray>>(
params?: ListPetsNestedArrayParams, options?: AxiosRequestConfig
): Promise<TData> => {
return axios.get(
`/pets-nested-array`,{
params?: ListPetsNestedArrayParams,
options?: AxiosRequestConfig,
): Promise<TData> => {
return axios.get(`/pets-nested-array`, {
...options,
params: {...params, ...options?.params},}
);
}
params: { ...params, ...options?.params },
});
};

/**
* @summary Info for a specific pet
*/
export const showPetById = <TData = AxiosResponse<Pet>>(
petId: string, options?: AxiosRequestConfig
): Promise<TData> => {
return axios.get(
`/pets/${petId}`,options
);
}
petId: string,
options?: AxiosRequestConfig,
): Promise<TData> => {
return axios.get(`/pets/${petId}`, options);
};

export type ListPetsResult = AxiosResponse<PetsArray>
export type CreatePetsResult = AxiosResponse<void>
export type ListPetsNestedArrayResult = AxiosResponse<PetsNestedArray>
export type ShowPetByIdResult = AxiosResponse<Pet>
export type ListPetsResult = AxiosResponse<PetsArray>;
export type CreatePetsResult = AxiosResponse<void>;
export type ListPetsNestedArrayResult = AxiosResponse<PetsNestedArray>;
export type ShowPetByIdResult = AxiosResponse<Pet>;

0 comments on commit 43766c8

Please sign in to comment.