Help OpenAPI to infer EnrichedThingDTO model channels type as a list of EnrichedChannelDTOs (#2487)

Fixes #2461

Signed-off-by: Wouter Born <github@maindrain.net>
pull/2489/head
Wouter Born 2021-09-15 22:30:52 +02:00 committed by GitHub
parent 75bddf4143
commit 14bbbb6a92
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 60 additions and 20 deletions

View File

@ -15,7 +15,7 @@ package org.openhab.core.io.rest.core.thing;
import java.util.List;
import org.openhab.core.thing.ThingStatusInfo;
import org.openhab.core.thing.dto.ChannelDTO;
import org.openhab.core.thing.dto.AbstractThingDTO;
import org.openhab.core.thing.dto.ThingDTO;
import org.openhab.core.thing.firmware.dto.FirmwareStatusDTO;
@ -25,9 +25,11 @@ import org.openhab.core.thing.firmware.dto.FirmwareStatusDTO;
* @author Dennis Nobel - Initial contribution
* @author Kai Kreuzer - Removed links and items
* @author Chris Jackson - Added 'editable' flag
* @author Wouter Born - Let (Enriched)ThingDTO extend AbstractThingDTO so both can define their own "channels" type
*/
public class EnrichedThingDTO extends ThingDTO {
public class EnrichedThingDTO extends AbstractThingDTO {
public List<EnrichedChannelDTO> channels;
public ThingStatusInfo statusInfo;
public final FirmwareStatusDTO firmwareStatus;
public boolean editable;
@ -41,10 +43,11 @@ public class EnrichedThingDTO extends ThingDTO {
* @param firmwareStatus {@link FirmwareStatusDTO} for this thing
* @param editable true if this thing can be edited
*/
EnrichedThingDTO(ThingDTO thingDTO, List<ChannelDTO> channels, ThingStatusInfo statusInfo,
EnrichedThingDTO(ThingDTO thingDTO, List<EnrichedChannelDTO> channels, ThingStatusInfo statusInfo,
FirmwareStatusDTO firmwareStatus, boolean editable) {
super(thingDTO.thingTypeUID, thingDTO.UID, thingDTO.label, thingDTO.bridgeUID, channels, thingDTO.configuration,
super(thingDTO.thingTypeUID, thingDTO.UID, thingDTO.label, thingDTO.bridgeUID, thingDTO.configuration,
thingDTO.properties, thingDTO.location);
this.channels = channels;
this.statusInfo = statusInfo;
this.firmwareStatus = firmwareStatus;
this.editable = editable;

View File

@ -47,7 +47,7 @@ public class EnrichedThingDTOMapper extends ThingDTOMapper {
Map<String, Set<String>> linkedItemsMap, boolean editable) {
ThingDTO thingDTO = ThingDTOMapper.map(thing);
List<ChannelDTO> channels = new ArrayList<>();
List<EnrichedChannelDTO> channels = new ArrayList<>();
for (ChannelDTO channel : thingDTO.channels) {
Set<String> linkedItems = linkedItemsMap != null ? linkedItemsMap.get(channel.id) : Collections.emptySet();
channels.add(new EnrichedChannelDTO(channel, linkedItems));

View File

@ -0,0 +1,49 @@
/**
* Copyright (c) 2010-2021 Contributors to the openHAB project
*
* See the NOTICE file(s) distributed with this work for additional
* information.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.core.thing.dto;
import java.util.Map;
/**
* This is a data transfer object that is used to serialize things.
*
* @author Dennis Nobel - Initial contribution
* @author Thomas Höfer - Added thing and thing type properties
* @author Stefan Bußweiler - Added new thing status handling
* @author Simon Kaufmann - Added label
* @author Wouter Born - Let (Enriched)ThingDTO extend AbstractThingDTO so both can define their own "channels" type
*/
public abstract class AbstractThingDTO {
public String label;
public String bridgeUID;
public Map<String, Object> configuration;
public Map<String, String> properties;
public String UID;
public String thingTypeUID;
public String location;
public AbstractThingDTO() {
}
protected AbstractThingDTO(String thingTypeUID, String UID, String label, String bridgeUID,
Map<String, Object> configuration, Map<String, String> properties, String location) {
this.thingTypeUID = thingTypeUID;
this.UID = UID;
this.label = label;
this.bridgeUID = bridgeUID;
this.configuration = configuration;
this.properties = properties;
this.location = location;
}
}

View File

@ -22,30 +22,18 @@ import java.util.Map;
* @author Thomas Höfer - Added thing and thing type properties
* @author Stefan Bußweiler - Added new thing status handling
* @author Simon Kaufmann - Added label
* @author Wouter Born - Let (Enriched)ThingDTO extend AbstractThingDTO so both can define their own "channels" type
*/
public class ThingDTO {
public class ThingDTO extends AbstractThingDTO {
public String label;
public String bridgeUID;
public Map<String, Object> configuration;
public Map<String, String> properties;
public String UID;
public String thingTypeUID;
public List<ChannelDTO> channels;
public String location;
public ThingDTO() {
}
protected ThingDTO(String thingTypeUID, String UID, String label, String bridgeUID, List<ChannelDTO> channels,
Map<String, Object> configuration, Map<String, String> properties, String location) {
this.thingTypeUID = thingTypeUID;
this.UID = UID;
this.label = label;
this.bridgeUID = bridgeUID;
super(thingTypeUID, UID, label, bridgeUID, configuration, properties, location);
this.channels = channels;
this.configuration = configuration;
this.properties = properties;
this.location = location;
}
}