@@ -3,169 +3,169 @@ import spec2 from '../public/swagger/v2.json' with { type: 'json' }
3
3
4
4
const v1SummaryOverrides = {
5
5
'post-users-login' : 'Login' ,
6
- 'get-users-id -getMqttCredentials' : 'MQTT Credentials' ,
6
+ 'get-users-{id} -getMqttCredentials' : 'MQTT Credentials' ,
7
7
// points
8
- 'get-devices-id -points-fk ' : 'Get device point by id' ,
9
- 'get-devices-id -points' : 'Get device points' ,
10
- 'delete-devices-id -points-fk ' : 'Delete device point by id' ,
8
+ 'get-devices-{id} -points-{fk} ' : 'Get device point by id' ,
9
+ 'get-devices-{id} -points' : 'Get device points' ,
10
+ 'delete-devices-{id} -points-{fk} ' : 'Delete device point by id' ,
11
11
// readings
12
- 'get-devices-id -readings-fk ' : 'Get device reading by id' ,
13
- 'get-devices-id -readings' : 'Get device readings' ,
14
- 'put-devices-id -gatewayReadings-fk ' : 'Update device reading by id' ,
12
+ 'get-devices-{id} -readings-{fk} ' : 'Get device reading by id' ,
13
+ 'get-devices-{id} -readings' : 'Get device readings' ,
14
+ 'put-devices-{id} -gatewayReadings-{fk} ' : 'Update device reading by id' ,
15
15
16
16
// device
17
17
'get-devices-id' : 'Get device' ,
18
- 'get-users-id -getDeviceSummary' : 'Summary of devices' ,
18
+ 'get-users-{id} -getDeviceSummary' : 'Summary of devices' ,
19
19
'post-devices-changeTags' : 'Change tags for a device' ,
20
20
21
21
// device config stuff
22
- 'get-devices-id -setupSqsForwarding' : 'Set SQS forwarding for a device' ,
23
- 'get-devices-id -setMetaItem' : 'Set meta item for a device' ,
24
- 'get-devices-id -flightMode' : 'Set flight mode for a device' ,
22
+ 'get-devices-{id} -setupSqsForwarding' : 'Set SQS forwarding for a device' ,
23
+ 'get-devices-{id} -setMetaItem' : 'Set meta item for a device' ,
24
+ 'get-devices-{id} -flightMode' : 'Set flight mode for a device' ,
25
25
26
- 'get-devices-id -gatewayReadings-fk ' : 'Get device gateway reading by id' ,
27
- 'delete-devices-id -gatewayReadings-fk ' : 'Delete device gateway reading by id' ,
26
+ 'get-devices-{id} -gatewayReadings-{fk} ' : 'Get device gateway reading by id' ,
27
+ 'delete-devices-{id} -gatewayReadings-{fk} ' : 'Delete device gateway reading by id' ,
28
28
29
- 'post-devices-id -messages' : 'Send a new message to the device' ,
30
- 'delete-devices-id -messages' : 'Delete all messages for a device' ,
31
- 'get-users-id -getDevicesInZone' : 'Devices in zone' ,
32
- 'get-users-id -getDevicesByTag' : 'Devices with tag' ,
29
+ 'post-devices-{id} -messages' : 'Send a new message to the device' ,
30
+ 'delete-devices-{id} -messages' : 'Delete all messages for a device' ,
31
+ 'get-users-{id} -getDevicesInZone' : 'Devices in zone' ,
32
+ 'get-users-{id} -getDevicesByTag' : 'Devices with tag' ,
33
33
34
34
// TODO notification triggers should probably render in swagger with better names
35
- 'get-devices-id -notificationTriggers' : 'Get device triggers' ,
36
- 'get-devices-id -notificationTriggers-fk ' : 'Get device trigger by id' ,
37
- 'put-devices-id -notificationTriggers-fk ' : 'Update device trigger by id' ,
38
- 'delete-devices-id -notificationTriggers-fk ' : 'Delete device trigger by id' ,
39
- 'post-devices-id -notificationTriggers' : 'Create device trigger' ,
40
- 'delete-devices-id -notificationTriggers' : 'Delete all device triggers' ,
35
+ 'get-devices-{id} -notificationTriggers' : 'Get device triggers' ,
36
+ 'get-devices-{id} -notificationTriggers-{fk} ' : 'Get device trigger by id' ,
37
+ 'put-devices-{id} -notificationTriggers-{fk} ' : 'Update device trigger by id' ,
38
+ 'delete-devices-{id} -notificationTriggers-{fk} ' : 'Delete device trigger by id' ,
39
+ 'post-devices-{id} -notificationTriggers' : 'Create device trigger' ,
40
+ 'delete-devices-{id} -notificationTriggers' : 'Delete all device triggers' ,
41
41
// TODO geofences should have better default summaries
42
- 'get-users-id -geofences-fk ' : 'Get user geofence by id' ,
43
- 'get-users-id -geofences' : 'Get user geofences' ,
44
- 'put-users-id -geofences-fk ' : 'Update user geofence by id' ,
45
- 'delete-users-id -geofences-fk ' : 'Delete user geofence by id' ,
46
- 'post-users-id -geofences' : 'Create user geofence' ,
47
- 'delete-users-id -geofences' : 'Delete all user geofences' ,
42
+ 'get-users-{id} -geofences-{fk} ' : 'Get user geofence by id' ,
43
+ 'get-users-{id} -geofences' : 'Get user geofences' ,
44
+ 'put-users-{id} -geofences-{fk} ' : 'Update user geofence by id' ,
45
+ 'delete-users-{id} -geofences-{fk} ' : 'Delete user geofence by id' ,
46
+ 'post-users-{id} -geofences' : 'Create user geofence' ,
47
+ 'delete-users-{id} -geofences' : 'Delete all user geofences' ,
48
48
49
- 'get-devices-id -deactivate' : 'Deactivate device' ,
50
- 'get-devices-id -activateOnResellerPlan' : 'Activate device on reseller plan' ,
49
+ 'get-devices-{id} -deactivate' : 'Deactivate device' ,
50
+ 'get-devices-{id} -activateOnResellerPlan' : 'Activate device on reseller plan' ,
51
51
52
- 'get-devices-id -setNtripSettings' : 'Set the NTRIP settings for a device.' ,
52
+ 'get-devices-{id} -setNtripSettings' : 'Set the NTRIP settings for a device.' ,
53
53
54
54
'post-reports-activity' : 'Device Activity' ,
55
55
'post-reports-vehicle-summary' : 'Vehicle Summary' ,
56
56
}
57
57
58
58
const v1DescriptionOverrides = {
59
- 'get-devices-id -points' : 'Gets one or more points for a device, based on filtering.' ,
60
- 'get-devices-id -points-fk ' : 'Get a specific point for device when you already know the device ID and point ID.' ,
61
- 'get-users-id -getMqttCredentials' : 'Retrieves a users MQTT Credentials if set, for legacy use in connecting to MQTT.' ,
62
- 'get-users-id -getDeviceSummary' : 'Lists all devices for a user, with a summary of state, including most resent points.' ,
63
- 'get-devices-id -deactivate' : 'Deactivates a device.' ,
64
- 'get-devices-id -activateOnResellerPlan' : 'Activates a device on a reseller plan.\n\nThis is a special endpoint for resellers to activate a device on a reseller plan.\n\nIf you want to activate a device on a modern plan, see the V2 API.' ,
65
- 'get-devices-id -readings' : "Gets [readings](/terminology/readings) that a device has taken, such as battery voltage, temperature, humidity etc.\n\nUse [filtering](/apis/v1/filtering) to get a specific [type](/terminology/readings#types)." ,
59
+ 'get-devices-{id} -points' : 'Gets one or more points for a device, based on filtering.' ,
60
+ 'get-devices-{id} -points-{fk} ' : 'Get a specific point for device when you already know the device ID and point ID.' ,
61
+ 'get-users-{id} -getMqttCredentials' : 'Retrieves a users MQTT Credentials if set, for legacy use in connecting to MQTT.' ,
62
+ 'get-users-{id} -getDeviceSummary' : 'Lists all devices for a user, with a summary of state, including most resent points.' ,
63
+ 'get-devices-{id} -deactivate' : 'Deactivates a device.' ,
64
+ 'get-devices-{id} -activateOnResellerPlan' : 'Activates a device on a reseller plan.\n\nThis is a special endpoint for resellers to activate a device on a reseller plan.\n\nIf you want to activate a device on a modern plan, see the V2 API.' ,
65
+ 'get-devices-{id} -readings' : "Gets [readings](/terminology/readings) that a device has taken, such as battery voltage, temperature, humidity etc.\n\nUse [filtering](/apis/v1/filtering) to get a specific [type](/terminology/readings#types)." ,
66
66
}
67
67
68
68
const v1Deprecated = [
69
- 'get-devices-id -transients-fk ' ,
69
+ 'get-devices-{id} -transients-{fk} ' ,
70
70
]
71
71
72
72
const v1ReTag = {
73
73
'post-users-login' : 'authentication' ,
74
74
75
75
// Keep the MQTT in its own section, near the bottom
76
- 'get-users-id -getMqttCredentials' : 'mqtt' ,
76
+ 'get-users-{id} -getMqttCredentials' : 'mqtt' ,
77
77
78
78
// TODO geofences should probably render in swagger with their own tag
79
- 'put-users-id -geofences-fk ' : 'geofences' ,
80
- 'delete-users-id -geofences-fk ' : 'geofences' ,
81
- 'post-users-id -geofences' : 'geofences' ,
82
- 'delete-users-id -geofences' : 'geofences' ,
79
+ 'put-users-{id} -geofences-{fk} ' : 'geofences' ,
80
+ 'delete-users-{id} -geofences-{fk} ' : 'geofences' ,
81
+ 'post-users-{id} -geofences' : 'geofences' ,
82
+ 'delete-users-{id} -geofences' : 'geofences' ,
83
83
84
84
// Split out gateway readings for clarity
85
- 'get-devices-id -gatewayReadings-fk ' : 'readings-gateway' ,
86
- 'delete-devices-id -gatewayReadings-fk ' : 'readings-gateway' ,
85
+ 'get-devices-{id} -gatewayReadings-{fk} ' : 'readings-gateway' ,
86
+ 'delete-devices-{id} -gatewayReadings-{fk} ' : 'readings-gateway' ,
87
87
88
88
// Split out device config for clarity
89
- 'get-devices-id -config' : 'device-config' ,
90
- 'put-devices-id -config' : 'device-config' ,
91
- 'post-devices-id -setSafeZone' : 'device-config' ,
92
- 'get-devices-id -setupSqsForwarding' : 'device-config' ,
93
- 'get-devices-id -setMetaItem' : 'device-config' ,
94
- 'get-devices-id -flightMode' : 'device-config' ,
95
- 'get-devices-id -getSafeZone' : 'device-config' ,
89
+ 'get-devices-{id} -config' : 'device-config' ,
90
+ 'put-devices-{id} -config' : 'device-config' ,
91
+ 'post-devices-{id} -setSafeZone' : 'device-config' ,
92
+ 'get-devices-{id} -setupSqsForwarding' : 'device-config' ,
93
+ 'get-devices-{id} -setMetaItem' : 'device-config' ,
94
+ 'get-devices-{id} -flightMode' : 'device-config' ,
95
+ 'get-devices-{id} -getSafeZone' : 'device-config' ,
96
96
97
97
// Split out device activation too
98
- 'get-devices-id -deactivate' : 'device-activation' ,
99
- 'get-devices-id -activateOnResellerPlan' : 'device-activation' ,
100
-
101
- 'get-devices-id -messages' : 'device-misc' ,
102
- 'post-devices-id -messages' : 'device-misc' ,
103
- 'delete-devices-id -messages' : 'device-misc' ,
104
- 'get-devices-id -transients' : 'device-misc' ,
105
- 'get-devices-id -transients-fk ' : 'device-misc' ,
106
- 'get-devices-id -nearbyDevices' : 'device-misc' ,
107
- 'get-devices-id -nearbyDeviceData' : 'device-misc' ,
108
-
109
- 'get-devices-id -getRtkStatus' : 'rtk' ,
110
- 'get-devices-id -getRecentRtkLogs' : 'rtk' ,
111
- 'get-devices-id -getRtkCommand' : 'rtk' ,
112
- 'get-devices-id -queueRtkCmd-UpdateRateMs' : 'rtk' ,
113
- 'get-devices-id -queueRtkCmd-AlertNow' : 'rtk' ,
114
- 'get-devices-id -queueRtkCmd-AlertWithPrompt' : 'rtk' ,
115
- 'get-devices-id -queueRtkCmd-RebootRtk' : 'rtk' ,
116
- 'get-devices-id -queueRtkCmd-SetPointBufferSize' : 'rtk' ,
117
- 'get-devices-id -updateRtkBaseStatus' : 'rtk' ,
118
- 'get-devices-id -setNtripSettings' : 'rtk' ,
98
+ 'get-devices-{id} -deactivate' : 'device-activation' ,
99
+ 'get-devices-{id} -activateOnResellerPlan' : 'device-activation' ,
100
+
101
+ 'get-devices-{id} -messages' : 'device-misc' ,
102
+ 'post-devices-{id} -messages' : 'device-misc' ,
103
+ 'delete-devices-{id} -messages' : 'device-misc' ,
104
+ 'get-devices-{id} -transients' : 'device-misc' ,
105
+ 'get-devices-{id} -transients-{fk} ' : 'device-misc' ,
106
+ 'get-devices-{id} -nearbyDevices' : 'device-misc' ,
107
+ 'get-devices-{id} -nearbyDeviceData' : 'device-misc' ,
108
+
109
+ 'get-devices-{id} -getRtkStatus' : 'rtk' ,
110
+ 'get-devices-{id} -getRecentRtkLogs' : 'rtk' ,
111
+ 'get-devices-{id} -getRtkCommand' : 'rtk' ,
112
+ 'get-devices-{id} -queueRtkCmd-UpdateRateMs' : 'rtk' ,
113
+ 'get-devices-{id} -queueRtkCmd-AlertNow' : 'rtk' ,
114
+ 'get-devices-{id} -queueRtkCmd-AlertWithPrompt' : 'rtk' ,
115
+ 'get-devices-{id} -queueRtkCmd-RebootRtk' : 'rtk' ,
116
+ 'get-devices-{id} -queueRtkCmd-SetPointBufferSize' : 'rtk' ,
117
+ 'get-devices-{id} -updateRtkBaseStatus' : 'rtk' ,
118
+ 'get-devices-{id} -setNtripSettings' : 'rtk' ,
119
119
120
120
'get-devices-id' : 'device' ,
121
- 'get-users-id -devices' : 'device' ,
122
- 'get-users-id -getDeviceSummary' : 'device' ,
123
- 'get-users-id -getDevicesInZone' : 'device' ,
124
- 'get-users-id -getDevicesByTag' : 'device' ,
121
+ 'get-users-{id} -devices' : 'device' ,
122
+ 'get-users-{id} -getDeviceSummary' : 'device' ,
123
+ 'get-users-{id} -getDevicesInZone' : 'device' ,
124
+ 'get-users-{id} -getDevicesByTag' : 'device' ,
125
125
126
- 'get-devices-id -points-fk ' : 'points' ,
127
- 'get-devices-id -points' : 'points' ,
128
- 'delete-devices-id -points-fk ' : 'points' ,
126
+ 'get-devices-{id} -points-{fk} ' : 'points' ,
127
+ 'get-devices-{id} -points' : 'points' ,
128
+ 'delete-devices-{id} -points-{fk} ' : 'points' ,
129
129
130
- 'get-devices-id -readings-fk ' : 'readings' ,
131
- 'get-devices-id -readings' : 'readings' ,
132
- 'put-devices-id -gatewayReadings-fk ' : 'readings' ,
130
+ 'get-devices-{id} -readings-{fk} ' : 'readings' ,
131
+ 'get-devices-{id} -readings' : 'readings' ,
132
+ 'put-devices-{id} -gatewayReadings-{fk} ' : 'readings' ,
133
133
134
- 'get-devices-id -notificationTriggers-fk ' : 'notifications' ,
135
- 'delete-devices-id -notificationTriggers-fk ' : 'notifications' ,
136
- 'put-devices-id -notificationTriggers-fk ' : 'notifications' ,
137
- 'get-devices-id -notificationTriggers' : 'notifications' ,
138
- 'post-devices-id -notificationTriggers' : 'notifications' ,
139
- 'delete-devices-id -notificationTriggers' : 'notifications' ,
134
+ 'get-devices-{id} -notificationTriggers-{fk} ' : 'notifications' ,
135
+ 'delete-devices-{id} -notificationTriggers-{fk} ' : 'notifications' ,
136
+ 'put-devices-{id} -notificationTriggers-{fk} ' : 'notifications' ,
137
+ 'get-devices-{id} -notificationTriggers' : 'notifications' ,
138
+ 'post-devices-{id} -notificationTriggers' : 'notifications' ,
139
+ 'delete-devices-{id} -notificationTriggers' : 'notifications' ,
140
140
141
- 'get-users-id -geofences' : 'geofences' ,
142
- 'get-users-id -geofences-fk ' : 'geofences' ,
141
+ 'get-users-{id} -geofences' : 'geofences' ,
142
+ 'get-users-{id} -geofences-{fk} ' : 'geofences' ,
143
143
144
144
'post-reports-activity' : 'reports' ,
145
145
'post-reports-vehicle-summary' : 'reports' ,
146
146
}
147
147
148
148
const v1Removed = [
149
149
// At the time of writing the new docs site, this endpoint had been removed
150
- 'delete-devices-id -gatewayReadings-fk ' ,
151
- 'delete-devices-id -transients-fk ' ,
152
- 'put-devices-id -transients-fk ' ,
153
- 'get-devices-id -transients-fk ' ,
150
+ 'delete-devices-{id} -gatewayReadings-{fk} ' ,
151
+ 'delete-devices-{id} -transients-{fk} ' ,
152
+ 'put-devices-{id} -transients-{fk} ' ,
153
+ 'get-devices-{id} -transients-{fk} ' ,
154
154
]
155
155
156
156
const V1ParamExamples = {
157
- 'get-devices-id -points' : {
157
+ 'get-devices-{id} -points' : {
158
158
'filter' : [
159
159
'{"limit":10,"order":["timestamp DESC"]}' ,
160
160
'{"where":{"timestamp":{"between":["2024-12-01T00:00:00.000Z","2024-12-01T23:59:59.999Z"]}},"order":["timestamp DESC"]}' ,
161
161
] ,
162
162
} ,
163
- 'get-devices-id -activateOnResellerPlan' : {
163
+ 'get-devices-{id} -activateOnResellerPlan' : {
164
164
'id' : '56892' ,
165
165
'resellerPlanId' : '10' ,
166
166
'expiry' : [ Date . now ( ) + ( 365 * 24 * 60 * 60 * 1000 ) ]
167
167
} ,
168
- 'get-devices-id -readings' : {
168
+ 'get-devices-{id} -readings' : {
169
169
'filter' : [
170
170
'{"limit":10,"order":["timestamp DESC"]}' ,
171
171
'{"where":{"type":"temp"},"limit":10,"order":["timestamp DESC"]}' ,
@@ -175,7 +175,7 @@ const V1ParamExamples = {
175
175
}
176
176
177
177
const V1ResponseExamples = {
178
- 'get-users-id -getDeviceSummary' : {
178
+ 'get-users-{id} -getDeviceSummary' : {
179
179
'200' : {
180
180
'application/json' : {
181
181
'schema' : {
@@ -329,18 +329,18 @@ const V1BodyExamples = {
329
329
}
330
330
331
331
const V1ParamDescriptions = {
332
- 'get-devices-id -points' : {
332
+ 'get-devices-{id} -points' : {
333
333
'filter' : 'Filter criteria for fetching device points.' ,
334
334
} ,
335
- 'get-devices-id -activateOnResellerPlan' : {
335
+ 'get-devices-{id} -activateOnResellerPlan' : {
336
336
'id' : 'The ID of the device to activate.' ,
337
337
'resellerPlanId' : 'The ID of the reseller plan, which must relate to your reseller account.' ,
338
338
'expiry' : 'The expiry date for the activation in milliseconds since epoch. The device will be deactivated at this time.' ,
339
339
} ,
340
340
}
341
341
342
342
const V1ParamSchemaFormats = {
343
- 'get-devices-id -activateOnResellerPlan' : {
343
+ 'get-devices-{id} -activateOnResellerPlan' : {
344
344
'resellerPlanId' : 'integer' ,
345
345
} ,
346
346
}
@@ -371,15 +371,13 @@ export function loadSpec(version: number): any {
371
371
}
372
372
}
373
373
374
- spec1 . paths = normalizePaths ( spec1 . paths )
375
-
376
374
// override stuff
377
375
for ( const path of Object . keys ( spec1 . paths ) ) {
378
376
for ( const method of Object . keys ( spec1 . paths [ path ] ) ) {
379
- // opertaionId is method- path (with / replaced with - )
380
- let operationId = method + path . replace ( / \/ / g, '-' )
381
- // Replace _ with -
382
- operationId = operationId . replace ( / _ / g , '-' )
377
+ let normalizedOperationId = method + path . replace ( / \/ / g , '-' ) . replace ( / { / g , '' ) . replace ( / } / g , '' )
378
+ normalizedOperationId = normalizedOperationId . replace ( / _ / g, '-' )
379
+ spec1 . paths [ path ] [ method ] . operationId = normalizedOperationId
380
+ let operationId = spec1 . paths [ path ] [ method ] . operationId
383
381
if ( v1Removed . includes ( operationId ) ) {
384
382
delete spec1 . paths [ path ] [ method ]
385
383
continue
@@ -477,24 +475,15 @@ export function loadSpec(version: number): any {
477
475
if ( spec2 . servers ) {
478
476
spec2 . servers = spec2 . servers . filter ( ( server : any ) => ! server . url . includes ( 'localhost' ) )
479
477
}
480
- spec2 . paths = normalizePaths ( spec2 . paths )
478
+ // Add normalizedOperationId to each operation
479
+ for ( const path of Object . keys ( spec2 . paths ) ) {
480
+ for ( const method of Object . keys ( spec2 . paths [ path ] ) ) {
481
+ let normalizedOperationId = method + path . replace ( / \/ / g, '-' ) . replace ( / { / g, '' ) . replace ( / } / g, '' )
482
+ normalizedOperationId = normalizedOperationId . replace ( / _ / g, '-' )
483
+ spec2 . paths [ path ] [ method ] . operationId = normalizedOperationId
484
+ }
485
+ }
481
486
return spec2
482
487
}
483
488
return null
484
489
}
485
-
486
- // Normalize paths by removing { and } from the path
487
- function normalizePaths ( paths : any ) {
488
- for ( const path of Object . keys ( paths ) ) {
489
- // Remove { and } from the path
490
- const pathName = path . replace ( / { / g, '' ) . replace ( / } / g, '' )
491
- if ( pathName === path ) {
492
- continue // No change
493
- }
494
- // Replace the path with the new path
495
- paths [ pathName ] = paths [ path ]
496
- // Remove the old path
497
- delete paths [ path ]
498
- }
499
- return paths
500
- }
0 commit comments