Skip to content

Commit

Permalink
fix: Update swagger to match latest changes in go-mod-core-contracts …
Browse files Browse the repository at this point in the history
…Device DTO

Per edgexfoundry/go-mod-core-contracts#800, the Device DTO is added with a new field properties, so the swagger file of core-metadata needs to be updated correspondingly.
This commit also updates the swagger with newly created field tags of the Device DTO.

Signed-off-by: Jude Hung <[email protected]>
  • Loading branch information
judehung committed Feb 20, 2023
1 parent 69b2f2f commit 60ed3a6
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 13 deletions.
12 changes: 9 additions & 3 deletions internal/core/metadata/controller/http/device_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ import (

var testDeviceLabels = []string{"MODBUS", "TEMP"}

var testProperties = map[string]any{
"TestProperty1": "property1",
"TestProperty2": true,
"TestProperty3": 123.45,
}

func buildTestDeviceRequest() requests.AddDeviceRequest {
var testAutoEvents = []dtos.AutoEvent{
{SourceName: "TestResource", Interval: "300ms", OnChange: true},
Expand Down Expand Up @@ -59,6 +65,7 @@ func buildTestDeviceRequest() requests.AddDeviceRequest {
Location: "{40lat;45long}",
AutoEvents: testAutoEvents,
Protocols: testProtocols,
Properties: testProperties,
},
}

Expand All @@ -73,7 +80,6 @@ func buildTestUpdateDeviceRequest() requests.UpdateDeviceRequest {
testProfileName := TestDeviceProfileName
testAdminState := models.Unlocked
testOperatingState := models.Up
testNotify := false
var testAutoEvents = []dtos.AutoEvent{
{SourceName: "TestResource", Interval: "300ms", OnChange: true},
}
Expand Down Expand Up @@ -101,7 +107,7 @@ func buildTestUpdateDeviceRequest() requests.UpdateDeviceRequest {
Location: "{40lat;45long}",
AutoEvents: testAutoEvents,
Protocols: testProtocols,
Notify: &testNotify,
Properties: testProperties,
},
}

Expand Down Expand Up @@ -471,7 +477,7 @@ func TestPatchDevice(t *testing.T) {
ProfileName: *testReq.Device.ProfileName,
AutoEvents: dtos.ToAutoEventModels(testReq.Device.AutoEvents),
Protocols: dtos.ToProtocolModels(testReq.Device.Protocols),
Notify: *testReq.Device.Notify,
Properties: testProperties,
}

valid := testReq
Expand Down
86 changes: 76 additions & 10 deletions openapi/v3/core-metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,12 @@ components:
description: A map of supported protocols for the given device
additionalProperties:
$ref: '#/components/schemas/ProtocolProperties'
notify:
type: boolean
description: If the 'notify' property is set to true, the device service managing the device will receive a notification
tags:
type: object
description: A map of tags used to tag the given device
properties:
type: object
description: A map of properties required to address the given device
CreateDevice:
type: object
properties:
Expand Down Expand Up @@ -215,9 +218,12 @@ components:
description: A map of supported protocols for the given device
additionalProperties:
$ref: '#/components/schemas/ProtocolProperties'
notify:
type: boolean
description: If the 'notify' property is set to true, the device service managing the device will receive a notification
tags:
type: object
description: A map of tags used to tag the given device
properties:
type: object
description: A map of properties required to address the given device
required:
- name
- adminState
Expand Down Expand Up @@ -268,9 +274,13 @@ components:
description: A map of supported protocols for the given device
additionalProperties:
$ref: '#/components/schemas/ProtocolProperties'
notify:
type: boolean
description: If the 'notify' property is set to true, the device service managing the device will receive a notification
tags:
type: object
description: A map of tags used to tag the given device
properties:
type: object
description: A map of properties required to address the given device

DeviceProfileBasicInfo:
description: "A profile basic information"
type: object
Expand Down Expand Up @@ -1167,7 +1177,21 @@ components:
Address: "localhost"
Port: "502"
UnitID: "1"
notify: false
tags:
- tag1:
field1: "field1Value"
field2: "field2Value"
- tag2:
field3: "field3Value"
field4: "field4Value"
field5: "field5Value"
properties:
- DeviceInstance:
instanceName: "myInstance"
instanceId: "instance1"
- Firmware:
firmwareId: "firmwareABC"
firmwareVersion: "v1.1.2"
UpdateDeviceRequest:
value:
- apiVersion: v3
Expand Down Expand Up @@ -1268,6 +1292,10 @@ components:
profileName: "device-simple"
serviceName: "device-simple"
adminState: "UNLOCKED"
properties:
- DeviceNameTemplate:
valueReplace: true
template: "device-name-{{Address}}-{{Port}"
GetAllDevicesResponse:
value:
apiVersion: "v3"
Expand Down Expand Up @@ -1295,6 +1323,21 @@ components:
other:
Address: "device-virtual-bool-01"
Port: "300"
tags:
- tag1:
field1: "field1Value"
field2: "field2Value"
- tag2:
field3: "field3Value"
field4: "field4Value"
field5: "field5Value"
properties:
- DeviceInstance:
instanceName: "myInstance"
instanceId: "instance1"
- Firmware:
firmwareId: "firmwareABC"
firmwareVersion: "v1.1.2"
- id: "03bd5ce0-b967-4165-a335-775fea604142"
name: "Random-UnsignedInteger-Device"
description: "Example of Device Virtual"
Expand All @@ -1318,6 +1361,21 @@ components:
other:
Address: "device-virtual-uint-01"
Port: "300"
tags:
- tag1:
field1: "field1Value"
field2: "field2Value"
- tag2:
field3: "field3Value"
field4: "field4Value"
field5: "field5Value"
properties:
- DeviceInstance:
instanceName: "myInstance"
instanceId: "instance2"
- Firmware:
firmwareId: "firmwareXYZ"
firmwareVersion: "v3.1.0"
GetAllDeviceProfilesResponse:
value:
apiVersion: "v3"
Expand Down Expand Up @@ -1397,6 +1455,10 @@ components:
- sourceName: "Bool"
interval: "10s"
onChange: false
properties:
- DeviceNameTemplate:
valueReplace: true
template: "device-name-{{Address}}-{{Port}"
- id: "90c971f0-cb84-4bda-a9f0-d9494196b54d"
name: "simple-watcher"
created: 0
Expand Down Expand Up @@ -3533,6 +3595,10 @@ paths:
- sourceName: "Bool"
interval: "10s"
onChange: false
properties:
- DeviceNameTemplate:
valueReplace: true
template: "device-name-{{Address}}-{{Port}"
'400':
description: "Request is in an invalid state"
headers:
Expand Down

0 comments on commit 60ed3a6

Please sign in to comment.