Rename file
This commit is contained in:
parent
e3a2f9f921
commit
2059ee3a8a
@ -2,7 +2,7 @@
|
||||
* @author Martin Karkowski
|
||||
* @email m.karkowski@zema.de
|
||||
* @create date 2020-11-09 16:22:51
|
||||
* @modify date 2020-11-10 08:50:17
|
||||
* @modify date 2020-11-11 08:39:33
|
||||
* @desc [description]
|
||||
*/
|
||||
|
||||
@ -12,6 +12,7 @@ import { join } from 'path';
|
||||
import * as TJS from "typescript-json-schema";
|
||||
import { createFile } from "../../helpers/fileMethods";
|
||||
import { flattenSchema, schemaGetDefinition } from "../../helpers/jsonSchemaMethods";
|
||||
import { deepClone } from '../../helpers/objectMethods';
|
||||
import { IJsonSchema } from "../../types/IJSONSchema";
|
||||
import { INopeDescriptor } from "../../types/nope/nopeDescriptor.interface";
|
||||
import { ITypeInformation } from './types/ITypeInformation';
|
||||
@ -28,6 +29,11 @@ import { ITypeInformation } from './types/ITypeInformation';
|
||||
async function _getSchema(param: ITypeInformation, options: {
|
||||
tempDir: string
|
||||
}) {
|
||||
|
||||
if (param.simplifiedSubType === 'void'){
|
||||
return {}
|
||||
}
|
||||
|
||||
// Options for the TJS.Compiler;
|
||||
const compilerOptions: TJS.CompilerOptions = {
|
||||
strictNullChecks: true,
|
||||
@ -51,7 +57,7 @@ async function _getSchema(param: ITypeInformation, options: {
|
||||
export type PARAM = {{{originalCode}}};
|
||||
{{/if}}
|
||||
{{#unless isBaseType}}
|
||||
export type PARAM = {{{simplifiedType}}};
|
||||
export type PARAM = {{{simplifiedSubType}}};
|
||||
{{/unless}}
|
||||
|
||||
`+
|
||||
@ -64,28 +70,27 @@ export type PARAM = {{{simplifiedType}}};
|
||||
);
|
||||
|
||||
const _program = TJS.getProgramFromFiles(
|
||||
[join(options.tempDir, 'param.ts')],
|
||||
[join(options.tempDir, 'temp.ts')],
|
||||
compilerOptions
|
||||
);
|
||||
|
||||
// We can either get the schema for one file and one type...
|
||||
const _schema = TJS.generateSchema(_program, "*", _settings) as any as IJsonSchema;
|
||||
let _schema = JSON.parse(JSON.stringify(TJS.generateSchema(_program, "*", _settings))) as any as IJsonSchema;
|
||||
|
||||
return schemaGetDefinition(flattenSchema(_schema), '#/definitions/PARAM');
|
||||
try {
|
||||
// Try to flatten the Schema:
|
||||
_schema = flattenSchema(deepClone(_schema));
|
||||
return schemaGetDefinition(_schema, '#/definitions/PARAM');
|
||||
} catch(error) {
|
||||
// Failed to flatten the schema. it seams that it is an recursive one.
|
||||
return Object.assign(
|
||||
{},
|
||||
deepClone(_schema),
|
||||
schemaGetDefinition(_schema, '#/definitions/PARAM')
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
async function _defineNoFunctionParam(param: ITypeInformation, options: {
|
||||
tempDir: string
|
||||
}) {
|
||||
|
||||
// Store the flattend schema and extracted Schema of the Element.
|
||||
return {
|
||||
name: param.name,
|
||||
optional: param.isOptional,
|
||||
description: '',
|
||||
schema: await _getSchema(param, options)
|
||||
};
|
||||
}
|
||||
/**
|
||||
* Returns a Schema for a Function:
|
||||
*
|
||||
@ -100,7 +105,7 @@ export async function getSchemaForFunction(param: ITypeInformation, options: {
|
||||
tempDir: string
|
||||
}) {
|
||||
if (param.baseType !== 'function') {
|
||||
return await _defineNoFunctionParam(param, options);
|
||||
return await _getSchema(param, options);
|
||||
} else {
|
||||
const schemaMapping: INopeDescriptor = {
|
||||
type: 'function',
|
Loading…
Reference in New Issue
Block a user