Hi @ramil Thanks for the reply
Yes, I’m fully aware of how it works. I already have the component running inside a Vaadin-based application. I made it confusing by mentioning open API, so you thought I was referring to rest operations. I was actually only referring to the model structure.
Let me try to rephrase.
I’m not using Vaadin itself, but jmix, a RAD platform for java applications (that internally uses Vaadin). They have a section on the integration of Javascript-based components.
Integrating JavaScript Library :: Jmix Documentation
I did this and effectively have the component working in my application. All is good here.
Now, I want to configure this component from within Java. I do this by creating a big Configuration class that reflects the Javascript configuration object.
This class will look familiar to you
public class GanttConfigDto {
Layout layout = Layout.builder().build();
Links links = Links.builder().build();
Types types = Types.builder().build();
boolean auto_types = false;
String duration_unit = "day";
boolean work_time = false;
boolean correct_work_time = false;
...
}
My first attempt at creating this class was by looking at Properties Gantt Docs and building that class by manually adding each property, one by one. This would mean a LOT of work.
In my second attempt, I opened the component without any modification. I dumped the structure using console.log(gantt.config) in the browser developer console. The result was a huge json. I then asked Copilot to reverse engineer this JSON and create java from it. This turned out to work pretty well. Wherever it sees a complex JSON object it created a class and added the properties.
This second approach is a huge timesaver. The java code I pasted above is the result. As you can see it created classes for Layout, Links, Types, …
But it is not ideal. Certain information is still missing.
E.g. in the Javascript Scales class https://docs.dhtmlx.com/gantt/api__gantt_scales_config.html
There is the unit field.
That JSON with the default values that I used only contains the default value “day”
There is no mention of the other values “minute”, “hour”, “week”, “quarter”, “month”, “year” so the assumption was made that it was a string.
So now I could yet again go over all the properties and manually change them.
The unit would become an enum instead of a string, and the enum values would become the different units.
So what I’m looking for is the contract of the component. A structured document that details the operations and properties. From this document I could generate code for all properties and operations.
It would not just help me. Because it is language agnostic you would be helping anyone that wants to integrate the component in any language.
I mentioned open API because that’s what I typically use between a javascript front-end and java back-end. A better example would have been https://json-schema.org/understanding-json-schema/about
ps. as a new user I am only allowed to have 2 links in my post, so I had to put some of the links as quotes