Web API: /sdrangel/deviceset/{deviceSetIndex}/device PUT: let client specify only the necessary fields. Inernally set integer value default (-1) if not specified

This commit is contained in:
f4exb 2017-12-23 07:28:02 +01:00
parent 514e408aac
commit a72200d2d0
5 changed files with 94 additions and 32 deletions

View File

@ -888,7 +888,6 @@ margin-bottom: 20px;
"description" : "DV serial device details"
};
defs.DeviceListItem = {
"required" : [ "tx" ],
"properties" : {
"displayedName" : {
"type" : "string",
@ -4253,7 +4252,7 @@ public class DeviceSetApiExample {
DeviceSetApi apiInstance = new DeviceSetApi();
Integer deviceSetIndex = 56; // Integer | Index of device set in the device set list
DeviceListItem body = ; // DeviceListItem | Device item to look for. Give values for only the fields you want to search for among displayedName, hwType, serial, sequence and deviceSetIndex. For integers except tx set to -1 to ignore the field. It will match the first device found.
DeviceListItem body = ; // DeviceListItem | Device item to look for. Specify only the fields you want to search for. You must at least specify one among displayedName, hwType or serial. index and nbStreams are ignored. Rx is assumed if tx is not specified.
try {
DeviceListItem result = apiInstance.devicesetDevicePut(deviceSetIndex, body);
System.out.println(result);
@ -4273,7 +4272,7 @@ public class DeviceSetApiExample {
public static void main(String[] args) {
DeviceSetApi apiInstance = new DeviceSetApi();
Integer deviceSetIndex = 56; // Integer | Index of device set in the device set list
DeviceListItem body = ; // DeviceListItem | Device item to look for. Give values for only the fields you want to search for among displayedName, hwType, serial, sequence and deviceSetIndex. For integers except tx set to -1 to ignore the field. It will match the first device found.
DeviceListItem body = ; // DeviceListItem | Device item to look for. Specify only the fields you want to search for. You must at least specify one among displayedName, hwType or serial. index and nbStreams are ignored. Rx is assumed if tx is not specified.
try {
DeviceListItem result = apiInstance.devicesetDevicePut(deviceSetIndex, body);
System.out.println(result);
@ -4290,7 +4289,7 @@ public class DeviceSetApiExample {
</div> -->
<div class="tab-pane" id="examples-DeviceSet-devicesetDevicePut-0-objc">
<pre class="prettyprint"><code class="language-cpp">Integer *deviceSetIndex = 56; // Index of device set in the device set list
DeviceListItem *body = ; // Device item to look for. Give values for only the fields you want to search for among displayedName, hwType, serial, sequence and deviceSetIndex. For integers except tx set to -1 to ignore the field. It will match the first device found.
DeviceListItem *body = ; // Device item to look for. Specify only the fields you want to search for. You must at least specify one among displayedName, hwType or serial. index and nbStreams are ignored. Rx is assumed if tx is not specified.
DeviceSetApi *apiInstance = [[DeviceSetApi alloc] init];
@ -4314,7 +4313,7 @@ var api = new SdRangel.DeviceSetApi()
var deviceSetIndex = 56; // {Integer} Index of device set in the device set list
var body = ; // {DeviceListItem} Device item to look for. Give values for only the fields you want to search for among displayedName, hwType, serial, sequence and deviceSetIndex. For integers except tx set to -1 to ignore the field. It will match the first device found.
var body = ; // {DeviceListItem} Device item to look for. Specify only the fields you want to search for. You must at least specify one among displayedName, hwType or serial. index and nbStreams are ignored. Rx is assumed if tx is not specified.
var callback = function(error, data, response) {
@ -4347,7 +4346,7 @@ namespace Example
var apiInstance = new DeviceSetApi();
var deviceSetIndex = 56; // Integer | Index of device set in the device set list
var body = new DeviceListItem(); // DeviceListItem | Device item to look for. Give values for only the fields you want to search for among displayedName, hwType, serial, sequence and deviceSetIndex. For integers except tx set to -1 to ignore the field. It will match the first device found.
var body = new DeviceListItem(); // DeviceListItem | Device item to look for. Specify only the fields you want to search for. You must at least specify one among displayedName, hwType or serial. index and nbStreams are ignored. Rx is assumed if tx is not specified.
try
{
@ -4370,7 +4369,7 @@ require_once(__DIR__ . '/vendor/autoload.php');
$api_instance = new Swagger\Client\Api\DeviceSetApi();
$deviceSetIndex = 56; // Integer | Index of device set in the device set list
$body = ; // DeviceListItem | Device item to look for. Give values for only the fields you want to search for among displayedName, hwType, serial, sequence and deviceSetIndex. For integers except tx set to -1 to ignore the field. It will match the first device found.
$body = ; // DeviceListItem | Device item to look for. Specify only the fields you want to search for. You must at least specify one among displayedName, hwType or serial. index and nbStreams are ignored. Rx is assumed if tx is not specified.
try {
$result = $api_instance->devicesetDevicePut($deviceSetIndex, $body);
@ -4388,7 +4387,7 @@ use SWGSDRangel::DeviceSetApi;
my $api_instance = SWGSDRangel::DeviceSetApi->new();
my $deviceSetIndex = 56; # Integer | Index of device set in the device set list
my $body = SWGSDRangel::Object::DeviceListItem->new(); # DeviceListItem | Device item to look for. Give values for only the fields you want to search for among displayedName, hwType, serial, sequence and deviceSetIndex. For integers except tx set to -1 to ignore the field. It will match the first device found.
my $body = SWGSDRangel::Object::DeviceListItem->new(); # DeviceListItem | Device item to look for. Specify only the fields you want to search for. You must at least specify one among displayedName, hwType or serial. index and nbStreams are ignored. Rx is assumed if tx is not specified.
eval {
my $result = $api_instance->devicesetDevicePut(deviceSetIndex => $deviceSetIndex, body => $body);
@ -4409,7 +4408,7 @@ from pprint import pprint
# create an instance of the API class
api_instance = swagger_sdrangel.DeviceSetApi()
deviceSetIndex = 56 # Integer | Index of device set in the device set list
body = # DeviceListItem | Device item to look for. Give values for only the fields you want to search for among displayedName, hwType, serial, sequence and deviceSetIndex. For integers except tx set to -1 to ignore the field. It will match the first device found.
body = # DeviceListItem | Device item to look for. Specify only the fields you want to search for. You must at least specify one among displayedName, hwType or serial. index and nbStreams are ignored. Rx is assumed if tx is not specified.
try:
api_response = api_instance.deviceset_device_put(deviceSetIndex, body)
@ -4468,7 +4467,7 @@ $(document).ready(function() {
var schemaWrapper = {
"in" : "body",
"name" : "body",
"description" : "Device item to look for. Give values for only the fields you want to search for among displayedName, hwType, serial, sequence and deviceSetIndex. For integers except tx set to -1 to ignore the field. It will match the first device found.",
"description" : "Device item to look for. Specify only the fields you want to search for. You must at least specify one among displayedName, hwType or serial. index and nbStreams are ignored. Rx is assumed if tx is not specified.",
"required" : true,
"schema" : {
"$ref" : "#/definitions/DeviceListItem"
@ -16201,7 +16200,7 @@ except ApiException as e:
</div>
<div id="generator">
<div class="content">
Generated 2017-12-22T13:37:01.264+01:00
Generated 2017-12-23T07:26:19.634+01:00
</div>
</div>
</div>

View File

@ -823,20 +823,29 @@ void WebAPIRequestMapper::devicesetDeviceService(const std::string& indexStr, qt
if (request.getMethod() == "PUT")
{
SWGSDRangel::SWGDeviceListItem normalResponse;
QString jsonStr = request.getBody();
QJsonObject jsonObject;
if (parseJsonBody(jsonStr, jsonObject, response))
{
normalResponse.fromJson(jsonStr);
SWGSDRangel::SWGDeviceListItem normalResponse;
int status = m_adapter->devicesetDevicePut(deviceSetIndex, normalResponse, errorResponse);
response.setStatus(status);
if (validateDeviceListItem(normalResponse, jsonObject))
{
int status = m_adapter->devicesetDevicePut(deviceSetIndex, normalResponse, errorResponse);
response.setStatus(status);
if (status/100 == 2) {
response.write(normalResponse.asJson().toUtf8());
} else {
if (status/100 == 2) {
response.write(normalResponse.asJson().toUtf8());
} else {
response.write(errorResponse.asJson().toUtf8());
}
}
else
{
response.setStatus(400,"Missing device identification");
errorResponse.init();
*errorResponse.getMessage() = "Missing device identification";
response.write(errorResponse.asJson().toUtf8());
}
}
@ -1285,6 +1294,62 @@ bool WebAPIRequestMapper::validatePresetExport(SWGSDRangel::SWGPresetExport& pre
return validatePresetIdentifer(*presetIdentifier);
}
bool WebAPIRequestMapper::validateDeviceListItem(SWGSDRangel::SWGDeviceListItem& deviceListItem, QJsonObject& jsonObject)
{
if (jsonObject.contains("tx")) {
deviceListItem.setTx(jsonObject["tx"].toInt());
} else {
deviceListItem.setTx(0); // assume Rx
}
bool identified = false;
if (jsonObject.contains("displayedName") && jsonObject["displayedName"].isString())
{
deviceListItem.setDisplayedName(new QString(jsonObject["displayedName"].toString()));
identified = true;
} else {
deviceListItem.setDisplayedName(0);
}
if (jsonObject.contains("hwType") && jsonObject["hwType"].isString())
{
deviceListItem.setHwType(new QString(jsonObject["hwType"].toString()));
identified = true;
} else {
deviceListItem.setHwType(0);
}
if (jsonObject.contains("serial") && jsonObject["serial"].isString())
{
deviceListItem.setSerial(new QString(jsonObject["serial"].toString()));
identified = true;
} else {
deviceListItem.setSerial(0);
}
if (jsonObject.contains("index")) {
deviceListItem.setIndex(jsonObject["index"].toInt(-1));
} else {
deviceListItem.setIndex(-1);
}
if (jsonObject.contains("sequence")){
deviceListItem.setSequence(jsonObject["sequence"].toInt(-1));
} else {
deviceListItem.setSequence(-1);
}
if (jsonObject.contains("streamIndex")) {
deviceListItem.setStreamIndex(jsonObject["streamIndex"].toInt(-1));
} else {
deviceListItem.setStreamIndex(-1);
}
return identified;
}
bool WebAPIRequestMapper::validateDeviceSettings(SWGSDRangel::SWGDeviceSettings& deviceSettings, QJsonObject& jsonObject)
{
if (jsonObject.contains("tx")) {

View File

@ -69,6 +69,7 @@ private:
bool validatePresetTransfer(SWGSDRangel::SWGPresetTransfer& presetTransfer);
bool validatePresetIdentifer(SWGSDRangel::SWGPresetIdentifier& presetIdentifier);
bool validatePresetExport(SWGSDRangel::SWGPresetExport& presetExport);
bool validateDeviceListItem(SWGSDRangel::SWGDeviceListItem& deviceListItem, QJsonObject& jsonObject);
bool validateDeviceSettings(SWGSDRangel::SWGDeviceSettings& deviceSettings, QJsonObject& jsonObject);
bool validateChannelSettings(SWGSDRangel::SWGChannelSettings& deviceSettings, QJsonObject& jsonObject);

View File

@ -582,7 +582,7 @@ paths:
description: Index of device set in the device set list
- name: body
in: body
description: Device item to look for. Give values for only the fields you want to search for among displayedName, hwType, serial, sequence and deviceSetIndex. For integers except tx set to -1 to ignore the field. It will match the first device found.
description: Device item to look for. Specify only the fields you want to search for. You must at least specify one among displayedName, hwType or serial. index and nbStreams are ignored. Rx is assumed if tx is not specified.
required: true
schema:
$ref: "#/definitions/DeviceListItem"
@ -1035,8 +1035,6 @@ definitions:
DeviceListItem:
description: "Summarized information about attached hardware device"
required:
- tx
properties:
displayedName:
description: "Displayable name that uniquely identifies this device instance"

View File

@ -888,7 +888,6 @@ margin-bottom: 20px;
"description" : "DV serial device details"
};
defs.DeviceListItem = {
"required" : [ "tx" ],
"properties" : {
"displayedName" : {
"type" : "string",
@ -4253,7 +4252,7 @@ public class DeviceSetApiExample {
DeviceSetApi apiInstance = new DeviceSetApi();
Integer deviceSetIndex = 56; // Integer | Index of device set in the device set list
DeviceListItem body = ; // DeviceListItem | Device item to look for. Give values for only the fields you want to search for among displayedName, hwType, serial, sequence and deviceSetIndex. For integers except tx set to -1 to ignore the field. It will match the first device found.
DeviceListItem body = ; // DeviceListItem | Device item to look for. Specify only the fields you want to search for. You must at least specify one among displayedName, hwType or serial. index and nbStreams are ignored. Rx is assumed if tx is not specified.
try {
DeviceListItem result = apiInstance.devicesetDevicePut(deviceSetIndex, body);
System.out.println(result);
@ -4273,7 +4272,7 @@ public class DeviceSetApiExample {
public static void main(String[] args) {
DeviceSetApi apiInstance = new DeviceSetApi();
Integer deviceSetIndex = 56; // Integer | Index of device set in the device set list
DeviceListItem body = ; // DeviceListItem | Device item to look for. Give values for only the fields you want to search for among displayedName, hwType, serial, sequence and deviceSetIndex. For integers except tx set to -1 to ignore the field. It will match the first device found.
DeviceListItem body = ; // DeviceListItem | Device item to look for. Specify only the fields you want to search for. You must at least specify one among displayedName, hwType or serial. index and nbStreams are ignored. Rx is assumed if tx is not specified.
try {
DeviceListItem result = apiInstance.devicesetDevicePut(deviceSetIndex, body);
System.out.println(result);
@ -4290,7 +4289,7 @@ public class DeviceSetApiExample {
</div> -->
<div class="tab-pane" id="examples-DeviceSet-devicesetDevicePut-0-objc">
<pre class="prettyprint"><code class="language-cpp">Integer *deviceSetIndex = 56; // Index of device set in the device set list
DeviceListItem *body = ; // Device item to look for. Give values for only the fields you want to search for among displayedName, hwType, serial, sequence and deviceSetIndex. For integers except tx set to -1 to ignore the field. It will match the first device found.
DeviceListItem *body = ; // Device item to look for. Specify only the fields you want to search for. You must at least specify one among displayedName, hwType or serial. index and nbStreams are ignored. Rx is assumed if tx is not specified.
DeviceSetApi *apiInstance = [[DeviceSetApi alloc] init];
@ -4314,7 +4313,7 @@ var api = new SdRangel.DeviceSetApi()
var deviceSetIndex = 56; // {Integer} Index of device set in the device set list
var body = ; // {DeviceListItem} Device item to look for. Give values for only the fields you want to search for among displayedName, hwType, serial, sequence and deviceSetIndex. For integers except tx set to -1 to ignore the field. It will match the first device found.
var body = ; // {DeviceListItem} Device item to look for. Specify only the fields you want to search for. You must at least specify one among displayedName, hwType or serial. index and nbStreams are ignored. Rx is assumed if tx is not specified.
var callback = function(error, data, response) {
@ -4347,7 +4346,7 @@ namespace Example
var apiInstance = new DeviceSetApi();
var deviceSetIndex = 56; // Integer | Index of device set in the device set list
var body = new DeviceListItem(); // DeviceListItem | Device item to look for. Give values for only the fields you want to search for among displayedName, hwType, serial, sequence and deviceSetIndex. For integers except tx set to -1 to ignore the field. It will match the first device found.
var body = new DeviceListItem(); // DeviceListItem | Device item to look for. Specify only the fields you want to search for. You must at least specify one among displayedName, hwType or serial. index and nbStreams are ignored. Rx is assumed if tx is not specified.
try
{
@ -4370,7 +4369,7 @@ require_once(__DIR__ . '/vendor/autoload.php');
$api_instance = new Swagger\Client\Api\DeviceSetApi();
$deviceSetIndex = 56; // Integer | Index of device set in the device set list
$body = ; // DeviceListItem | Device item to look for. Give values for only the fields you want to search for among displayedName, hwType, serial, sequence and deviceSetIndex. For integers except tx set to -1 to ignore the field. It will match the first device found.
$body = ; // DeviceListItem | Device item to look for. Specify only the fields you want to search for. You must at least specify one among displayedName, hwType or serial. index and nbStreams are ignored. Rx is assumed if tx is not specified.
try {
$result = $api_instance->devicesetDevicePut($deviceSetIndex, $body);
@ -4388,7 +4387,7 @@ use SWGSDRangel::DeviceSetApi;
my $api_instance = SWGSDRangel::DeviceSetApi->new();
my $deviceSetIndex = 56; # Integer | Index of device set in the device set list
my $body = SWGSDRangel::Object::DeviceListItem->new(); # DeviceListItem | Device item to look for. Give values for only the fields you want to search for among displayedName, hwType, serial, sequence and deviceSetIndex. For integers except tx set to -1 to ignore the field. It will match the first device found.
my $body = SWGSDRangel::Object::DeviceListItem->new(); # DeviceListItem | Device item to look for. Specify only the fields you want to search for. You must at least specify one among displayedName, hwType or serial. index and nbStreams are ignored. Rx is assumed if tx is not specified.
eval {
my $result = $api_instance->devicesetDevicePut(deviceSetIndex => $deviceSetIndex, body => $body);
@ -4409,7 +4408,7 @@ from pprint import pprint
# create an instance of the API class
api_instance = swagger_sdrangel.DeviceSetApi()
deviceSetIndex = 56 # Integer | Index of device set in the device set list
body = # DeviceListItem | Device item to look for. Give values for only the fields you want to search for among displayedName, hwType, serial, sequence and deviceSetIndex. For integers except tx set to -1 to ignore the field. It will match the first device found.
body = # DeviceListItem | Device item to look for. Specify only the fields you want to search for. You must at least specify one among displayedName, hwType or serial. index and nbStreams are ignored. Rx is assumed if tx is not specified.
try:
api_response = api_instance.deviceset_device_put(deviceSetIndex, body)
@ -4468,7 +4467,7 @@ $(document).ready(function() {
var schemaWrapper = {
"in" : "body",
"name" : "body",
"description" : "Device item to look for. Give values for only the fields you want to search for among displayedName, hwType, serial, sequence and deviceSetIndex. For integers except tx set to -1 to ignore the field. It will match the first device found.",
"description" : "Device item to look for. Specify only the fields you want to search for. You must at least specify one among displayedName, hwType or serial. index and nbStreams are ignored. Rx is assumed if tx is not specified.",
"required" : true,
"schema" : {
"$ref" : "#/definitions/DeviceListItem"
@ -16201,7 +16200,7 @@ except ApiException as e:
</div>
<div id="generator">
<div class="content">
Generated 2017-12-22T13:37:01.264+01:00
Generated 2017-12-23T07:26:19.634+01:00
</div>
</div>
</div>