openhab-core icon indicating copy to clipboard operation
openhab-core copied to clipboard

[REST API] metadata value is not optional

Open spacemanspiff2007 opened this issue 5 years ago • 6 comments

Posting metadata config without a value entry always results in a 404 response. The data model however defines value as optional.

grafik

Example Body:

{
  "config": {
    "test": 1
  }
}

spacemanspiff2007 avatar Jul 02 '20 04:07 spacemanspiff2007

You are talking about this API ?

image

Where do you see the value as optional ?

I see that 400 should be returned if no valuye is provided:

image

Is it what's not working ?

lolodomo avatar Nov 28 '20 11:11 lolodomo

And it looks this is correctly checked:

https://github.com/openhab/openhab-core/blob/master/bundles/org.openhab.core.io.rest.core/src/main/java/org/openhab/core/io/rest/core/internal/item/ItemResource.java#L521

lolodomo avatar Nov 28 '20 11:11 lolodomo

In the screenshot I posted it shows value and config as optional

spacemanspiff2007 avatar Nov 28 '20 16:11 spacemanspiff2007

Where did you get that screenshot from? If value is reported as optional, that is the bug. What is the use-case of metadata without value?

J-N-K avatar May 14 '22 16:05 J-N-K

I think it was from OH2.X. Currently it looks like that

grafik

Isn't the config part optional?

spacemanspiff2007 avatar May 15 '22 04:05 spacemanspiff2007

Currently the Schema does not show optional/required values. The problem is (similar to other DTOs) that the MetadataDTO is part of the org.openhab.core bundle which is agnostic of the REST API.

Even if we added annotations, the code currently is not able to process these annotations, we would need to find a way to identify packages that contain DTOs (which are currently spread over a lot of bundles) and feed those to the Swagger Model.

J-N-K avatar May 15 '22 09:05 J-N-K