mirror of
https://github.com/ferdikoomen/openapi-typescript-codegen.git
synced 2025-12-08 20:16:21 +00:00
- Fixed service template
- Added dictionary
This commit is contained in:
parent
7167c97c1d
commit
05d5a10599
@ -34,12 +34,14 @@ export class {{{name}}} {
|
||||
*/
|
||||
public static async {{{name}}}({{#each parameters}}{{{name}}}{{#unless required}}?{{/unless}}: {{{type}}}{{#if nullable}} | null{{/if}}{{#unless @last}}, {{/unless}}{{/each}}): Promise<{{{result}}}> {
|
||||
{{#if parameters}}
|
||||
|
||||
{{#each parameters}}
|
||||
{{#if required}}
|
||||
isValidRequiredParam({{{name}}}, '{{{name}}}');
|
||||
{{/if}}
|
||||
{{/each}}
|
||||
{{/if}}
|
||||
|
||||
const result = await request({
|
||||
method: '{{{method}}}',
|
||||
path: `{{{path}}}`,
|
||||
@ -69,6 +71,7 @@ export class {{{name}}} {
|
||||
{{/if}}
|
||||
});
|
||||
{{#if errors}}
|
||||
|
||||
if (!result.ok) {
|
||||
switch (result.status) {
|
||||
{{#each errors}}
|
||||
@ -77,9 +80,11 @@ export class {{{name}}} {
|
||||
}
|
||||
}
|
||||
{{/if}}
|
||||
|
||||
catchGenericError(result);
|
||||
|
||||
return result.body;
|
||||
}
|
||||
|
||||
{{/each}}
|
||||
}
|
||||
|
||||
@ -2,10 +2,11 @@ import { Model } from '../client/interfaces/Model';
|
||||
|
||||
export function getModelNames(models: Map<string, Model>): string[] {
|
||||
return Array.from(models.values())
|
||||
.map(model => model.name)
|
||||
.concat(['Dictionary'])
|
||||
.sort((a, b) => {
|
||||
const nameA = a.name.toLowerCase();
|
||||
const nameB = b.name.toLowerCase();
|
||||
const nameA = a.toLowerCase();
|
||||
const nameB = b.toLowerCase();
|
||||
return nameA.localeCompare(nameB, 'en');
|
||||
})
|
||||
.map(model => model.name);
|
||||
});
|
||||
}
|
||||
|
||||
@ -2,10 +2,10 @@ import { Service } from '../client/interfaces/Service';
|
||||
|
||||
export function getServiceNames(services: Map<string, Service>): string[] {
|
||||
return Array.from(services.values())
|
||||
.map(service => service.name)
|
||||
.sort((a, b) => {
|
||||
const nameA = a.name.toLowerCase();
|
||||
const nameB = b.name.toLowerCase();
|
||||
const nameA = a.toLowerCase();
|
||||
const nameB = b.toLowerCase();
|
||||
return nameA.localeCompare(nameB, 'en');
|
||||
})
|
||||
.map(service => service.name);
|
||||
});
|
||||
}
|
||||
|
||||
@ -19,7 +19,7 @@ export function writeClientServices(services: Map<string, Service>, language: La
|
||||
const fileName = getFileName(service.name, language);
|
||||
try {
|
||||
const templateData = exportService(service);
|
||||
const templateResult = templates.model(templateData);
|
||||
const templateResult = templates.service(templateData);
|
||||
fs.writeFileSync(path.resolve(outputPath, fileName), format(templateResult));
|
||||
} catch (e) {
|
||||
throw new Error(`Could not write service: "${fileName}"`);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user