-
-
Notifications
You must be signed in to change notification settings - Fork 432
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
[WIP][REST] New API to transform to/from DSL file format (items & things) #4630
base: main
Are you sure you want to change the base?
Conversation
This PR is not yet ready for review because not yet finished. I consider it finished at around 75%. |
18df1df
to
41f606c
Compare
f4e1437
to
70b9979
Compare
It seems you decided to use the following naming schema:
I think this is very good and I like it very much. However for |
/file-format/items is IMHO obvious that we are talking about file format for items. /file-format/items-file is redundant IMHO.. But if an official reviewer thinks your suggestion is better than mine, I will then change. |
But
|
I don't want to steer this discussion too much and I would be fine with any conclusion on this, but here is another alternative that could be considered:
As the 'what' is already in the MIME type (e.g. |
For parse the input is always a string and the output schema could be set according to the MIME type (thank you @mherwege for showing that that's possible). That would also be fine with me. |
For output, as type is Response, there to s no problem to return any DTO object inside the Response. |
@mherwege : the day we have a YAML file format, media type will be application/yaml. This is not sufficient for the parse API to know if it should return a ItemXXXDTO or ThingXXXDTO.. Not sufficient to specify what kind of information you are requesting. |
Or you imagine to rather define text/vnd.openhab.yaml.item and text/vnd.openhab.yaml.thing ? |
I think it's important to differentiate between the existing ui yaml files and a possible new yaml format. |
There is no plan to create 2 different YAML formats. |
No, this never was my intention. Please re-read the pointed issue you apparently missed the general intention. My intention is to show DSL and new YAML file formats in Main UI code tab. Management of YAML would be moved from Main UI to core. Main UI would just call API to create/parse YAML. |
The UI YAML will disappear in my solution and be replaced by any file format. |
Then that was a misunderstanding. I thought additionaly to the new yaml file the plan is to provide a parse function for the existing ui yamls so the forum examples will still work. The new yaml format can contain both items and things at the same time. |
Because UI need is to work either on item or thing, depending on the configuration WEB page. One time again, we start discuss YAML in a PR which is not about YAML. Why not having this discussion rather in the issue itself? |
Because the way the format looks has implications and obviously we're not on the same page how the format looks. So please let's have this discussion (not here) otherwise it will be an endless source of confusion |
That was my thinking, but I am fine either way. You could then also have For multiple types of objects content, if you want some analogies in the UI, we currently support working with this on multiple levels in the UI in a few places:
I would not get stuck on the exact format in the UI. That is a later concern. For now, I fully agree with @lolodomo that the first target should be making DSL import work without the parser code in the UI, just by calling a REST endpoint.
I believe you can define multiple possible input MIME types as well in the
|
In you example, the type is the same in both cases, MyData. |
You can achieve that with something like this:
|
For create API, content type will be only JSON and output will accept text/vnd.openhab.dsl.item and text/vnd.openhab.dsl.thing. |
a3d16f8
to
351a1e7
Compare
351a1e7
to
561dc0b
Compare
cb4bcc8
to
0bd3331
Compare
Related to openhab#4585 POST /file-format/parse to parse file format POST /file-format/create to create file format Signed-off-by: Laurent Garnier <[email protected]>
0bd3331
to
7b6218b
Compare
Hi @mherwege , I defined this DTO object:
but I was asking myself if it would be easier for Main UI to have channel links and metadata directly inside each item, rather than having them all grouped and separated ? |
@mherwege : I also defined this class used as return type for the parse API:
DSL parsers have two levels or errors, critical errors and warnings. Any critical error will reject the object loading, while warnings will not. Regarding our parse API, any critical error detected by the DSL parser will lead to the API returning status code 400 with the errors as a message in the output. |
It is now ready for things I believe. |
Yes, I think that’s a good solution in general. Can we get the line number and line position of the error(s) or warning(s) with this? That could allow the UI to point to the problem, as it does now. I don’t know if the DSL parser in core provides that info, or just strings for the errors and warnings. |
I have not gone through all UI code yet on this. It might be slightly more efficient if it is provided inside the item, but overall I don’t see a big issue in any case. The argument pro including it is that the REST endpoint for items also includes it I believe. |
For the errors, yes you have line and column. See in the current code: |
Yes - that's why I'd put it there, too.
That would require to return a json: {
"file": "FileText",
"warnings": ["SomeWarningDto"]
} I'm not really sure it it's a valid use case. |
We are talking about the other way. |
Related to #4585
POST /file-format/parse to parse file format
POST /file-format/create to create file format