Skip to content

[BUG] Association key not correctly typed when String with asserted enum range #518

@MarvinWeitz

Description

@MarvinWeitz

Is there an existing issue for this?

  • I have searched the existing issues

Nature of Your Project

TypeScript

Current Behavior

When having an entity that has a key of type String @assert.range enum { ... }

entity BookIDs {
  key ID : String @assert.range enum {
        ID1;
        ID2;
      };
}

and this entity is used in an Association of another entity

entity Books {
  key ID    : Association to BookIDs;
      title : String;
      stock : Integer;
}

which in tern is used in a service

service CatalogService {
    @readonly
    entity Books as projection on my.Books;
}

the generated types break, as the association key of Books in the service definition uses the custom type of BookID_ID which is neither defined locally nor imported from the entity ts file.

Expected Behavior

The type is either imported or generated in file.

Steps To Reproduce

  1. cds init
  2. cds add typescript
  3. npm i
  4. Create entities as above (or see repo below)
  5. Look at @cds-models/CatalogService/index.ts

Environment

- **OS**: Debian GNU/Linux 12 (bookworm)
- **Node**: v20.18.1
- **npm**: 11.1.0
- **cds-typer**: 0.33.1
- **cds**: 8.8.3

Repository Containing a Minimal Reproducible Example

https://github.com/MarvinWeitz/cds-typer-service-enum-bug

Anything else?

I guess the problem will come with any specially typed key used this way, I just encountered it with enum asserted strings.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingkeepaliveWill not be closed by Stale botnew

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions