-
-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Enriching the JDL grammar #6275
Comments
I like your ideas, but some depend on the fact that we generate code some special way. If we were to change the code (because some new way would be better than some former way of doing something), we'd have to change the grammar, and that's a direct dependency... Except this problem, I like the idea of extending the JDL. After all, it can already be used to generate entities and applications. Looks like VagabondUML is not actively maintained anymore, too bad =( |
👍 I really like the idea to make the jdl more powerful. Especially the idea to be able to provide some more hints to an entity as I was asked multiple times already how to get audit functions. |
@agoncal thanks for bringing that into discussion and letting me know about that. I agree that JDL is a lot more powerful than CLI and I am a fan of "persisted textual representations of domain models". ;-) vagabond-uml has started about a year ago to put some ideas about making JDL more flexible. It was not updated since then due to the lack of interest from the community. At that time we have exchanged some emails with @MathieuAA and that was it. I'd love to see where the discussion here will bring us and I am open to contribute. :-) |
@jhipster/developers let me share my thoughts. I had some discussion with @agoncal regarding this and I believe I had some exchanges with @MathieuAA on similar things in the past. These are my personal opinions.
@MathieuAA what is the status of supporting app generation from JDL, I believe you were working on that I also wish that at some point in future JHipster becomes an intelligent platform where you could craft entire applications or microservice stack using JDL, something like
|
Imagine how magical it would be to have an entire microservice stack generated from one command with the JDL above 😎 |
@deepu105 the app generation is done (minus some probable minor changes I might make before releasing). About the first version, documentation is on its way.
Of course Deepu, the point is to be able to quickly generate microservice apps (gateway included). |
@MathieuAA what is the syntax that you have now?
so that segrgation is easier and and it is easier to read as well. WDYT? |
@MathieuAA also I think its very important that we all agree on the syntax/grammar before releasing this else it will become difficult to change later so lets discuss and get concurrence from the core team first here before we release version1 as its a big step |
@deepu105 I like the "new" syntax that you are proposing: one single file to generate an entire app (this new syntax could be an excuse to get a JHipster 5.0 ;o). ATM when I need to add new attributes on an entity, I always try to keep my JDL up to date. So for me, it feel redundant to have the entity descriptors (under But I have to say, even if I don't use the CLI anymore, it is a nice way for new comers to get into JHipster quickly. Maybe the CLI could stay displaying a little warning "Use the JDL syntax to get the most of JHipster", or something like that ;o) |
I had a more "split" syntax in mind, so that moving entities to and fro apps (or adding and removing) wouldn't change the app declaration or the entity declaration (for instance one could declare entities in one file, and apps in another). one
or
|
@MathieuAA while your syntax is perfect for power users it might not be very friendly to beginners and people who look at a JDL for the first time as you have to mentally map entities to apps. Where as grouping them in app makes user experience much better and very easy to read and understand the model. IMO It would be very nice if we can support both what I suggested and one of the option you suggested without much overhead. Lets see what others think about it |
@deepu105 Yeah, let's do both. |
In microservice architectures, you tend to see the same entity name, but with different meaning. So, for example, let's say we have twice the entity
If we can use both syntaxes, we would need to differentiate them. Either fully qualifying the name
Or using aliases (
|
Fully qualifying is a good idea. |
I like the idea of generating entire microservice stack based on JDL without CLI interaction. What about other JDL syntax changes and backwards compatibility? Is it a better idea to push other proposed changes like service, repository, and (env)variables and still keep it compatible with the current JDL syntax or skip the overhead and keep it simple? |
Implementing new things like that isn't an issue for me. As @agoncal and I talked about last time we met, it's more about making it possible in the generator. |
And what about the best of both worlds. We could use singular to mark an artifact (eg. Is something like that readable:
|
That'd be a very understandable convention! |
If the "new" JDL is meant to bootstrap any kind of application, we could have things like that. Bootstraping a Monolith
Bootstraping a more complex microservice application
KeywordsBasically, we would have a bunch of keywords related to the architecture we want:
And other keywords related to the content of each app:
|
It may be too complicated:
looks pretty good to me. Having the singular & plural forms for "entity" or "service" is an awesome idea. For me, an application is an application and can either be a microservice, a monolith or whatever. I don't see it as root. And I don't like the idea of mixing the
To sum it all up, for me:
A few other things:
|
Defining several micro-services in a unique file feels like distibuting a monolith to me... IMO there should be only one app per JDL. |
@cbornet I think it's important to define "what is an application" ? Today, even the smallest project needs several blocks. These blocks are microservices, of course, but also one or two gateways, a registry, console, admin, log.... All these blocks will form one application (or let's call it product). If you have:
You could end up with the following structure:
But you would also have the choice to create one product per application:
And you will end up with a different structure (no parent pom, different groupid...):
You could then have both choices. |
Well, to me, microservices should have independant lifecycle, ownership, etc... So binding them in a JDL file is against the philosophy. |
@cbornet For a single product, you could just have one microservice and one gateway (therefore, a registry). That's a valid application that needs 3 different blocks. BTW, when I mentioned the previous structure, I didn't see any inheritance, or binding between the application (therefore, no lifecycle dependency). In terms of pom.xml (let's stick with Maven for now), you'll have:
|
You have dependency at the JDL level. If there are multiple teams, who is owner of the JDL ? |
Nice ideas @agoncal buts lets not complicate things too much
It is redundant but good for readability as you can easily separate the application configuration from other stuff like entities, entity options(pagination, service ..) etc.
Not very sure about this. using the application keyword gives as the flexibility to add an applicationType field in the config and decide what it is. I also don't like idea of nesting applications inside another application as @cbornet highlighted for microservices this feels against the whole theory. I would prefer 1 file per service and common stuff in another file So wrapping up my personal favorite syntax would be (stealing some ideas from @agoncal and @MathieuAA ) commonConfig.jdl
myMicroservice1JDLFile.jdl
myGateway.jdl
This will generate
@MathieuAA take a look at http://zaa.ch/jison/ its suppose to be easy to use as well, but not sure if its better than PegJS(it's apparently used for Coffescript). Also found few other options here https://sap.github.io/chevrotain/performance/ |
Hello @MathieuAA @deepu105 & everyone else. I'm the main author of the benchmark linked above: And of the Chevrotain parsing library.
Questions:
Additional Resource on Parsing Libraries in JavaScript:On building Parsers by hand.Most programing languages are built without Parser Generators or Combinators.
This is usually due to the need From what I understand JDL is not a programing language, but a Definition Language Why would a Parser Library author recommend against using parsing libraries?Firstly it always depends on the specific use case. |
@deepu105 Yes, this syntax is really good. Let's freeze it for now to know where we're heading. I'll have a look at everything you guys have linked to the previous posts. @bd82 hello there! PegJS doesn't support Regexes, the generated parser is ugly (I think the parser is generated from a template, which is itself kinda ugly and never cleaned up after the generation process is over) and we (Carl and I, two years ago or so) have encountered some cases where we had to ask ourselves "Ok, we know how to do it using XXX, how the hell do we do that now?". I have to have a look at various tools to make my mind. Finally, we have to redefine what is an application. I say redefine because (warning: I'll be using the "thing" word a lot):
So.... importing a JDL that creates an app structure isn't that crazy an idea, we just have to define a convention of usability and readability, -> define a good, clean way of doing things.
I agree with @cbornet on this point, but users are free to do whatever they want and if they want to define everything they have in a single file (as ugly as it is) they are free to do it. We could have warnings to tell users why this is not considered a good practice and what they should do instead. |
From my understanding this is exactly what is done (sorry I'm not the developer of jhipster-ide and know very little about parsers...). Note that the IDE project is a work in progress (works only for Eclipse & VSCode) but it's really cool and definitely integration between the JDL and editors is a goal of the project. |
For JDL studio I provide auto-complete support by adding a custom script. Syntax errors are reported by using the same pegJS parser used by the Jhipster core |
@bd82 writing our own parser sounds like a good idea given that it is much more flexible. @MathieuAA what do you think about that and about Chevrotain parsing library? |
So this means you can only report the first syntax error? because pegjs stops on the first error Try the Chevrotain Playground and select different "samples" in the input pane while examining the output pane to see how multiple syntax errors
Could you link to the custom script please? Next questions:
|
|
I'm locking this thread as I've created the related issue in JHipster Core |
@jdubois do let us know what you think as wellm |
Thanks @deepu105 - I didn't have a look at all, and I won't be able to do it this week (I'm in New York, meeting lots of JHipster users!). But I trust all of you on this: just go on, and I'll have a look when I have more time. |
Overview of the issue
The idea of this ticket is to brainstorm about a possible enrichment of the JDL grammar.
Motivation for or Use Case
ATM the JDL syntax is mostly used to describe all the entities and their relationships. Having a richer JDL would give many extra code generation possibilities (repositories, services...). On the other hand, it would be the start of having JDL and CLI shifting apart : the CLI can't ask hundreds of questions to be as rich as the JDL.
So if we agree that CLI can't support 100% of JDL, what new features could we have in the JDL ? Let me start with a few ideas, you can then give some feedback and also give your new ideas.
Entity
Entities are already pretty rich, but we can go further.
Versionning
In some cases it's useful to have
@Version
for optimistic locking. We could use thewith
keyword :Adding
with version
would generate a@Version
attribute in the entity :Auditing
JHipster already has an
AbstractAuditingEntity
allowing auditing on entities. It would just be a matter of having a newwith audit
keyword :The
with audit
would generate the following code (and of course, the Liquibase changelog) :Uniqueness
Today we have several validations on our attributes (
required
,minlength
,maxlength
,pattern
). We could haveunique
.This would generate a
@Column(unique = true)
as well as a Liquibase constraint :List of datatypes
It's sometimes useful to map a list of datatypes (String, Integer...). We could introduce the
List<>
syntax, such as :Embeddable
Embeddables are important mapping objects. We should be able to declare them and embed them on entities (lists of embeddables are also possible) :
Repositories
Today there is no JDL for repositories. This could be quite useful to add extra query methods. When we have a
Customer
entity, we automatically generate an emptyCustomer
repository. With the newrepository
JDL keyword, we could add extra queries :And off-course, have these query methods generated in the service and REST controller too.
Services
Services are where we find the business code, so it's difficult to generate a lot of code. One thing could be extending from a custom service (therefore adding the
extends
keyword). For example :Of course, depending on what does
MyOwnService
some tests might break.REST Controllers
Again, REST resources can handle complex code, so I don't see a lot of customization here. Extending from another resource maybe (not sure it's really useful) ?
A bunch of variables
Today we can set the JHI_PREFIX in JDL, but it would be good to be able to set others. Just as an example, I find my self always changing the title of website (which is by default the name of the project). This title is mostly in the i18n files (
"global": {"title": "myproject")
) that I regenerate and need to rechange. Having access to a few variables would solve the problemYour thoughts ?
Related issues
The text was updated successfully, but these errors were encountered: