Skip to content

Commit

Permalink
fix: fix return type is unknown
Browse files Browse the repository at this point in the history
  • Loading branch information
KoichiKiyokawa committed Feb 23, 2023
1 parent ad9724b commit a11bae6
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 10 deletions.
3 changes: 1 addition & 2 deletions src/__snapshots__/index.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ export interface operations {
};
}
export const operationIdToPath = {
listUsers: \\"/users\\",
createUser: \\"/users\\",
Expand All @@ -124,7 +123,7 @@ type Func<OpId extends OperationIds> = (
OperationIdToResponseBody<OpId> extends never ? {} : { body: OperationIdToResponseBody<OpId> }
)
) => Promise<
Get<operations[OpId], [\\"responses\\", \\"200\\", \\"content\\", \\"application/json\\"]>
Get<operations[OpId], [\\"responses\\", 200, \\"content\\", \\"application/json\\"]>
>
type Fetchers = {
Expand Down
3 changes: 1 addition & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ export default async function generate({
import { Get } from "${packageName}"
${await openapiTS(schema, { ...openApiTsOption, commentHeader: "" })}
export const operationIdToPath = {
${[...operationIdToSchemaInfo.entries()]
.map(([operationId, { path }]) => `${operationId}: "${path}"`)
Expand All @@ -53,7 +52,7 @@ type Func<OpId extends OperationIds> = (
OperationIdToResponseBody<OpId> extends never ? {} : { body: OperationIdToResponseBody<OpId> }
)
) => Promise<
Get<operations[OpId], ["responses", "200", "content", "application/json"]>
Get<operations[OpId], ["responses", 200, "content", "application/json"]>
>
type Fetchers = {
Expand Down
22 changes: 18 additions & 4 deletions test/generated/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,29 @@ test("listUsers", async () => {
{ id: 1, name: "John" },
{ id: 2, name: "Jane" },
];
const h = rest.get(`${baseURL}/users`, (_req, res, ctx) => {
return res(ctx.json(dummyUsers));
});
server.use(h);
server.use(
rest.get(`${baseURL}/users`, (_req, res, ctx) => {
return res(ctx.json(dummyUsers));
}),
);

const fetcher = createFetcher((path, { method, body }) =>
axios({ baseURL, url: path, method, data: body }).then((res) => res.data),
);
const res = await fetcher.listUsers({ query: { per: 10, page: 0 } });

expect(res).toStrictEqual(dummyUsers);

expectTypeOf(res).toMatchTypeOf<
{
id?: number | undefined;
username?: string | undefined;
firstName?: string | undefined;
lastName?: string | undefined;
email?: string | undefined;
password?: string | undefined;
phone?: string | undefined;
userStatus?: number | undefined;
}[]
>();
});
3 changes: 1 addition & 2 deletions test/generated/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ export interface operations {
};
}


export const operationIdToPath = {
listUsers: "/users",
createUser: "/users",
Expand All @@ -121,7 +120,7 @@ type Func<OpId extends OperationIds> = (
OperationIdToResponseBody<OpId> extends never ? {} : { body: OperationIdToResponseBody<OpId> }
)
) => Promise<
Get<operations[OpId], ["responses", "200", "content", "application/json"]>
Get<operations[OpId], ["responses", 200, "content", "application/json"]>
>

type Fetchers = {
Expand Down

0 comments on commit a11bae6

Please sign in to comment.