cap-js / cds-typer

CDS type generator for JavaScript
Apache License 2.0
25 stars 8 forks source link

[BUG] Singular name is derived, although a @singular annotation is present #251

Open chuckberrry opened 1 month ago

chuckberrry commented 1 month ago

Is there an existing issue for this?

Nature of Your Project

TypeScript

Current Behavior

When I try to enter the singular and plural names as described in the documentation, I get the error message that the derived singular already exists. [ERROR] Derived singular 'SalesDelivery' for your entity 'my.bookshop.SalesDelivery', already exists. The resulting types will be erronous. Consider using '@singular:'/ '@plural:' annotations in your model or move the offending declarations into different namespaces to resolve this collision.

Expected Behavior

The name of the singular entity should be taken from the @singular annotation and not derived.

Steps To Reproduce

@singular: 'SalesDelivery'
@plural  : 'SalesDeliveries'
entity SalesDelivery {
    deliveryNumber : String(10);
}

Environment

| @cap-js/cds-typer      | 0.21.0                                                                  |
| @cap-js/cds-types      | 0.2.0                                                                   |
| @cap-js/sqlite         | 1.7.1                                                                   |
| @sap/cds               | 7.9.2                                                                   |
| @sap/cds-compiler      | 4.9.4                                                                   |
| @sap/cds-dk (global)   | 7.9.2                                                                   |
| @sap/cds-fiori         | 1.2.3                                                                   |
| @sap/cds-foss          | 5.0.0                                                                   |
| @sap/cds-mtxs          | 1.18.0                                                                  |
| @sap/eslint-plugin-cds | 3.0.3                                                                   |
| Node.js                | v18.18.0

Repository Containing a Minimal Reproducible Example

No response

Anything else?

No response

daogrady commented 1 month ago

Hi Armin,

thanks for this report and for providing a minimal model! I was not able to reproduce the issue with the model you provided. Do you maybe have another entity called SalesDelivery which falls into the same namespace? Could you also please point out why you are explicitly setting the singular for this entity, given that it is the same as its regular name?

Best, Daniel

chuckberrry commented 1 month ago

Hi Daniel,

No, there is no other entity called SalesDelivery. You can also use the tiny cap example and change the entity "Books" as follows:

@singular: 'Book'
@plural  : 'Books'
entity Book : managed {
    key ID    : Integer;
        title : localized String(111) @mandatory;
        descr : localized String(1111);
        stock : Integer;

}

We are in the process of introducing cds-typer into existing CAP projects where the naming convention for entities is singular. Simply setting the @plural annotation to entity "Book" does not seem to be enough, because I get the same error message that the singular could not be derived. For this reason, I have also added the singular annotation.

best regards, Armin

daogrady commented 1 month ago

Hi Armin,

this is really curious, as I can not reproduce the described behaviour with the second model either. Could you please put this minimal model into a separate foo.cds file, then run cds-typer foo.cds to make sure it is run in isolation. Then if the error persists, check the output of cds-typer --version to make sure there is no old version of cds-typer at play beside the one you have in your project.

Best, Daniel

chuckberrry commented 1 month ago

I was able to reproduce this with the following foo.cds:

namespace my.bookshop;

@singular: 'Book'
@plural  : 'Books'
entity Book {
    key ID    : Integer;
        title : localized String(111) @mandatory;
        descr : localized String(1111);
        stock : Integer;
}

and cds-typer version 0.21.1.

Interestingly, this error was only reproducible with a defined namespace.

best regards, Armin

daogrady commented 4 weeks ago

Hi Armin,

thanks for putting in the work to track down the exact circumstances in which the bug occurs! I can now reproduce the issue and will look into asap.

Best, Daniel