Skip to content

Commit

Permalink
Use JSON schema anchors where relevant
Browse files Browse the repository at this point in the history
With the upgrade to the latest JSON schema validator, internal anchor references (within a schema) now work. Types which should only be used internally still use the longer paths to `$defs`.

This has the added benefit that these anchors are also evaluated. It turned out that some anchors in `ParticipantGroupStatus` were wrong, and in `DataStreamServiceRequest` one was missing.

Closes #353
  • Loading branch information
Whathecode committed Oct 28, 2024
1 parent 0eadde6 commit c356f9c
Show file tree
Hide file tree
Showing 25 changed files with 85 additions and 80 deletions.
4 changes: 2 additions & 2 deletions rpc/schemas/common/data/input/elements/InputElement.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"$schema": "https://json-schema.org/draft/2019-09/schema",
"type": "object",
"oneOf": [
{ "$ref": "#/$defs/SelectOne" },
{ "$ref": "#/$defs/Text" }
{ "$ref": "#SelectOne" },
{ "$ref": "#Text" }
],
"$defs": {
"SelectOne": {
Expand Down
2 changes: 1 addition & 1 deletion rpc/schemas/common/devices/DeviceConfiguration.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "https://json-schema.org/draft/2019-09/schema",
"allOf": [
{ "$ref": "#/$defs/DeviceConfiguration" },
{ "$ref": "#DeviceConfiguration" },
{
"if": { "properties": { "__type": { "const": "dk.cachet.carp.common.application.devices.AltBeacon" } } },
"then": { "$ref": "AltBeacon.json" }
Expand Down
2 changes: 1 addition & 1 deletion rpc/schemas/common/devices/DeviceRegistration.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "https://json-schema.org/draft/2019-09/schema",
"allOf": [
{ "$ref": "#/$defs/DeviceRegistration" },
{ "$ref": "#DeviceRegistration" },
{
"if": { "properties": { "__type": { "const": "dk.cachet.carp.common.application.devices.AltBeaconDeviceRegistration" } } },
"then": { "$ref": "AltBeacon.json#DeviceRegistration" }
Expand Down
2 changes: 1 addition & 1 deletion rpc/schemas/common/devices/PrimaryDeviceConfiguration.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "https://json-schema.org/draft/2019-09/schema",
"allOf": [
{ "$ref": "#/$defs/PrimaryDeviceConfiguration" },
{ "$ref": "#PrimaryDeviceConfiguration" },
{
"if": { "properties": { "__type": { "const": "dk.cachet.carp.common.application.devices.Smartphone" } } },
"then": { "$ref": "Smartphone.json" }
Expand Down
2 changes: 1 addition & 1 deletion rpc/schemas/common/sampling/SamplingConfiguration.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "https://json-schema.org/draft/2019-09/schema",
"allOf": [
{ "$ref": "#/$defs/SamplingConfiguration" },
{ "$ref": "#SamplingConfiguration" },
{
"if": { "properties": { "__type": { "const": "dk.cachet.carp.common.application.sampling.BatteryAwareSamplingConfiguration" } } },
"then": { "$ref": "BatteryAwareSamplingConfiguration.json" }
Expand Down
4 changes: 2 additions & 2 deletions rpc/schemas/common/tasks/Measure.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"$schema": "https://json-schema.org/draft/2019-09/schema",
"type": "object",
"oneOf": [
{ "$ref": "#/$defs/DataStream" },
{ "$ref": "#/$defs/TriggerData" }
{ "$ref": "#DataStream" },
{ "$ref": "#TriggerData" }
],
"$defs": {
"DataStream": {
Expand Down
2 changes: 1 addition & 1 deletion rpc/schemas/common/tasks/TaskConfiguration.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "https://json-schema.org/draft/2019-09/schema",
"allOf": [
{ "$ref": "#/$defs/TaskConfiguration" },
{ "$ref": "#TaskConfiguration" },
{
"if": { "properties": { "__type": { "const": "dk.cachet.carp.common.application.tasks.BackgroundTask" } } },
"then": { "$ref": "BackgroundTask.json" }
Expand Down
2 changes: 1 addition & 1 deletion rpc/schemas/common/triggers/TaskControl.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"triggerId": { "type": "integer" },
"taskName": { "type": "string" },
"destinationDeviceRoleName": { "type": "string" },
"control": { "$ref": "#/$defs/Control" }
"control": { "$ref": "#Control" }
},
"required": [ "triggerId", "taskName", "destinationDeviceRoleName", "control" ],
"additionalProperties": false,
Expand Down
2 changes: 1 addition & 1 deletion rpc/schemas/common/triggers/TriggerConfiguration.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "https://json-schema.org/draft/2019-09/schema",
"allOf": [
{ "$ref": "#/$defs/TriggerConfiguration" },
{ "$ref": "#TriggerConfiguration" },
{
"if": { "properties": { "__type": { "const": "dk.cachet.carp.common.application.triggers.ElapsedTimeTrigger" } } },
"then": { "$ref": "ElapsedTimeTrigger.json" }
Expand Down
4 changes: 2 additions & 2 deletions rpc/schemas/common/users/AccountIdentity.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"$schema": "https://json-schema.org/draft/2019-09/schema",
"type": "object",
"oneOf": [
{ "$ref": "#/$defs/EmailAccountIdentity" },
{ "$ref": "#/$defs/UsernameAccountIdentity" }
{ "$ref": "#EmailAccountIdentity" },
{ "$ref": "#UsernameAccountIdentity" }
],
"$defs": {
"EmailAccountIdentity": {
Expand Down
4 changes: 2 additions & 2 deletions rpc/schemas/common/users/AssignedTo.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"$schema": "https://json-schema.org/draft/2019-09/schema",
"type": "object",
"oneOf": [
{ "$ref": "#/$defs/All" },
{ "$ref": "#/$defs/Roles" }
{ "$ref": "#All" },
{ "$ref": "#Roles" }
],
"$defs": {
"All": {
Expand Down
4 changes: 2 additions & 2 deletions rpc/schemas/common/users/ParticipantAttribute.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"$schema": "https://json-schema.org/draft/2019-09/schema",
"type": "object",
"oneOf": [
{ "$ref": "#/$defs/DefaultParticipantAttribute" },
{ "$ref": "#/$defs/CustomParticipantAttribute" }
{ "$ref": "#DefaultParticipantAttribute" },
{ "$ref": "#CustomParticipantAttribute" }
],
"$defs": {
"DefaultParticipantAttribute": {
Expand Down
11 changes: 6 additions & 5 deletions rpc/schemas/data/DataStreamService/DataStreamServiceRequest.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"$schema": "https://json-schema.org/draft/2019-09/schema",
"oneOf": [
{ "$ref": "#/$defs/OpenDataStreams" },
{ "$ref": "#/$defs/AppendToDataStreams" },
{ "$ref": "#/$defs/GetDataStream" },
{ "$ref": "#/$defs/CloseDataStreams" },
{ "$ref": "#/$defs/RemoveDataStreams" }
{ "$ref": "#OpenDataStreams" },
{ "$ref": "#AppendToDataStreams" },
{ "$ref": "#GetDataStream" },
{ "$ref": "#CloseDataStreams" },
{ "$ref": "#RemoveDataStreams" }
],
"$defs": {
"ApiVersion": { "const": "1.1" },
Expand Down Expand Up @@ -76,6 +76,7 @@
}
},
"RemoveDataStreams": {
"$anchor": "RemoveDataStreams",
"type": "object",
"properties": {
"__type": { "const": "dk.cachet.carp.data.infrastructure.DataStreamServiceRequest.RemoveDataStreams" },
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"$schema": "https://json-schema.org/draft/2019-09/schema",
"oneOf": [
{ "$ref": "#/$defs/CreateStudyDeployment" },
{ "$ref": "#/$defs/RemoveStudyDeployments" },
{ "$ref": "#/$defs/GetStudyDeploymentStatus" },
{ "$ref": "#/$defs/GetStudyDeploymentStatusList" },
{ "$ref": "#/$defs/RegisterDevice" },
{ "$ref": "#/$defs/UnregisterDevice" },
{ "$ref": "#/$defs/GetDeviceDeploymentFor" },
{ "$ref": "#/$defs/DeviceDeployed" },
{ "$ref": "#/$defs/Stop" }
{ "$ref": "#CreateStudyDeployment" },
{ "$ref": "#RemoveStudyDeployments" },
{ "$ref": "#GetStudyDeploymentStatus" },
{ "$ref": "#GetStudyDeploymentStatusList" },
{ "$ref": "#RegisterDevice" },
{ "$ref": "#UnregisterDevice" },
{ "$ref": "#GetDeviceDeploymentFor" },
{ "$ref": "#DeviceDeployed" },
{ "$ref": "#Stop" }
],
"$defs": {
"ApiVersion": { "const": "1.3" },
Expand Down
15 changes: 8 additions & 7 deletions rpc/schemas/deployments/DeviceDeploymentStatus.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"$schema": "https://json-schema.org/draft/2019-09/schema",
"oneOf": [
{ "$ref": "#/$defs/Unregistered" },
{ "$ref": "#/$defs/Registered" },
{ "$ref": "#/$defs/Deployed" },
{ "$ref": "#/$defs/NeedsRedeployment" }
{ "$ref": "#Unregistered" },
{ "$ref": "#Registered" },
{ "$ref": "#Deployed" },
{ "$ref": "#NeedsRedeployment" }
],
"$defs": {
"DeviceDeploymentStatus": {
Expand All @@ -16,6 +16,7 @@
"required": [ "__type", "device" ]
},
"NotDeployed": {
"$anchor": "NotDeployed",
"type": "object",
"properties": {
"remainingDevicesToRegisterToObtainDeployment": {
Expand All @@ -33,7 +34,7 @@
"$anchor": "Unregistered",
"allOf": [
{ "$ref": "#/$defs/DeviceDeploymentStatus" },
{ "$ref": "#/$defs/NotDeployed" }
{ "$ref": "#NotDeployed" }
],
"properties": {
"__type": { "const": "dk.cachet.carp.deployments.application.DeviceDeploymentStatus.Unregistered" },
Expand All @@ -46,7 +47,7 @@
"$anchor": "Registered",
"allOf": [
{ "$ref": "#/$defs/DeviceDeploymentStatus" },
{ "$ref": "#/$defs/NotDeployed" }
{ "$ref": "#NotDeployed" }
],
"properties": {
"__type": { "const": "dk.cachet.carp.deployments.application.DeviceDeploymentStatus.Registered" },
Expand All @@ -69,7 +70,7 @@
"$anchor": "NeedsRedeployment",
"allOf": [
{ "$ref": "#/$defs/DeviceDeploymentStatus" },
{ "$ref": "#/$defs/NotDeployed" }
{ "$ref": "#NotDeployed" }
],
"properties": {
"__type": { "const": "dk.cachet.carp.deployments.application.DeviceDeploymentStatus.NeedsRedeployment" }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"$schema": "https://json-schema.org/draft/2019-09/schema",
"oneOf": [
{ "$ref": "#/$defs/GetActiveParticipationInvitations" },
{ "$ref": "#/$defs/GetParticipantData" },
{ "$ref": "#/$defs/GetParticipantDataList" },
{ "$ref": "#/$defs/SetParticipantData" }
{ "$ref": "#GetActiveParticipationInvitations" },
{ "$ref": "#GetParticipantData" },
{ "$ref": "#GetParticipantDataList" },
{ "$ref": "#SetParticipantData" }
],
"$defs": {
"ApiVersion": { "const": "1.0" },
Expand Down
8 changes: 4 additions & 4 deletions rpc/schemas/deployments/StudyDeploymentStatus.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"$schema": "https://json-schema.org/draft/2019-09/schema",
"oneOf": [
{ "$ref": "#/$defs/Invited" },
{ "$ref": "#/$defs/DeployingDevices" },
{ "$ref": "#/$defs/Running" },
{ "$ref": "#/$defs/Stopped" }
{ "$ref": "#Invited" },
{ "$ref": "#DeployingDevices" },
{ "$ref": "#Running" },
{ "$ref": "#Stopped" }
],
"$defs": {
"StudyDeploymentStatus": {
Expand Down
3 changes: 2 additions & 1 deletion rpc/schemas/deployments/users/ParticipantData.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
"common": { "$ref": "../users/ParticipantDataMap.json" },
"roles": {
"type": "array",
"items": { "$ref": "#/$defs/RoleData" }
"items": { "$ref": "#RoleData" }
}
},
"required": [ "studyDeploymentId", "common", "roles" ],
"additionalProperties": false,
"$defs": {
"RoleData": {
"$anchor": "RoleData",
"type": "object",
"properties":{
"roleName": { "type": "string" },
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "https://json-schema.org/draft/2019-09/schema",
"oneOf": [
{ "$ref": "#/$defs/CreateCustomProtocol" }
{ "$ref": "#CreateCustomProtocol" }
],
"$defs": {
"ApiVersion": { "const": "1.1" },
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"$schema": "https://json-schema.org/draft/2019-09/schema",
"oneOf": [
{ "$ref": "#/$defs/Add" },
{ "$ref": "#/$defs/AddVersion" },
{ "$ref": "#/$defs/UpdateParticipantDataConfiguration" },
{ "$ref": "#/$defs/GetBy" },
{ "$ref": "#/$defs/GetAllForOwner" },
{ "$ref": "#/$defs/GetVersionHistoryFor" }
{ "$ref": "#Add" },
{ "$ref": "#AddVersion" },
{ "$ref": "#UpdateParticipantDataConfiguration" },
{ "$ref": "#GetBy" },
{ "$ref": "#GetAllForOwner" },
{ "$ref": "#GetVersionHistoryFor" }
],
"$defs": {
"ApiVersion": { "const": "1.1" },
Expand Down
3 changes: 2 additions & 1 deletion rpc/schemas/protocols/StudyProtocolSnapshot.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
},
"connections": {
"type": "array",
"items": { "$ref": "#/$defs/DeviceConnection" }
"items": { "$ref": "#DeviceConnection" }
},
"tasks": {
"type": "array",
Expand Down Expand Up @@ -54,6 +54,7 @@
"additionalProperties": false,
"$defs": {
"DeviceConnection": {
"$anchor": "DeviceConnection",
"type": "object",
"properties": {
"roleName": { "type": "string" },
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"$schema": "https://json-schema.org/draft/2019-09/schema",
"oneOf": [
{ "$ref": "#/$defs/AddParticipantByEmailAddress" },
{ "$ref": "#/$defs/AddParticipantByUsername" },
{ "$ref": "#/$defs/GetParticipant" },
{ "$ref": "#/$defs/GetParticipants" },
{ "$ref": "#/$defs/InviteNewParticipantGroup" },
{ "$ref": "#/$defs/GetParticipantGroupStatusList" },
{ "$ref": "#/$defs/StopParticipantGroup" }
{ "$ref": "#AddParticipantByEmailAddress" },
{ "$ref": "#AddParticipantByUsername" },
{ "$ref": "#GetParticipant" },
{ "$ref": "#GetParticipants" },
{ "$ref": "#InviteNewParticipantGroup" },
{ "$ref": "#GetParticipantGroupStatusList" },
{ "$ref": "#StopParticipantGroup" }
],
"$defs": {
"ApiVersion": { "const": "1.2" },
Expand Down
20 changes: 10 additions & 10 deletions rpc/schemas/studies/StudyService/StudyServiceRequest.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
{
"$schema": "https://json-schema.org/draft/2019-09/schema",
"oneOf": [
{ "$ref": "#/$defs/CreateStudy" },
{ "$ref": "#/$defs/SetInternalDescription" },
{ "$ref": "#/$defs/GetStudyDetails" },
{ "$ref": "#/$defs/GetStudyStatus" },
{ "$ref": "#/$defs/GetStudiesOverview" },
{ "$ref": "#/$defs/SetInvitation" },
{ "$ref": "#/$defs/SetProtocol" },
{ "$ref": "#/$defs/RemoveProtocol" },
{ "$ref": "#/$defs/GoLive" },
{ "$ref": "#/$defs/Remove" }
{ "$ref": "#CreateStudy" },
{ "$ref": "#SetInternalDescription" },
{ "$ref": "#GetStudyDetails" },
{ "$ref": "#GetStudyStatus" },
{ "$ref": "#GetStudiesOverview" },
{ "$ref": "#SetInvitation" },
{ "$ref": "#SetProtocol" },
{ "$ref": "#RemoveProtocol" },
{ "$ref": "#GoLive" },
{ "$ref": "#Remove" }
],
"$defs": {
"ApiVersion": { "const": "1.1" },
Expand Down
4 changes: 2 additions & 2 deletions rpc/schemas/studies/StudyStatus.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"$schema": "https://json-schema.org/draft/2019-09/schema",
"oneOf": [
{ "$ref": "#/$defs/Configuring" },
{ "$ref": "#/$defs/Live" }
{ "$ref": "#Configuring" },
{ "$ref": "#Live" }
],
"$defs": {
"StudyStatus": {
Expand Down
Loading

0 comments on commit c356f9c

Please sign in to comment.