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

TypeScript codegen is broken with a model containing enum or scalar #95

Open
dselman opened this issue Mar 15, 2023 · 2 comments
Open

Comments

@dselman
Copy link
Contributor

dselman commented Mar 15, 2023

Bug Report 🐛

Invalid TS code is generated from this model. Looks like the logic to generate unions doesn't take into account scalars or enums.

namespace [email protected]

concept Address {
    o String street
    o String city
    o String zip
}

concept Order {
    o String sku
    o Integer amount
}

concept LoyaltyStatus {
    o String level
}

enum Color {
    o RED
    o GREEN
    o BLUE
    o PINK
    o BLACK
    o WHITE
}

concept Preferences {
    o Color[] favoriteColors optional
}

@template
concept TemplateData {
    o String firstName
    o String lastName
    o String[] middleNames
    o Boolean active
    o DateTime lastVisit
    o Address address
    o Order[] orders
    o LoyaltyStatus loyaltyStatus optional
    o Preferences preferences
}

Expected Behavior

Generates code that compiles.

Current Behavior

Code doesn't compile because a union is created containing IColor, even though Color is an enum.

Possible Solution

Steps to Reproduce

Context (Environment)

Desktop

  • OS: [e.g. macOS]
  • Browser: [e.g. Chrome, Safari]
  • Version: [e.g. 0.22.15]

Detailed Description

Possible Implementation

@sanketshevkar
Copy link
Member

Hi @dselman
I've done some basic investigation and found out that, enum is a subclass under the class declaration Concept. Which shouldn't be the case right?
In the case of scalar, it is treated as a field, but there is no check in place to generate a specific code for it.
What would be the expected output for the input above?

@mttrbrts mttrbrts transferred this issue from accordproject/concerto Feb 27, 2024
@Mamatha1718
Copy link

Mamatha1718 commented Dec 26, 2024

Hi @dselman
I Would like to tackle this issue :The generated TypeScript code incorrectly treats the Color enum as a concept, leading to the inclusion of IColor in unions. Since Color is defined as an enum in the model, it should not be mapped to an interface (IColor) but rather as a TypeScript enum or a string literal union.
This is solved by using String Literal union.
will you please let me know, any other changes are required. And where i can start to solve this issue.

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

No branches or pull requests

3 participants