Defining Media Types for the textual representations #1495
Replies: 12 comments
-
As and end user I don't really have an opinion on this one. The proposal seems reasonable but I can't comment on the implications and it largely looks like it would not be something end users have to worry about. But it does sound like it would make new features possible in the UI which would be good, right? |
Beta Was this translation helpful? Give feedback.
-
Yeah, I wasn't sure where to file this since it seemed to be a project-wide decision. Nobody seems interested though... Still I used the above anyway until it's challenged and worked a bit on expanding the autocompletion to rules in openhab/openhab-webui#364 so it's easier to add modules to these UI-driven rules in code. |
Beta Was this translation helpful? Give feedback.
-
Hey, don't be disappointed so easily 😆 . As I had previously discussed the rule dsl media type, you know that I care! |
Beta Was this translation helpful? Give feedback.
-
I asked myself this very question, I figured it made sense to distinguish the objects themselves (a rule, an item, a thing...) with the syntax used to define them, but now I'm not so sure... and the fact that you brought it up too probably is a good hint that it doesn't. So to recap we'd have (after fixing the parameter syntax and adding the persistence which I forgot):
At some point I think it would also be useful to provide a way to or modify Things with a text editor in the UI. That would be handy to be able to copy-paste to create new similar things or duplicate channels, with autocompletion etc... The best of course would be to have a parser/stringifier for the .things syntax but I was wondering if YAML (and therefore application/vnd.openhab.thing+yaml) could also be an alternative... ? It would certainly be easier! |
Beta Was this translation helpful? Give feedback.
-
Definitely +1 for copy/paste/modify for Things. Especially with HTTP and MQTT binding having that capability would be really appreciated. From what I've been told, the modbus binding almost would require this. For now I recommend people to pull the JSON from the REST API, modify the JSON and resubmit the modified JSON using the REST API to duplicate similar Things and Rules. Alternatively modifying the JSONDB itself (with OH stopped of course). This is probably the biggest pain point causing users to use .things files over automatic discovery and manually created Things in the JSONDB. Personally I would put this capability relatively high on the list of priorities actually. |
Beta Was this translation helpful? Give feedback.
-
I saw your posts and that's part of the reason why I think it would be good to have something that could handle this better. With YAML as the thing description syntax it would be relatively easy to implement and provide a good added value, even if as a principle I'd prefer using the established description languages whenever possible - to try to keep the docs current with no changes if we can. The thing details page in the new UI was one of the first I designed for the first prototype almost 2 years ago and I'm already thinking about revisiting it, that is, merging the Info & Config tabs together and adding a new Code tab, similarly to many other pages throughout the UI where the last tab is always Code. |
Beta Was this translation helpful? Give feedback.
-
Hi @ghys , i have a probably silly question, but what endpoints would expose the available media types? Is this the |
Beta Was this translation helpful? Give feedback.
-
No silly question, currently the REST API mostly sets the "generic" JSON media type aka. |
Beta Was this translation helpful? Give feedback.
-
So i ask for ?type=json and the response content type in the HTTP header is |
Beta Was this translation helpful? Give feedback.
-
This is not about what the REST API can do, really, it's just a matter of identifying MIME types - now called media types - of the documents (as in sequences of bytes) that we can encounter and are related to openHAB, so when you see such a document, no matter what its source is (a file, or the output of an API) with "when... then... end" structures you can affix the |
Beta Was this translation helpful? Give feedback.
-
Now to actually answer your question :) theoretically if you would specify the |
Beta Was this translation helpful? Give feedback.
-
In case you missed it, I have squeezed that feature in time to have it the milestone release (openhab/openhab-webui#368) so people who start using OH3 with the upcoming release can test drive it. I didn't manage to add the ability to create new things from YAML, but you can edit existing things, their configuration and the (user-defined) channels in the new Code tab; the thing details page now behave quite similarly to the rule details page - you can save with Ctrl+S, disable/re-enable the thing with Ctrl+D, and so on. It doesn't seem to work too badly and hopefully should make the process of building generic MQTT or HTTP things a little less tedious. I have updated the table above with the new media type application/vnd.openhab.thing+yaml. |
Beta Was this translation helpful? Give feedback.
-
Hello @openhab/architecture-council!
With this I'm seeking a discussion and eventual decision on the subject of defining official (note: not "really" official as in IANA-registered... for now! rather "generally accepted") Media Types - formerly MIME types - for the textual representations of openHAB objects and entities.
The reason for this is mainly because my pet project of late (today, really) has been to explore adding some "hint" mechanism, aka. Intellisense or autocomplete, to some of the CodeMirror editors in the UI to aid in writing structures and code in these.
Example:
For now I'm focused on the pages/UI components YAML structures, but I'm eager to expand this - not necessarily myself btw, perhaps others could contribute...? - to all types of "code" we can edit in the UI: rule YAML representations, things, items... but to do this we need to identify exactly what we're talking about, hence the expansion of media types.
Following discussions with @kaikreuzer we have already informally defined the
application/vnd.openhab.dsl.rule
media type for the rule DSL - it's recognized by the rule engine as a language for the "run a script" actions and conditions.I'd like to propose expanding this to for instance (here's where I seek your approval):
application/vnd.openhab.items-definition
- for textually defined items (multiple, as in a text file with several of them)application/vnd.openhab.things-definition
- for textually defined things (ditto)application/vnd.openhab.sitemap-definition
- for a (singular) textually defined sitemapNow as you may have noticed, the OH3 UI offers a YAML representation of a rule in the new rule engine:
For these I think a suffix is necessary because it's in essence an object representation which could be serialized using any syntax. For instance these rules could be stored in JSON format in the JSON DB or represented in YAML in the UI. While
+json
is officially recognized in the IANA's Structured Syntax Suffix Registry (and RFC 6839),+yaml
is not, although it seems to be commonly adopted. I propose to adopt it anyway.If we were to define the
application/vnd.openhab.rule-definition
media type for the structured definition of a rule, the YAML representation of it would therefore be:In the same manner, "UI components" (simple hierarchical structures mostly comprising a type, configuration and "slots") are stored as JSON and represented as YAML, however the nature of their "root components" could help identifying some context, for that I suggest we use parameters to the media type to give these indications. I don't want to overwhelm you with specifics, but we could have different types of pages as root components (
layout-page
,chart-page
,widget
), their media types might therefore look like this:What do you think? Looking forward to your feedback!
Beta Was this translation helpful? Give feedback.
All reactions