Skip to content

Commit d9ae7a5

Browse files
Added tenant override to api gen
1 parent e34e246 commit d9ae7a5

File tree

4 files changed

+99
-84
lines changed

4 files changed

+99
-84
lines changed

src/client/interfaces/OperationParameter.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ export interface OperationParameter extends Model {
44
in: 'path' | 'query' | 'header' | 'formData' | 'body' | 'cookie';
55
prop: string;
66
mediaType: string | null;
7+
resolvedName?: string;
78
}

src/templates/core/OpenAPI.hbs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export type OpenAPIConfig = {
1616
HEADERS?: Headers | Resolver<Headers>;
1717
ENCODE_PATH?: (path: string) => string;
1818
FETCH_IMPL?: any;
19+
TENANT?: string;
1920
};
2021

2122
export const OpenAPI: OpenAPIConfig = {
@@ -29,4 +30,5 @@ export const OpenAPI: OpenAPIConfig = {
2930
HEADERS: undefined,
3031
ENCODE_PATH: undefined,
3132
FETCH_IMPL: undefined,
33+
TENANT: undefined,
3234
};

src/templates/exportService.hbs

Lines changed: 85 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import type { CancelablePromise } from '../core/CancelablePromise';
2525
import { BaseHttpRequest } from '../core/BaseHttpRequest';
2626
{{else}}
2727
import type { BaseHttpRequest } from '../core/BaseHttpRequest';
28+
import type { OpenAPIConfig } from '../core/OpenAPI';
2829
{{/equals}}
2930
{{else}}
3031
import { OpenAPI } from '../core/OpenAPI';
@@ -33,13 +34,13 @@ import { request as __request } from '../core/request';
3334

3435
{{#equals @root.httpClient 'angular'}}
3536
@Injectable({
36-
providedIn: 'root',
37+
providedIn: 'root',
3738
})
3839
{{/equals}}
3940
export class {{{name}}}{{{@root.postfix}}} {
40-
{{#if @root.exportClient}}
41+
{{#if @root.exportClient}}
4142

42-
constructor(public readonly httpRequest: BaseHttpRequest) {}
43+
constructor(public readonly httpRequest: BaseHttpRequest, public config?: Partial<OpenAPIConfig>) {}
4344
{{else}}
4445
{{#equals @root.httpClient 'angular'}}
4546

@@ -50,103 +51,103 @@ export class {{{name}}}{{{@root.postfix}}} {
5051
{{#each operations}}
5152
/**
5253
{{#if deprecated}}
53-
* @deprecated
54+
* @deprecated
5455
{{/if}}
5556
{{#if summary}}
56-
* {{{escapeComment summary}}}
57+
* {{{escapeComment summary}}}
5758
{{/if}}
5859
{{#if description}}
59-
* {{{escapeComment description}}}
60+
* {{{escapeComment description}}}
6061
{{/if}}
6162
{{#unless @root.useOptions}}
6263
{{#if parameters}}
6364
{{#each parameters}}
64-
* @param {{{name}}} {{#if description}}{{{escapeComment description}}}{{/if}}
65+
* @param {{{name}}} {{#if description}}{{{escapeComment description}}}{{/if}}
6566
{{/each}}
6667
{{/if}}
6768
{{/unless}}
6869
{{#each results}}
69-
* @returns {{{type}}} {{#if description}}{{{escapeComment description}}}{{/if}}
70+
* @returns {{{type}}} {{#if description}}{{{escapeComment description}}}{{/if}}
7071
{{/each}}
71-
* @throws ApiError
72-
*/
72+
* @throws ApiError
73+
*/
7374
{{#if @root.exportClient}}
7475
{{#equals @root.httpClient 'angular'}}
7576
public {{{name}}}({{>parameters}}): Observable<{{>result}}> {
7677
return this.httpRequest.request({
77-
{{else}}
78-
public {{{name}}}({{>parameters}}): CancelablePromise<{{>result}}> {
79-
return this.httpRequest.request({
80-
{{/equals}}
81-
{{else}}
82-
{{#equals @root.httpClient 'angular'}}
83-
public {{{name}}}({{>parameters}}): Observable<{{>result}}> {
84-
return __request(OpenAPI, this.http, {
85-
{{else}}
86-
public static {{{name}}}({{>parameters}}): CancelablePromise<{{>result}}> {
87-
return __request(OpenAPI, {
88-
{{/equals}}
89-
{{/if}}
90-
method: '{{{method}}}',
91-
url: '{{{path}}}',
92-
{{#if parametersPath}}
93-
path: {
94-
{{#each parametersPath}}
95-
'{{{prop}}}': {{{name}}},
96-
{{/each}}
97-
},
98-
{{/if}}
99-
{{#if parametersCookie}}
100-
cookies: {
101-
{{#each parametersCookie}}
102-
'{{{prop}}}': {{{name}}},
103-
{{/each}}
104-
},
105-
{{/if}}
106-
{{#if parametersHeader}}
107-
headers: {
108-
{{#each parametersHeader}}
109-
'{{{prop}}}': {{{name}}},
110-
{{/each}}
111-
},
112-
{{/if}}
113-
{{#if parametersQuery}}
114-
query: {
115-
{{#each parametersQuery}}
116-
'{{{prop}}}': {{{name}}},
117-
{{/each}}
118-
},
119-
{{/if}}
120-
{{#if parametersForm}}
121-
formData: {
122-
{{#each parametersForm}}
123-
'{{{prop}}}': {{{name}}},
124-
{{/each}}
125-
},
126-
{{/if}}
127-
{{#if parametersBody}}
128-
{{#equals parametersBody.in 'formData'}}
129-
formData: {{{parametersBody.name}}},
130-
{{/equals}}
131-
{{#equals parametersBody.in 'body'}}
132-
body: {{{parametersBody.name}}},
78+
{{else}}
79+
public {{{name}}}({{>parameters}}): CancelablePromise<{{>result}}> {
80+
return this.httpRequest.request({
13381
{{/equals}}
134-
{{#if parametersBody.mediaType}}
135-
mediaType: '{{{parametersBody.mediaType}}}',
136-
{{/if}}
137-
{{/if}}
138-
{{#if responseHeader}}
139-
responseHeader: '{{{responseHeader}}}',
140-
{{/if}}
141-
{{#if errors}}
142-
errors: {
143-
{{#each errors}}
144-
{{{code}}}: `{{{escapeDescription description}}}`,
145-
{{/each}}
146-
},
147-
{{/if}}
148-
});
149-
}
82+
{{else}}
83+
{{#equals @root.httpClient 'angular'}}
84+
public {{{name}}}({{>parameters}}): Observable<{{>result}}> {
85+
return __request(OpenAPI, this.http, {
86+
{{else}}
87+
public static {{{name}}}({{>parameters}}): CancelablePromise<{{>result}}> {
88+
return __request(OpenAPI, {
89+
{{/equals}}
90+
{{/if}}
91+
method: '{{{method}}}',
92+
url: '{{{path}}}',
93+
{{#if parametersPath}}
94+
path: {
95+
{{#each parametersPath}}
96+
'{{{prop}}}': {{{resolvedName}}},
97+
{{/each}}
98+
},
99+
{{/if}}
100+
{{#if parametersCookie}}
101+
cookies: {
102+
{{#each parametersCookie}}
103+
'{{{prop}}}': {{{name}}},
104+
{{/each}}
105+
},
106+
{{/if}}
107+
{{#if parametersHeader}}
108+
headers: {
109+
{{#each parametersHeader}}
110+
'{{{prop}}}': {{{name}}},
111+
{{/each}}
112+
},
113+
{{/if}}
114+
{{#if parametersQuery}}
115+
query: {
116+
{{#each parametersQuery}}
117+
'{{{prop}}}': {{{name}}},
118+
{{/each}}
119+
},
120+
{{/if}}
121+
{{#if parametersForm}}
122+
formData: {
123+
{{#each parametersForm}}
124+
'{{{prop}}}': {{{name}}},
125+
{{/each}}
126+
},
127+
{{/if}}
128+
{{#if parametersBody}}
129+
{{#equals parametersBody.in 'formData'}}
130+
formData: {{{parametersBody.name}}},
131+
{{/equals}}
132+
{{#equals parametersBody.in 'body'}}
133+
body: {{{parametersBody.name}}},
134+
{{/equals}}
135+
{{#if parametersBody.mediaType}}
136+
mediaType: '{{{parametersBody.mediaType}}}',
137+
{{/if}}
138+
{{/if}}
139+
{{#if responseHeader}}
140+
responseHeader: '{{{responseHeader}}}',
141+
{{/if}}
142+
{{#if errors}}
143+
errors: {
144+
{{#each errors}}
145+
{{{code}}}: `{{{escapeDescription description}}}`,
146+
{{/each}}
147+
},
148+
{{/if}}
149+
});
150+
}
150151

151-
{{/each}}
152-
}
152+
{{/each}}
153+
}

src/utils/writeClientServices.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,17 @@ export const writeClientServices = async (
3333
clientName?: string
3434
): Promise<void> => {
3535
for (const service of services) {
36+
for (const op of service.operations) {
37+
for (const p of op.parametersPath) {
38+
p.resolvedName = p.name;
39+
if (p.name == 'tenant') {
40+
p.resolvedName = p.name + ' ?? this.config?.TENANT'
41+
p.isRequired = false
42+
}
43+
}
44+
}
45+
46+
3647
const file = resolve(outputPath, `${service.name}${postfix}.ts`);
3748
const templateResult = templates.exports.service({
3849
...service,

0 commit comments

Comments
 (0)