Skip to content

Commit

Permalink
fix(hono): validator return parsed value (#1339)
Browse files Browse the repository at this point in the history
* fix(hono): validator return parsed value

* fix(format): check

* fix(format): check
  • Loading branch information
anymaniax committed Apr 30, 2024
1 parent 3d965f4 commit 6d41605
Show file tree
Hide file tree
Showing 13 changed files with 252 additions and 278 deletions.
2 changes: 2 additions & 0 deletions packages/hono/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -843,6 +843,8 @@ export const zValidator =
'Content-Type': 'application/json',
},
});
} else {
c.res = new Response(JSON.stringify(result.data), c.res);
}
}
};
Expand Down
6 changes: 3 additions & 3 deletions packages/orval/src/utils/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,11 +215,11 @@ export const normalizeOptions = async (
useMutation: outputOptions.override?.query?.useMutation ?? true,
signal: outputOptions.override?.query?.signal ?? true,
shouldExportMutatorHooks:
outputOptions.override?.query?.shouldExportMutatorHooks ?? true,
outputOptions.override?.query?.shouldExportMutatorHooks ?? true,
shouldExportHttpClient:
outputOptions.override?.query?.shouldExportHttpClient ?? true,
outputOptions.override?.query?.shouldExportHttpClient ?? true,
shouldExportQueryKey:
outputOptions.override?.query?.shouldExportQueryKey ?? true,
outputOptions.override?.query?.shouldExportQueryKey ?? true,
...normalizeQueryOptions(outputOptions.override?.query, workspace),
},
zod: {
Expand Down
4 changes: 2 additions & 2 deletions packages/zod/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,8 @@ export const generateZodValidationSchemaDefinition = (
const separator = schema.allOf
? 'allOf'
: schema.oneOf
? 'oneOf'
: 'anyOf';
? 'oneOf'
: 'anyOf';

const schemas = (schema.allOf ?? schema.oneOf ?? schema.anyOf) as (
| SchemaObject
Expand Down
64 changes: 27 additions & 37 deletions samples/basic/api/endpoints/petstoreFromFileSpec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,18 @@
* 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 CreatePetsBody = {
name: string;
tag: string;
};

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 Down Expand Up @@ -54,46 +51,39 @@ export interface Pet {
*/
export type Pets = Pet[];





/**
/**
* @summary List all pets
*/
export const listPets = <TData = AxiosResponse<Pets>>(
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 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<Pets>
export type CreatePetsResult = AxiosResponse<void>
export type ShowPetByIdResult = AxiosResponse<Pet>
export type ListPetsResult = AxiosResponse<Pets>;
export type CreatePetsResult = AxiosResponse<void>;
export type ShowPetByIdResult = AxiosResponse<Pet>;
64 changes: 27 additions & 37 deletions samples/basic/api/endpoints/petstoreFromFileSpecWithConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,18 @@
* 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 CreatePetsBody = {
name: string;
tag: string;
};

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 Down Expand Up @@ -54,46 +51,39 @@ export interface Pet {
*/
export type Pets = Pet[];





/**
/**
* @summary List all pets
*/
export const listPets = <TData = AxiosResponse<Pets>>(
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 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<Pets>
export type CreatePetsResult = AxiosResponse<void>
export type ShowPetByIdResult = AxiosResponse<Pet>
export type ListPetsResult = AxiosResponse<Pets>;
export type CreatePetsResult = AxiosResponse<void>;
export type ShowPetByIdResult = AxiosResponse<Pet>;
Loading

0 comments on commit 6d41605

Please sign in to comment.