Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support array of / many #7

Closed
ericsolberg opened this issue May 5, 2021 · 4 comments
Closed

Support array of / many #7

ericsolberg opened this issue May 5, 2021 · 4 comments

Comments

@ericsolberg
Copy link

This is an awesome tool, already very helpful to me!

I'm not sure if this is a bug (because it fails on valid CDS input) or just a feature that hasn't been implemented- I suspect the latter. But it would be nice to support array of / many constructs:

entity foo {
    bar1 : array of String;
    bar2 : many String;
}

Either of these result in:

Unable to write types. 
Error: Unable to parse element 'bar1' on entity 'captest.foo'. It seems to be a CDS expression without a type definition, please add a type to it.
@mrbandler
Copy link
Owner

Hi @ericsolberg, awesome to hear you like it, thank you for using it!

This looks like a part of the Abstract Syntax Tree (AST) that I missed on the initial implementation. I will check the compiler output and get back to you.

mrbandler added a commit that referenced this issue Jun 5, 2021
@mrbandler
Copy link
Owner

Hi @ericsolberg, sorry for the delay, just wanted to let you know I just released v2.6.1 which adds support for inline array type declarations inside entities and types.

Turns out it was part of the AST which I didn't consider while writing the CDS parser.

Your example:

entity foo {
    bar1 : array of String;
    bar2 : many String;
}

now compiles to:

export interface IFoo {
    bar1: string[];
    bar2: string[];
}

export enum Entity {
    Foo = "foo",
}

export enum SanitizedEntity {
    Foo = "Foo",
}

Additionally, I wanted to add (even though it might be too late now) that it would have been possible to use something like this:

type ArrayString : array of String;
type ManyString : many String;

entity foo {
    bar1 : ArrayString;
    bar2 : ManyString;
}

which would have compiled to this:

export type ArrayString = string[];
export type ManyString = string[];

export interface IFoo {
    bar1: ArrayString[];
    bar2: ManyString[];
}

export enum Entity {
    Foo = "foo",
}

export enum SanitizedEntity {
    Foo = "Foo",
}

@andrew-mai-laidon
Copy link

Is it possible to use array of for the input of the action, currently, this will return error:
Error: Cannot read property 'ref' of undefined
action createTemplate(template : Templates, templateSections : array of TemplateSections, templateSectionFields : array of TemplateSectionFields, templateCopied : String) returns CommonActionOutput;

@mrbandler
Copy link
Owner

mrbandler commented Jul 24, 2021

Hi @andrew-mai-laidon, I just created a new issue based on your comment.

This seems like another part of the AST that has seems to have slipped through the cracks. I will take a look tomorrow.

Any further communication will be in the newly created issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants