mirror of
https://github.com/ferdikoomen/openapi-typescript-codegen.git
synced 2025-12-08 20:16:21 +00:00
- Working on whitespace issues
This commit is contained in:
parent
76690fbe2d
commit
cff2376996
@ -88,6 +88,7 @@ export function getModel(openApi: OpenApi, definition: OpenApiSchema, name: stri
|
||||
result.base = additionalProperties.base;
|
||||
result.template = additionalProperties.template;
|
||||
result.imports.push(...additionalProperties.imports);
|
||||
result.imports.push('Dictionary');
|
||||
} else {
|
||||
const additionalProperties = getModel(openApi, definition.additionalProperties);
|
||||
result.export = 'dictionary';
|
||||
@ -96,6 +97,7 @@ export function getModel(openApi: OpenApi, definition: OpenApiSchema, name: stri
|
||||
result.template = additionalProperties.template;
|
||||
result.link = additionalProperties;
|
||||
result.imports.push(...additionalProperties.imports);
|
||||
result.imports.push('Dictionary');
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -1,22 +1,20 @@
|
||||
{{#if description}}
|
||||
{{~#if description}}
|
||||
/**
|
||||
* {{{description}}}
|
||||
*/
|
||||
{{/if}}
|
||||
{{~/if}}
|
||||
export type {{{name}}} = {{>type}}{{#if nullable}} | null{{/if}};
|
||||
|
||||
export namespace {{{name}}} {
|
||||
|
||||
{{#indent}}
|
||||
export const schema = {{>validation}};
|
||||
export const schema = {{>validation}};
|
||||
|
||||
export function validate(value: any): Promise<{{{name}}}{{#if nullable}} | null{{/if}}> {
|
||||
return schema.validate(value, { strict: true });
|
||||
}
|
||||
export async function validate(value: any): Promise<{{{name}}}{{#if nullable}} | null{{/if}}> {
|
||||
return schema.validate(value, { strict: true });
|
||||
}
|
||||
|
||||
export function validateSync(value: any): {{{name}}}{{#if nullable}} | null{{/if}} {
|
||||
return schema.validateSync(value, { strict: true });
|
||||
}
|
||||
export function validateSync(value: any): {{{name}}}{{#if nullable}} | null{{/if}} {
|
||||
return schema.validateSync(value, { strict: true });
|
||||
}
|
||||
{{/indent}}
|
||||
|
||||
}
|
||||
|
||||
@ -1,22 +1,20 @@
|
||||
{{#if description}}
|
||||
{{~#if description}}
|
||||
/**
|
||||
* {{{description}}}
|
||||
*/
|
||||
{{/if}}
|
||||
{{~/if}}
|
||||
export type {{{name}}} = {{>type}}{{#if nullable}} | null{{/if}};
|
||||
|
||||
export namespace {{{name}}} {
|
||||
|
||||
{{#indent}}
|
||||
export const schema = {{>validation}};
|
||||
export const schema = {{>validation}};
|
||||
|
||||
export function validate(value: any): Promise<{{{name}}}{{#if nullable}} | null{{/if}}> {
|
||||
return schema.validate(value, { strict: true });
|
||||
}
|
||||
export async function validate(value: any): Promise<{{{name}}}{{#if nullable}} | null{{/if}}> {
|
||||
return schema.validate(value, { strict: true });
|
||||
}
|
||||
|
||||
export function validateSync(value: any): {{{name}}}{{#if nullable}} | null{{/if}} {
|
||||
return schema.validateSync(value, { strict: true });
|
||||
}
|
||||
export function validateSync(value: any): {{{name}}}{{#if nullable}} | null{{/if}} {
|
||||
return schema.validateSync(value, { strict: true });
|
||||
}
|
||||
{{/indent}}
|
||||
|
||||
}
|
||||
|
||||
@ -1,26 +1,24 @@
|
||||
{{#if description}}
|
||||
{{~#if description}}
|
||||
/**
|
||||
* {{{description}}}
|
||||
*/
|
||||
{{/if}}
|
||||
{{~/if}}
|
||||
export enum {{{name}}} {
|
||||
{{#each enum}}
|
||||
{{~#each enum}}
|
||||
{{{name}}} = {{{value}}},
|
||||
{{/each}}
|
||||
{{~/each}}
|
||||
}
|
||||
|
||||
export namespace {{{name}}} {
|
||||
|
||||
{{#indent}}
|
||||
export const schema = {{>validation}};
|
||||
export const schema = {{>validation}};
|
||||
|
||||
export function validate(value: any): Promise<{{{name}}}> {
|
||||
return schema.validate(value, { strict: true });
|
||||
}
|
||||
export async function validate(value: any): Promise<{{{name}}}> {
|
||||
return schema.validate(value, { strict: true });
|
||||
}
|
||||
|
||||
export function validateSync(value: any): {{{name}}} {
|
||||
return schema.validateSync(value, { strict: true });
|
||||
}
|
||||
export function validateSync(value: any): {{{name}}} {
|
||||
return schema.validateSync(value, { strict: true });
|
||||
}
|
||||
{{/indent}}
|
||||
|
||||
}
|
||||
|
||||
@ -1,22 +1,20 @@
|
||||
{{#if description}}
|
||||
{{~#if description}}
|
||||
/**
|
||||
* {{{description}}}
|
||||
*/
|
||||
{{/if}}
|
||||
{{~/if}}
|
||||
export type {{{name}}} = {{>type}}{{#if nullable}} | null{{/if}};
|
||||
|
||||
export namespace {{{name}}} {
|
||||
|
||||
{{#indent}}
|
||||
export const schema = {{>validation}};
|
||||
export const schema = {{>validation}};
|
||||
|
||||
export function validate(value: any): Promise<{{{name}}}{{#if nullable}} | null{{/if}}> {
|
||||
return schema.validate(value, { strict: true });
|
||||
}
|
||||
export async function validate(value: any): Promise<{{{name}}}{{#if nullable}} | null{{/if}}> {
|
||||
return schema.validate(value, { strict: true });
|
||||
}
|
||||
|
||||
export function validateSync(value: any): {{{name}}}{{#if nullable}} | null{{/if}} {
|
||||
return schema.validateSync(value, { strict: true });
|
||||
}
|
||||
export function validateSync(value: any): {{{name}}}{{#if nullable}} | null{{/if}} {
|
||||
return schema.validateSync(value, { strict: true });
|
||||
}
|
||||
{{/indent}}
|
||||
|
||||
}
|
||||
|
||||
@ -1,52 +1,47 @@
|
||||
{{#if description}}
|
||||
{{~#if description}}
|
||||
/**
|
||||
* {{{description}}}
|
||||
*/
|
||||
{{/if}}
|
||||
{{~/if}}
|
||||
export interface {{{name}}}{{{template}}}{{#if extends}} extends {{#each extends}}{{{this}}}{{#unless @last}}, {{/unless}}{{/each}}{{/if}} {
|
||||
|
||||
{{#indent}}
|
||||
{{#each properties}}
|
||||
{{#if description}}
|
||||
/**
|
||||
* {{{description}}}
|
||||
*/
|
||||
{{/if}}
|
||||
{{#if readOnly}}readonly {{/if}}{{{name}}}{{#unless required}}?{{/unless}}: {{>type}}{{#if nullable}} | null{{/if}};
|
||||
{{/each}}
|
||||
{{/indent}}
|
||||
|
||||
{{~#indent}}
|
||||
{{~#each properties}}
|
||||
{{~#if description}}
|
||||
/**
|
||||
* {{{description}}}
|
||||
*/
|
||||
{{~/if}}
|
||||
{{#if readOnly}}readonly {{/if}}{{{name}}}{{#unless required}}?{{/unless}}: {{>type}}{{#if nullable}} | null{{/if}};
|
||||
{{~/each}}
|
||||
{{~/indent}}
|
||||
}
|
||||
|
||||
export namespace {{{name}}} {
|
||||
|
||||
{{#indent}}
|
||||
{{#each enums}}
|
||||
{{#if description}}
|
||||
/**
|
||||
* {{{description}}}
|
||||
*/
|
||||
{{/if}}
|
||||
export enum {{{name}}} {
|
||||
{{#each values}}
|
||||
{{{name}}} = {{{value}}},
|
||||
{{~#each enums}}
|
||||
{{~#if description}}
|
||||
/**
|
||||
* {{{description}}}
|
||||
*/
|
||||
{{~/if}}
|
||||
export enum {{{name}}} {
|
||||
{{~#each values}}
|
||||
{{{name}}} = {{{value}}},
|
||||
{{~/each}}
|
||||
}
|
||||
{{/each}}
|
||||
}
|
||||
export const schema: yup.ObjectSchema<{{{name}}}{{{template}}}> = (
|
||||
{{~#indent}}
|
||||
{{>validation}}
|
||||
{{~/indent}}
|
||||
);
|
||||
|
||||
{{/each}}
|
||||
export const schema: yup.ObjectSchema<{{{name}}}{{{template}}}> = (
|
||||
{{#indent}}
|
||||
{{>validation}}
|
||||
export async function validate(value: any): Promise<{{{name}}}{{{template}}}> {
|
||||
return schema.validate(value, { strict: true });
|
||||
}
|
||||
|
||||
export function validateSync(value: any): {{{name}}}{{{template}}} {
|
||||
return schema.validateSync(value, { strict: true });
|
||||
}
|
||||
{{/indent}}
|
||||
/**/);
|
||||
|
||||
export function validate(value: any): Promise<{{{name}}}{{{template}}}> {
|
||||
return schema.validate(value, { strict: true });
|
||||
}
|
||||
|
||||
export function validateSync(value: any): {{{name}}}{{{template}}} {
|
||||
return schema.validateSync(value, { strict: true });
|
||||
}
|
||||
{{/indent}}
|
||||
|
||||
}
|
||||
|
||||
@ -1,17 +1,20 @@
|
||||
{{~#if description}}
|
||||
/**
|
||||
* {{{description}}}
|
||||
*/
|
||||
{{~/if}}
|
||||
export type {{{name}}} = {{>type}}{{#if nullable}} | null{{/if}};
|
||||
|
||||
export namespace {{{name}}} {
|
||||
|
||||
{{#indent}}
|
||||
export const schema = {{>validation}};
|
||||
export const schema = {{>validation}};
|
||||
|
||||
export function validate(value: any): Promise<{{{name}}}{{#if nullable}} | null{{/if}}> {
|
||||
return schema.validate(value, { strict: true });
|
||||
}
|
||||
export async function validate(value: any): Promise<{{{name}}}{{#if nullable}} | null{{/if}}> {
|
||||
return schema.validate(value, { strict: true });
|
||||
}
|
||||
|
||||
export function validateSync(value: any): {{{name}}}{{#if nullable}} | null{{/if}} {
|
||||
return schema.validateSync(value, { strict: true });
|
||||
}
|
||||
export function validateSync(value: any): {{{name}}}{{#if nullable}} | null{{/if}} {
|
||||
return schema.validateSync(value, { strict: true });
|
||||
}
|
||||
{{/indent}}
|
||||
|
||||
}
|
||||
|
||||
@ -5,17 +5,14 @@
|
||||
|
||||
export { ApiError } from './core/ApiError';
|
||||
export { isSuccess } from './core/isSuccess';
|
||||
export { Dictionary } from './core/Dictionary';
|
||||
export { OpenAPI } from './core/OpenAPI';
|
||||
{{#if models}}
|
||||
|
||||
{{#each models}}
|
||||
{{~#each models}}
|
||||
export { {{{this}}} } from './models/{{{this}}}';
|
||||
{{/each}}
|
||||
{{/if}}
|
||||
{{~/each}}
|
||||
{{~/if}}
|
||||
{{#if services}}
|
||||
|
||||
{{#each services}}
|
||||
{{~#each services}}
|
||||
export { {{{this}}} } from './services/{{{this}}}';
|
||||
{{/each}}
|
||||
{{/if}}
|
||||
{{~/each}}
|
||||
{{~/if}}
|
||||
|
||||
@ -2,25 +2,22 @@
|
||||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
/* prettier-ignore */
|
||||
|
||||
{{#if imports}}
|
||||
{{#each imports}}
|
||||
{{~#each imports}}
|
||||
import { {{{this}}} } from '../models/{{{this}}}';
|
||||
{{/each}}
|
||||
{{/if}}
|
||||
import { Dictionary } from '../core/Dictionary';
|
||||
{{~/each}}
|
||||
{{~/if}}
|
||||
import * as yup from 'yup';
|
||||
|
||||
{{#eq export 'reference'}}
|
||||
{{>exportReference}}
|
||||
{{else eq export 'generic'}}
|
||||
{{>exportGeneric}}
|
||||
{{else eq export 'enum'}}
|
||||
{{>exportEnum}}
|
||||
{{else eq export 'array'}}
|
||||
{{>exportArray}}
|
||||
{{else eq export 'dictionary'}}
|
||||
{{>exportDictionary}}
|
||||
{{else eq export 'interface'}}
|
||||
{{>exportInterface}}
|
||||
{{/eq}}
|
||||
{{~>exportReference}}
|
||||
{{~else eq export 'generic'}}
|
||||
{{~>exportGeneric}}
|
||||
{{~else eq export 'enum'}}
|
||||
{{~>exportEnum}}
|
||||
{{~else eq export 'array'}}
|
||||
{{~>exportArray}}
|
||||
{{~else eq export 'dictionary'}}
|
||||
{{~>exportDictionary}}
|
||||
{{~else eq export 'interface'}}
|
||||
{{~>exportInterface}}
|
||||
{{~/eq}}
|
||||
|
||||
@ -2,78 +2,72 @@
|
||||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
/* prettier-ignore */
|
||||
|
||||
{{#if imports}}
|
||||
{{#each imports}}
|
||||
{{~#each imports}}
|
||||
import { {{{this}}} } from '../models/{{{this}}}';
|
||||
{{/each}}
|
||||
{{/if}}
|
||||
{{~/each}}
|
||||
{{~/if}}
|
||||
import { ApiError, catchGenericError } from '../core/ApiError';
|
||||
import { request } from '../core/request';
|
||||
import { Dictionary } from '../core/Dictionary';
|
||||
import { isValidRequiredParam } from '../core/isValidRequiredParam';
|
||||
import { OpenAPI } from '../core/OpenAPI';
|
||||
import { Result } from '../core/Result';
|
||||
|
||||
export class {{{name}}} {
|
||||
|
||||
{{#each operations}}
|
||||
{{~#each operations}}
|
||||
/**
|
||||
{{#if deprecated}}
|
||||
{{~#if deprecated}}
|
||||
* @deprecated
|
||||
{{/if}}
|
||||
{{#if summary}}
|
||||
{{~/if}}
|
||||
{{~#if summary}}
|
||||
* {{{summary}}}
|
||||
{{/if}}
|
||||
{{#if description}}
|
||||
{{~/if}}
|
||||
{{~#if description}}
|
||||
* {{{description}}}
|
||||
{{/if}}
|
||||
{{#if parameters}}
|
||||
{{#each parameters}}
|
||||
{{~/if}}
|
||||
{{~#if parameters}}
|
||||
{{~#each parameters}}
|
||||
* @param {{{name}}} {{{description}}}
|
||||
{{/each}}
|
||||
{{/if}}
|
||||
{{~/each}}
|
||||
{{~/if}}
|
||||
*/
|
||||
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}}
|
||||
{{~#each parameters}}
|
||||
{{~#if required}}
|
||||
isValidRequiredParam({{{name}}}, '{{{name}}}');
|
||||
{{~/if}}
|
||||
{{~/each}}
|
||||
{{/if}}
|
||||
{{/each}}
|
||||
{{/if}}
|
||||
|
||||
const result = await request({
|
||||
method: '{{{method}}}',
|
||||
path: `{{{path}}}`,
|
||||
{{~#if parametersHeader~}}
|
||||
headers: {
|
||||
{{#each parametersHeader}}
|
||||
{{~#each parametersHeader}}
|
||||
'{{{prop}}}': {{{name}}},
|
||||
{{/each}}
|
||||
{{~/each}}
|
||||
},
|
||||
{{~/if~}}
|
||||
{{~#if parametersQuery~}}
|
||||
{{~/if}}
|
||||
{{~#if parametersQuery}}
|
||||
query: {
|
||||
{{#each parametersQuery}}
|
||||
{{~#each parametersQuery}}
|
||||
'{{{prop}}}': {{{name}}},
|
||||
{{/each}}
|
||||
{{~/each}}
|
||||
},
|
||||
{{~/if~}}
|
||||
{{~#if parametersForm~}}
|
||||
{{~/if}}
|
||||
{{~#if parametersForm}}
|
||||
formData: {
|
||||
{{#each parametersForm}}
|
||||
{{~#each parametersForm}}
|
||||
'{{{prop}}}': {{{name}}},
|
||||
{{/each}}
|
||||
{{~/each}}
|
||||
},
|
||||
{{~/if~}}
|
||||
{{~#if parametersBody~}}
|
||||
{{~/if}}
|
||||
{{~#if parametersBody}}
|
||||
body: {{{parametersBody.name}}},
|
||||
{{~/if~}}
|
||||
{{~/if}}
|
||||
});
|
||||
{{#if errors}}
|
||||
|
||||
{{~#if errors}}
|
||||
if (!result.ok) {
|
||||
switch (result.status) {
|
||||
{{#each errors}}
|
||||
@ -81,12 +75,10 @@ export class {{{name}}} {
|
||||
{{/each}}
|
||||
}
|
||||
}
|
||||
{{/if}}
|
||||
|
||||
{{~/if}}
|
||||
catchGenericError(result);
|
||||
|
||||
return result.body;
|
||||
}
|
||||
|
||||
{{/each}}
|
||||
{{~/each}}
|
||||
}
|
||||
|
||||
@ -1,13 +1,13 @@
|
||||
{{~#eq export 'reference'~}}
|
||||
{{>typeForReference}}
|
||||
{{~else eq export 'generic'~}}
|
||||
{{>typeForGeneric}}
|
||||
{{~else eq export 'enum'~}}
|
||||
{{>typeForEnum}}
|
||||
{{~else eq export 'array'~}}
|
||||
{{>typeForArray}}
|
||||
{{~else eq export 'dictionary'~}}
|
||||
{{>typeForDictionary}}
|
||||
{{~else eq export 'interface'~}}
|
||||
{{>typeForInterface}}
|
||||
{{~/eq~}}
|
||||
{{~#eq export 'reference'}}
|
||||
{{~>typeForReference}}
|
||||
{{~else eq export 'generic'}}
|
||||
{{~>typeForGeneric}}
|
||||
{{~else eq export 'enum'}}
|
||||
{{~>typeForEnum}}
|
||||
{{~else eq export 'array'}}
|
||||
{{~>typeForArray}}
|
||||
{{~else eq export 'dictionary'}}
|
||||
{{~>typeForDictionary}}
|
||||
{{~else eq export 'interface'}}
|
||||
{{~>typeForInterface}}
|
||||
{{~/eq}}
|
||||
|
||||
@ -1,12 +1,12 @@
|
||||
{
|
||||
{{#indent}}
|
||||
{{#each properties}}
|
||||
{{#if description}}
|
||||
/**
|
||||
* {{{description}}}
|
||||
*/
|
||||
{{/if}}
|
||||
{{#if readOnly}}readonly {{/if}}{{{name}}}{{#unless required}}?{{/unless}}: {{>type}}{{#if nullable}} | null{{/if}},
|
||||
{{/each}}
|
||||
{{~#each properties}}
|
||||
{{~#if description}}
|
||||
/**
|
||||
* {{{description}}}
|
||||
*/
|
||||
{{~/if}}
|
||||
{{#if readOnly}}readonly {{/if}}{{{name}}}{{#unless required}}?{{/unless}}: {{>type}}{{#if nullable}} | null{{/if}},
|
||||
{{~/each}}
|
||||
{{/indent}}
|
||||
/**/}
|
||||
}
|
||||
|
||||
@ -1,31 +1,31 @@
|
||||
{{~#if link~}}
|
||||
{{~#if link}}
|
||||
yup.lazy<Dictionary<{{>type link}}>>(value =>
|
||||
{{#indent}}
|
||||
yup.object<Dictionary<{{>type link}}>>().shape(
|
||||
{{#indent}}
|
||||
Object.entries(value).reduce((obj, item) => ({
|
||||
{{#indent}}
|
||||
...obj,
|
||||
[item[0]]: {{>validation link}},
|
||||
yup.object<Dictionary<{{>type link}}>>().shape(
|
||||
{{#indent}}
|
||||
Object.entries(value).reduce((obj, item) => ({
|
||||
{{#indent}}
|
||||
...obj,
|
||||
[item[0]]: {{>validation link}},
|
||||
{{/indent}}
|
||||
}), {})
|
||||
{{/indent}}
|
||||
)
|
||||
{{/indent}}
|
||||
/**/}), {})
|
||||
{{/indent}}
|
||||
/**/)
|
||||
{{/indent}}
|
||||
/**/)
|
||||
{{~else~}}
|
||||
)
|
||||
{{~else}}
|
||||
yup.lazy<Dictionary<{{{type}}}>>(value =>
|
||||
{{#indent}}
|
||||
yup.object<Dictionary<{{{type}}}>>().shape(
|
||||
{{#indent}}
|
||||
Object.entries(value).reduce((obj, item) => ({
|
||||
{{#indent}}
|
||||
...obj,
|
||||
[item[0]]: {{{base}}}.schema,
|
||||
yup.object<Dictionary<{{{type}}}>>().shape(
|
||||
{{#indent}}
|
||||
Object.entries(value).reduce((obj, item) => ({
|
||||
{{#indent}}
|
||||
...obj,
|
||||
[item[0]]: {{{base}}}.schema,
|
||||
{{/indent}}
|
||||
}), {})
|
||||
{{/indent}}
|
||||
)
|
||||
{{/indent}}
|
||||
/**/}), {})
|
||||
{{/indent}}
|
||||
/**/)
|
||||
{{/indent}}
|
||||
/**/)
|
||||
{{~/if~}}
|
||||
)
|
||||
{{~/if}}
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
yup.mixed{{#if name}}<{{{name}}}>{{/if}}().oneOf([
|
||||
{{#each enum}}
|
||||
{{#if ../name}}
|
||||
{{~#each enum}}
|
||||
{{~#if ../name}}
|
||||
{{{../name}}}.{{{name}}},
|
||||
{{else}}
|
||||
{{~else}}
|
||||
{{{value}}},
|
||||
{{/if}}
|
||||
{{/each}}
|
||||
{{~/if}}
|
||||
{{~/each}}
|
||||
])
|
||||
|
||||
@ -1,17 +1,17 @@
|
||||
{{#if extends}}
|
||||
{{#each extends}}
|
||||
{{~#if extends}}
|
||||
{{~#each extends}}
|
||||
{{{this}}}.schema.concat(
|
||||
{{/each}}
|
||||
{{/if}}
|
||||
{{~/each}}
|
||||
{{~/if}}
|
||||
yup.object{{#if name}}<{{{name}}}>{{/if}}().shape({
|
||||
{{#indent}}
|
||||
{{#each properties}}
|
||||
{{{name}}}: yup.lazy(() => {{>validation}}.default(undefined)){{#if required}}.required(){{/if}}{{#if nullable}}.nullable(){{/if}},
|
||||
{{/each}}
|
||||
{{~#each properties}}
|
||||
{{{name}}}: yup.lazy(() => {{>validation}}.default(undefined)){{#if required}}.required(){{/if}}{{#if nullable}}.nullable(){{/if}},
|
||||
{{~/each}}
|
||||
{{/indent}}
|
||||
/**/}).noUnknown()
|
||||
{{#if extends}}
|
||||
{{#each extends}}
|
||||
}).noUnknown()
|
||||
{{~#if extends}}
|
||||
{{~#each extends}}
|
||||
)
|
||||
{{/each}}
|
||||
{{/if}}
|
||||
{{~/each}}
|
||||
{{~/if}}
|
||||
|
||||
@ -16,6 +16,7 @@ export function readHandlebarsTemplate(filePath: string): Handlebars.TemplateDel
|
||||
strict: true,
|
||||
noEscape: true,
|
||||
preventIndent: true,
|
||||
ignoreStandalone: true,
|
||||
knownHelpersOnly: true,
|
||||
knownHelpers: {
|
||||
indent: true,
|
||||
|
||||
@ -1,18 +1,20 @@
|
||||
import * as Handlebars from 'handlebars';
|
||||
import { EOL } from 'os';
|
||||
import {EOL} from 'os';
|
||||
|
||||
export function registerHandlebarHelpers(): void {
|
||||
Handlebars.registerHelper('indent', function(options: Handlebars.HelperOptions): string {
|
||||
|
||||
Handlebars.registerHelper('indent', function (options: Handlebars.HelperOptions): string {
|
||||
// eslint-disable
|
||||
// prettier-ignore
|
||||
// @ts-ignore
|
||||
return options.fn(this)
|
||||
.split(EOL)
|
||||
.map(line => ` ${line}`)
|
||||
.join(EOL)
|
||||
.map(line => line.replace(/^\s{4}/g, ''))
|
||||
.map(line => `/**/${line}`)
|
||||
.join(EOL);
|
||||
});
|
||||
|
||||
Handlebars.registerHelper('eq', function(a: string, b: string, options: Handlebars.HelperOptions): string {
|
||||
Handlebars.registerHelper('eq', function (a: string, b: string, options: Handlebars.HelperOptions): string {
|
||||
// eslint-disable
|
||||
// prettier-ignore
|
||||
// @ts-ignore
|
||||
|
||||
@ -1,14 +1,13 @@
|
||||
import { writeClientModels } from './writeClientModels';
|
||||
import { writeClientServices } from './writeClientServices';
|
||||
import { Client } from '../client/interfaces/Client';
|
||||
import {writeClientModels} from './writeClientModels';
|
||||
import {writeClientServices} from './writeClientServices';
|
||||
import {Client} from '../client/interfaces/Client';
|
||||
import * as path from 'path';
|
||||
import * as mkdirp from 'mkdirp';
|
||||
import * as rimraf from 'rimraf';
|
||||
import { Templates } from './readHandlebarsTemplates';
|
||||
import { writeClientIndex } from './writeClientIndex';
|
||||
import { Language } from '../index';
|
||||
import {Templates} from './readHandlebarsTemplates';
|
||||
import {writeClientIndex} from './writeClientIndex';
|
||||
import {Language} from '../index';
|
||||
import * as fs from 'fs';
|
||||
import { getFileName } from './getFileName';
|
||||
import * as glob from 'glob';
|
||||
|
||||
/**
|
||||
@ -40,14 +39,13 @@ export function writeClient(client: Client, language: Language, templates: Templ
|
||||
throw new Error(`Could not create output directories`);
|
||||
}
|
||||
|
||||
// Copy all core files
|
||||
const coreFiles = path.resolve(__dirname, `../../src/templates/${language}/core/`);
|
||||
const coreFilesExt = getFileName('*', language);
|
||||
const coreFilesList = glob.sync(coreFilesExt, { cwd: coreFiles });
|
||||
coreFilesList.forEach(file =>
|
||||
// Copy all support files
|
||||
const supportFiles = path.resolve(__dirname, `../../src/templates/${language}/`);
|
||||
const supportFilesList = glob.sync('**/*.{ts,js}', {cwd: supportFiles});
|
||||
supportFilesList.forEach(file =>
|
||||
fs.copyFileSync(
|
||||
path.resolve(coreFiles, file), // From input path
|
||||
path.resolve(outputPathCore, file) // To output path
|
||||
path.resolve(supportFiles, file), // From input path
|
||||
path.resolve(outputPath, file) // To output path
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user