Skip to content
This repository has been archived by the owner on Mar 21, 2021. It is now read-only.

add "external enum" capability in the JDL #465

Open
1 task done
62mkv opened this issue Apr 14, 2020 · 6 comments
Open
1 task done

add "external enum" capability in the JDL #465

62mkv opened this issue Apr 14, 2020 · 6 comments

Comments

@62mkv
Copy link

62mkv commented Apr 14, 2020

Overview of the feature request

Need to be able to "declare" an enum, (using JDL, actually, but I've been told it has to be supported by generator in the first place) that will NOT be generated by JHipster, but can be used in the entities, defined in JDL

Motivation for or Use Case

Nearly all of my enums in latest projects have been "extended" Java enums, where (most of the time a single String) value was attached to an enum element. For example:

public enum RequestType {
    PRINT_PARCEL_REQUEST("PrintParcelRequest"),
    DELETE_PARCEL_REQUEST("DeleteParcelRequest"),
    CLOSE_SHIPMENTS_REQUEST("CloseShipmentsRequest");
    private final String value;

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

    @JsonValue
    public String getValue() {
        return value;
    }
}

if not for that @JsonValue, that would be relatively straight-forward to generate (and I will create an issue for that as well) but I think being able to do something like

enum BatterySize external

entity Device {
  name String required
  batteryType BatterySize required
}
Related issues or PR

not sure if "related" but boils down to the same use-case: #357

  • Checking this box is mandatory (this is just to show you read everything)
@MathieuAA
Copy link
Member

A thing occurred to me. If it (the enum) already exists, you can do a JDL export and modify the exported JDL as a workaround. That way, no need for a keyword.

@62mkv
Copy link
Author

62mkv commented Apr 14, 2020

I will have to research what does it mean... (JDL export)

@62mkv
Copy link
Author

62mkv commented Apr 14, 2020

but in general, my suggestion does not assume that the enum "exists"; just that it will not be generated (but can be imported and used as a type name for entity fields). so, generated code will not compile until I provide the implementation, but at least I will immediately know where to put it and how it will be named

@MathieuAA
Copy link
Member

A JDL export basically means doing jhipster export-jdl in your JHipster application.
This feature is kinda impossible. It would mean bypassing validations, and build. I may be wrong, but it's a tough one.

@62mkv
Copy link
Author

62mkv commented Apr 14, 2020

ok, I've read about exportJdl it basically assumes having already generated JHipster app but without jdl file. I never generated a JHipster app without JDL file, so not sure what it could give me, but glad to know it exists.

by bypassing validations, you mean.. ? why would JHipster care what's in my enum?

@MathieuAA
Copy link
Member

You can always export to a JDL file, whether you've created your app from a JDL file is not taken into account.

by bypassing validations, you mean.. ? why would JHipster care what's in my enum?

I think I've jumped too quickly at conclusions here. There may be a way to implement that. It's a tough one.

@MathieuAA MathieuAA transferred this issue from jhipster/generator-jhipster May 16, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants