Skip to content

Commit

Permalink
fix: export type Client for FunctionalApiClient (#101)
Browse files Browse the repository at this point in the history
  • Loading branch information
Himenon committed Mar 20, 2023
1 parent 27ca48e commit aeb317b
Show file tree
Hide file tree
Showing 11 changed files with 51 additions and 24 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
import ts from "typescript";
import type { TsGenerator } from "../../../api";

export const create = (factory: TsGenerator.Factory.Type) => {
return factory.TypeAliasDeclaration.create({
export: true,
name: "Client",
type: factory.TypeReferenceNode.create({
name: `ReturnType<typeof createClient>`,
export const create = (factory: TsGenerator.Factory.Type): ts.TypeAliasDeclaration[] => {
return [
factory.TypeAliasDeclaration.create({
name: "ClientFunction<RequestOption>",
type: factory.TypeReferenceNode.create({
name: `typeof createClient<RequestOption>`,
})
}),
factory.TypeAliasDeclaration.create({
export: true,
name: "Client<RequestOption>",
type: factory.TypeReferenceNode.create({
name: `ReturnType<ClientFunction<RequestOption>>`,
})
})
})
]
};
5 changes: 4 additions & 1 deletion src/code-templates/functional-api-client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ export const generator: CodeGenerator.GenerateFunction<Option> = (

const apiClientStatement = FunctionalApiClient.create(factory, codeGeneratorParamsList, option || {});
statements.push(apiClientStatement);
statements.push(ClientTypeDefinition.create(factory));
ClientTypeDefinition.create(factory).forEach(statement => {
statements.push(statement);
})

return statements;
};
2 changes: 1 addition & 1 deletion src/meta.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export const Name = "@himenon/openapi-typescript-code-generator";
export const Version = "0.22.0";
export const Version = "0.22.1";
Original file line number Diff line number Diff line change
Expand Up @@ -3923,6 +3923,7 @@ export const createClient = <RequestOption>(apiClient: ApiClient<RequestOption>,
}
};
};
export type Client = ReturnType<typeof createClient>;
type ClientFunction<RequestOption> = typeof createClient<RequestOption>;
export type Client<RequestOption> = ReturnType<ClientFunction<RequestOption>>;
"
`;
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export interface ApiClient<RequestOption> {
export const createClient = <RequestOption>(apiClient: ApiClient<RequestOption>, baseUrl: string) => {
return {};
};
export type Client = ReturnType<typeof createClient>;
type ClientFunction<RequestOption> = typeof createClient<RequestOption>;
export type Client<RequestOption> = ReturnType<ClientFunction<RequestOption>>;
"
`;
Original file line number Diff line number Diff line change
Expand Up @@ -56556,6 +56556,7 @@ export const createClient = <RequestOption>(apiClient: ApiClient<RequestOption>,
}
};
};
export type Client = ReturnType<typeof createClient>;
type ClientFunction<RequestOption> = typeof createClient<RequestOption>;
export type Client<RequestOption> = ReturnType<ClientFunction<RequestOption>>;
"
`;
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ export const createClient = <RequestOption>(apiClient: ApiClient<RequestOption>,
}
};
};
export type Client = ReturnType<typeof createClient>;
type ClientFunction<RequestOption> = typeof createClient<RequestOption>;
export type Client<RequestOption> = ReturnType<ClientFunction<RequestOption>>;
"
`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,8 @@ export const createClient = <RequestOption>(apiClient: ApiClient<RequestOption>,
}
};
};
export type Client = ReturnType<typeof createClient>;
type ClientFunction<RequestOption> = typeof createClient<RequestOption>;
export type Client<RequestOption> = ReturnType<ClientFunction<RequestOption>>;
"
`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,8 @@ export const createClient = <RequestOption>(apiClient: ApiClient<RequestOption>,
}
};
};
export type Client = ReturnType<typeof createClient>;
type ClientFunction<RequestOption> = typeof createClient<RequestOption>;
export type Client<RequestOption> = ReturnType<ClientFunction<RequestOption>>;
"
`;
Expand Down Expand Up @@ -274,7 +275,8 @@ export const createClient = <RequestOption>(apiClient: ApiClient<RequestOption>,
}
};
};
export type Client = ReturnType<typeof createClient>;
type ClientFunction<RequestOption> = typeof createClient<RequestOption>;
export type Client<RequestOption> = ReturnType<ClientFunction<RequestOption>>;
"
`;
Expand Down Expand Up @@ -308,6 +310,7 @@ export interface ApiClient<RequestOption> {
export const createClient = <RequestOption>(apiClient: ApiClient<RequestOption>, baseUrl: string) => {
return {};
};
export type Client = ReturnType<typeof createClient>;
type ClientFunction<RequestOption> = typeof createClient<RequestOption>;
export type Client<RequestOption> = ReturnType<ClientFunction<RequestOption>>;
"
`;
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,8 @@ export const createClient = <RequestOption>(apiClient: ApiClient<RequestOption>,
}
};
};
export type Client = ReturnType<typeof createClient>;
type ClientFunction<RequestOption> = typeof createClient<RequestOption>;
export type Client<RequestOption> = ReturnType<ClientFunction<RequestOption>>;
"
`;
Expand Down Expand Up @@ -548,7 +549,8 @@ export const createClient = <RequestOption>(apiClient: ApiClient<RequestOption>,
}
};
};
export type Client = ReturnType<typeof createClient>;
type ClientFunction<RequestOption> = typeof createClient<RequestOption>;
export type Client<RequestOption> = ReturnType<ClientFunction<RequestOption>>;
"
`;
Expand Down Expand Up @@ -1036,7 +1038,8 @@ export const createClient = <RequestOption>(apiClient: ApiClient<RequestOption>,
}
};
};
export type Client = ReturnType<typeof createClient>;
type ClientFunction<RequestOption> = typeof createClient<RequestOption>;
export type Client<RequestOption> = ReturnType<ClientFunction<RequestOption>>;
"
`;
Expand Down Expand Up @@ -1093,7 +1096,8 @@ export interface ApiClient<RequestOption> {
export const createClient = <RequestOption>(apiClient: ApiClient<RequestOption>, baseUrl: string) => {
return {};
};
export type Client = ReturnType<typeof createClient>;
type ClientFunction<RequestOption> = typeof createClient<RequestOption>;
export type Client<RequestOption> = ReturnType<ClientFunction<RequestOption>>;
"
`;
Expand Down Expand Up @@ -1231,7 +1235,8 @@ export const createClient = <RequestOption>(apiClient: ApiClient<RequestOption>,
}
};
};
export type Client = ReturnType<typeof createClient>;
type ClientFunction<RequestOption> = typeof createClient<RequestOption>;
export type Client<RequestOption> = ReturnType<ClientFunction<RequestOption>>;
"
`;
Expand Down Expand Up @@ -1377,6 +1382,7 @@ export const createClient = <RequestOption>(apiClient: ApiClient<RequestOption>,
}
};
};
export type Client = ReturnType<typeof createClient>;
type ClientFunction<RequestOption> = typeof createClient<RequestOption>;
export type Client<RequestOption> = ReturnType<ClientFunction<RequestOption>>;
"
`;
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export const createClient = <RequestOption>(apiClient: ApiClient<RequestOption>,
}
};
};
export type Client = ReturnType<typeof createClient>;
type ClientFunction<RequestOption> = typeof createClient<RequestOption>;
export type Client<RequestOption> = ReturnType<ClientFunction<RequestOption>>;
"
`;

0 comments on commit aeb317b

Please sign in to comment.