jhipster / generator-jhipster

JHipster is a development platform to quickly generate, develop, & deploy modern web applications & microservice architectures.
https://www.jhipster.tech
Apache License 2.0
21.54k stars 4.02k forks source link

Generating an invalid code from enum in JDL #22192

Closed vw98075 closed 1 year ago

vw98075 commented 1 year ago
Overview of the issue

In JDL,

enum Currency {
    USD("USD")   
}

The generated Java code will be

/**
 * The Currency enumeration.
 */
public enum Currency {
    USD;

    private final String value;

    Currency(String value) {
        this.value = value;
    }

    public String getValue() {
        return value;
    }
}

The code isn't valid.

Motivation for or Use Case
Reproduce the error
Related issues
Suggest a Fix
JHipster Version(s)

7.9.3

JHipster configuration
Entity configuration(s) entityName.json files generated in the .jhipster directory
Browsers and Operating System
hide212131 commented 1 year ago

It seems appropriate to change the current code so that an enum is deemed to not have a custom value when its key equals its value:

https://github.com/jhipster/generator-jhipster/blob/06faa52ac18d70a6201cb8c444c63c5760ee8dc3/generators/base-application/support/enum.mjs#L22-L24

If there's no disagreement, I plan to submit a Pull Request for this.