Skip to content

Commit 8fd3126

Browse files
bonukaijs2me
andauthored
Add option to change main Api class name (#320)
* Update api.eta * Update index.d.ts * Update index.js * Update index.js * Update config.js Co-authored-by: Sergey S. Volkov <[email protected]>
1 parent 5a09a7a commit 8fd3126

File tree

5 files changed

+7
-1
lines changed

5 files changed

+7
-1
lines changed

index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,7 @@ export interface GenerateApiConfiguration {
343343
routeName: string;
344344
};
345345
routeNameDuplicatesMap: Map<string, string>;
346+
apiClassName: string
346347
};
347348
modelTypes: ModelType[];
348349
rawModelTypes: SchemaComponent[];

index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ generateApi({
106106
typePrefix: program.typePrefix,
107107
typeSuffix: program.typeSuffix,
108108
patch: !!program.patch,
109+
apiClassName,
109110
}).catch((err) => {
110111
// NOTE collect all errors on top level and shows to users in any case
111112
console.error(err);

src/config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ const config = {
9191
typeSuffix: "",
9292
patch: false,
9393
componentTypeNameResolver: new NameResolver([]),
94+
/** name of the main exported class */
95+
apiClassName: "Api",
9496
};
9597

9698
/** needs to use data everywhere in project */

src/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ module.exports = {
6464
typeSuffix = config.typeSuffix,
6565
patch = config.patch,
6666
authorizationToken,
67+
apiClassName = config.apiClassName,
6768
}) =>
6869
new Promise((resolve, reject) => {
6970
addToConfig({
@@ -99,6 +100,7 @@ module.exports = {
99100
typePrefix,
100101
typeSuffix,
101102
patch,
103+
apiClassName,
102104
});
103105
(spec
104106
? convertSwaggerObject(spec, { patch })

templates/default/api.eta

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ const descriptionLines = _.compact([
3636
<% }) %>
3737
*/
3838
<% } %>
39-
export class Api<SecurityDataType extends unknown><% if (!config.singleHttpClient) { %> extends HttpClient<SecurityDataType> <% } %> {
39+
export class <%~ config.apiClassName %><SecurityDataType extends unknown><% if (!config.singleHttpClient) { %> extends HttpClient<SecurityDataType> <% } %> {
4040

4141
<% if(config.singleHttpClient) { %>
4242
http: HttpClient<SecurityDataType>;

0 commit comments

Comments
 (0)