From 113259e6dbeae72624ddae42a1c575ce95d5361d Mon Sep 17 00:00:00 2001 From: Simon Gaudek Date: Tue, 31 Aug 2021 10:34:37 +0200 Subject: [PATCH] fix(parser): Fix parsing of array of #9 The parser has been enhanced based on Issue #9 so that it also works with array of definitions and resolves them correctly. --- src/cds.parser.ts | 17 +++++++++++++---- src/types/action.func.ts | 21 +++++++++++++++++---- src/utils/cds.types.ts | 6 +++++- src/utils/types.ts | 2 +- 4 files changed, 36 insertions(+), 10 deletions(-) diff --git a/src/cds.parser.ts b/src/cds.parser.ts index 6110e49..c32741d 100644 --- a/src/cds.parser.ts +++ b/src/cds.parser.ts @@ -43,7 +43,7 @@ import { ITypeAliasDefinition, } from "./utils/types"; -import _, { isElement } from "lodash"; +import _ from "lodash"; /** * Parses a compiled CDS JSON object. @@ -384,12 +384,21 @@ export class CDSParser { */ private parseParams( definition: ICsnActionDefinition | ICsnFunctionDefinition - ): Map { - const result: Map = new Map(); + ): Map { + const result: Map = new Map< + string, + ICsnParam | ITypeAliasDefinition + >(); if (definition.params) { for (const key in definition.params) { - if (definition.params.hasOwnProperty(key)) { + if (definition.params[key].items !== undefined) { + const value = this.parseArrayTypeAliasDef( + key, + definition.params[key] + ); + result.set(key, value); + } else if (definition.params.hasOwnProperty(key)) { const value = definition.params[key]; result.set(key, value as ICsnParam); } diff --git a/src/types/action.func.ts b/src/types/action.func.ts index ad64d7c..c99a0ca 100644 --- a/src/types/action.func.ts +++ b/src/types/action.func.ts @@ -1,10 +1,13 @@ import * as morph from "ts-morph"; -import { ICsnTypeRef, Kind, isTypeRef } from "../utils/cds.types"; +import { ICsnTypeRef, Kind, isTypeRef, Cardinality } from "../utils/cds.types"; import { BaseType } from "./base.type"; import { Entity } from "./entity"; -import { IActionFunctionDefinition } from "../utils/types"; +import { + IActionFunctionDefinition, + ITypeAliasDefinition, +} from "../utils/types"; /** * Action/Function toType return type. @@ -172,7 +175,7 @@ export class ActionFunction extends BaseType t.Name === typeRef.ref[0]); @@ -189,9 +192,19 @@ export class ActionFunction extends BaseType; + params?: Map; returns?: IActionFunctionReturns; }