From 2059ee3a8a0808427b56f0d2ec57d940055aa36d Mon Sep 17 00:00:00 2001 From: Martin Karkowski Date: Wed, 11 Nov 2020 17:06:54 +0100 Subject: [PATCH] Rename file --- ...yseFunction.ts => getSchemaForFunction.ts} | 41 +++++++++++-------- 1 file changed, 23 insertions(+), 18 deletions(-) rename lib/analyzers/typescript/{analyseFunction.ts => getSchemaForFunction.ts} (76%) diff --git a/lib/analyzers/typescript/analyseFunction.ts b/lib/analyzers/typescript/getSchemaForFunction.ts similarity index 76% rename from lib/analyzers/typescript/analyseFunction.ts rename to lib/analyzers/typescript/getSchemaForFunction.ts index c6d4712..15c09a7 100644 --- a/lib/analyzers/typescript/analyseFunction.ts +++ b/lib/analyzers/typescript/getSchemaForFunction.ts @@ -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',