-
-
Notifications
You must be signed in to change notification settings - Fork 431
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
[REST] New REST APIs to generate DSL syntax for items and things #4569
base: main
Are you sure you want to change the base?
Conversation
521b446
to
2ce9669
Compare
Here is an example of result for things:
|
And the result for items:
|
cff0a29
to
c3d70dc
Compare
@kaikreuzer and @openhab/core-maintainers : for your information, the PR is now ready for review. |
Go back to draft as I discovered a bug. |
c3d70dc
to
6bc963f
Compare
Problem with items sorting is solved. So ready again. |
52ce3b9
to
506527b
Compare
Fair point - things should be easy for the user.
What is your idea about resolving ambiguities?
That would also work. If the body is empty ( I'm still not a hundred percent sold on that because I think making requests and posting data between endpoints is cheap and it's something that's not done very often. The benefit is that there is a clear flow of data and an arbitrary input always produces the same output. But if it's clear from the use of the endpoint that the item registry is getting accessed or that it's not getting accessed than I have no objections.
This was my idea at first, too. However I then thought about how things will documented e.g. in api explorer and as far as I know there is currently no way to document the input/output data structure based on the query parameter. (You just wrote your response while I was typing the second paragraph out so I just left everything in) Just a small suggestion: How about a sub-endpoint which returns the registry?
|
Would this allow us to get rid of the Combined with #4585, this would also open up an easier route to defining sitemaps in yaml, and switch between UI configuration, DSL and yaml in the UI. One challenge I potentially see is showing errors in the UI. For sitemaps, as the parsing is done in the UI code, it will show (to a degree, and not always perfect) where the error in the sitemap DSL is. If the whole translation is done in core, the API response should be able to indicate where the error is as well, to be able visualize it in the UI. It shouldn't just be a log entry. |
Too much complicated to achieve by a lambda user.
If the POST APIs are fully independent from our server registries, we have no conflicts to resolve. It is the role of the client to finally not request the creation of a new item/thing in the registry that already exists. I believe there is nothing new there.
That would be fine for me, Looks better than my proposal: |
Yes, that is what we are discussing in a RFC I recently opened and that I finally started to embed in that PR.
Yes, that was my intention to come to you in a second step to also consider sitemap. But I will do that in a next step and for that I would need first some explanations from you how it works today, what are the used APIs and how is triggered the code in
Yes, that is exactly my current intention started with items and things but that I can continue later with sitemaps.
That is an interesting point, in my current (basic) implementation, the API that parses the DSL syntax will return a 400 status code and the errors are logged. One thing I could do easily is to provide what we currently log as output of the API in case of invalid syntax, so that it can be displayed in UI. But I will not be able to be more clever and more precise than what currently provides the core framework in logs when the DSL file is parsed. |
I think the rest api users are only developers and even for large installations (>1k items) it's almost instant.
I fully agree 👍
That would be great. Would it then need to be logged at all? |
I think that’s a good start. We may then have to look at the errors generated by core at some point to refine the messages (e.g. the position of the error would always e useful if it can be found), but that’s a next step. Also the logs would benefit from improvements there. |
4c78817
to
8970628
Compare
Related to openhab#4509 Added REST APIs: - GET /file-format/existing/items to create file format for all existing items in registry - GET /file-format/existing/item/{itemname} to create file format for an existing item in registry - GET /file-format/existing/things to create file format for all existing things in registry - GET /file-format/existing/thing/{thingUID} to create file format for an existing thing in registry - GET /file-format/existing/thing-from-inbox/{thingUID} to create file format for an existing thing in discovey registry All these APIs have a boolean parameter named "hideDefaultParameters" to hide or show the configuration parameters having the default value. They are hidden by default. Signed-off-by: Laurent Garnier <[email protected]>
4c70810
to
9740ead
Compare
I was certainly too much ambitious when I decided to try also covering #4585 in this PR. As a consequence, the PR is smaller and ready for review. @kaikreuzer : that would be great if you could have a look. For #4585, another PR will be created based on this one. |
I don't know if I should or not keep the "language" parameter as it is not used by these APIs. |
I agree, not used at this time, so not needed. In the future, when we would support e.g. a YAML format format as well, we can still introduce it with a default value equal to I would be keen to try to create a proper documentation of the generated response, rather than just |
Language parameter is to provide a locale, not to select the output format. I will remove the language parameter. |
I will first check if it makes sense to get a localized version of a thing/item before generating DSL syntax. |
Oops, sorry, of course. I was mixing up things. |
...core/src/main/java/org/openhab/core/io/rest/core/internal/fileformat/FileFormatResource.java
Outdated
Show resolved
Hide resolved
If you are interested, the code to convert to YAML is working in the prototype I created, and could easily be integrated here. See https://github.com/mherwege/openhab-core/tree/yaml |
....core.model.item/src/org/openhab/core/model/item/internal/syntax/DslItemSyntaxConverter.java
Outdated
Show resolved
Hide resolved
This PR introduces nothing related to YAML. |
Signed-off-by: Laurent Garnier <[email protected]>
Signed-off-by: Laurent Garnier <[email protected]>
Signed-off-by: Laurent Garnier <[email protected]>
Related to #4509
Added REST APIs:
All these APIs have a boolean parameter named "hideDefaultParameters" to hide or show the configuration parameters having the default value. They are hidden by default.