Skip to content

Commit

Permalink
fix(hono): missing import when operationId in pascal case
Browse files Browse the repository at this point in the history
  • Loading branch information
anymaniax committed Apr 11, 2024
1 parent 24b16e2 commit 0794603
Show file tree
Hide file tree
Showing 11 changed files with 252 additions and 282 deletions.
20 changes: 11 additions & 9 deletions packages/hono/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import {
import { getRoute } from './route';
import fs from 'fs-extra';
import { generateZod } from '@orval/zod';
import { getDefaultFilesHeader } from 'orval/src/utils';
import { InfoObject } from 'openapi3-ts/oas30';

const HONO_DEPENDENCIES: GeneratorDependency[] = [
Expand Down Expand Up @@ -55,22 +54,25 @@ export const getHonoHeader: ClientHeaderBuilder = ({

if (output.override.hono?.handlers) {
const handlerFileInfo = getFileInfo(output.override.hono.handlers);
handlers = Object.keys(verbOptions)
.filter((operationName) =>
clientImplementation.includes(`${operationName}Handlers`),
handlers = Object.values(verbOptions)
.filter((verbOption) =>
clientImplementation.includes(`${verbOption.operationName}Handlers`),
)
.map((operationName) => {
.map((verbOption) => {
const handlersPath = upath.relativeSafe(
targetInfo.dirname ?? '',
upath.join(handlerFileInfo.dirname ?? '', `./${operationName}`),
upath.join(
handlerFileInfo.dirname ?? '',
`./${verbOption.operationName}`,
),
);

return `import { ${operationName}Handlers } from '${handlersPath}';`;
return `import { ${verbOption.operationName}Handlers } from '${handlersPath}';`;
})
.join('\n');
} else {
handlers = `import {\n${Object.keys(verbOptions)
.map((operationName) => ` ${operationName}Handlers`)
handlers = `import {\n${Object.values(verbOptions)
.map((verbOption) => ` ${verbOption.operationName}Handlers`)
.join(`, \n`)}\n} from './${tag ?? targetInfo.filename}.handlers';`;
}

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>;

0 comments on commit 0794603

Please sign in to comment.