cds2types icon indicating copy to clipboard operation
cds2types copied to clipboard

[PROPOSAL] for interface name created for anonymous composition

Open mocotrah opened this issue 3 years ago • 2 comments

Given the following example:

entity Gathering {
  key id : String;
  employee :  Composition of {
                name : String
              };
}
entity Company {
  key id : String;
  companyName: String;
  employee :  Composition of {
                serialNumber : String;
                pointModel : String;
              };
}

after cds2types compilation, we'll find ourselves with 2 IEmployee interfaces

export interface IEmployee {
    up_?: IGathering;
    up__id?: string;
    name: string;
  }

  export interface IEmployee {
    up_?: ICompany;
    up__id?: string;
    serialNumber: string;
    pointModel: string;
  }

in the same namespace. This will produce typescript compilation errors later.

Proposal When generating the interface names for anonymous inline compositions, inject the entity name inside. Example: ICompanyEmployee IGatheringEmployee

Proposal extension: use the same approach for anonymous inline type definitions

Example:

type OpeningTime {
  twentyFourBySeven   :      Boolean;
  regularHour        :  {
      begin   : String;
      end     : String;
      weekday : Integer;
    };
}

will produce:

export interface IOpeningTimeRegularHour {
    begin: string;
    end: string;
    weekday: number;
  }
export interface IOpeningTime {
    twentyFourBySeven: boolean;
    regularHours: IOpeningTimeRegularHour;
  }

Today, the cds2types rejects with an error, and force the developer to declare the inline type declaration as a separate type.

mocotrah avatar Jan 03 '22 17:01 mocotrah

Hi @mocotrah

Thanks for the proposal. We will add this to our list, but we can't give any details by when and if we will implement this feature.

Regards Simon

HeneryHawk avatar Jan 04 '22 20:01 HeneryHawk

Thanks for accepting the proposal. I hope the proposal is correct, I'm new to CDS world... I have encountered the issue in my current project where we have a big data model and sometimes the interfaces are created with the same name.

mocotrah avatar Jan 12 '22 17:01 mocotrah