Skip to content

Commit e3e4813

Browse files
committed
Fix in path params in api try it
1 parent 9b328b2 commit e3e4813

File tree

1 file changed

+116
-127
lines changed

1 file changed

+116
-127
lines changed

swagger/load.ts

+116-127
Original file line numberDiff line numberDiff line change
@@ -3,169 +3,169 @@ import spec2 from '../public/swagger/v2.json' with { type: 'json' }
33

44
const v1SummaryOverrides = {
55
'post-users-login': 'Login',
6-
'get-users-id-getMqttCredentials': 'MQTT Credentials',
6+
'get-users-{id}-getMqttCredentials': 'MQTT Credentials',
77
// 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',
1111
// 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',
1515

1616
// device
1717
'get-devices-id': 'Get device',
18-
'get-users-id-getDeviceSummary': 'Summary of devices',
18+
'get-users-{id}-getDeviceSummary': 'Summary of devices',
1919
'post-devices-changeTags': 'Change tags for a device',
2020

2121
// 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',
2525

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',
2828

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',
3333

3434
// 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',
4141
// 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',
4848

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',
5151

52-
'get-devices-id-setNtripSettings': 'Set the NTRIP settings for a device.',
52+
'get-devices-{id}-setNtripSettings': 'Set the NTRIP settings for a device.',
5353

5454
'post-reports-activity': 'Device Activity',
5555
'post-reports-vehicle-summary': 'Vehicle Summary',
5656
}
5757

5858
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).",
6666
}
6767

6868
const v1Deprecated = [
69-
'get-devices-id-transients-fk',
69+
'get-devices-{id}-transients-{fk}',
7070
]
7171

7272
const v1ReTag = {
7373
'post-users-login': 'authentication',
7474

7575
// Keep the MQTT in its own section, near the bottom
76-
'get-users-id-getMqttCredentials': 'mqtt',
76+
'get-users-{id}-getMqttCredentials': 'mqtt',
7777

7878
// 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',
8383

8484
// 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',
8787

8888
// 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',
9696

9797
// 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',
119119

120120
'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',
125125

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',
129129

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',
133133

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',
140140

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',
143143

144144
'post-reports-activity': 'reports',
145145
'post-reports-vehicle-summary': 'reports',
146146
}
147147

148148
const v1Removed = [
149149
// 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}',
154154
]
155155

156156
const V1ParamExamples = {
157-
'get-devices-id-points': {
157+
'get-devices-{id}-points': {
158158
'filter': [
159159
'{"limit":10,"order":["timestamp DESC"]}',
160160
'{"where":{"timestamp":{"between":["2024-12-01T00:00:00.000Z","2024-12-01T23:59:59.999Z"]}},"order":["timestamp DESC"]}',
161161
],
162162
},
163-
'get-devices-id-activateOnResellerPlan': {
163+
'get-devices-{id}-activateOnResellerPlan': {
164164
'id': '56892',
165165
'resellerPlanId': '10',
166166
'expiry': [Date.now() + (365 * 24 * 60 * 60 * 1000)]
167167
},
168-
'get-devices-id-readings': {
168+
'get-devices-{id}-readings': {
169169
'filter': [
170170
'{"limit":10,"order":["timestamp DESC"]}',
171171
'{"where":{"type":"temp"},"limit":10,"order":["timestamp DESC"]}',
@@ -175,7 +175,7 @@ const V1ParamExamples = {
175175
}
176176

177177
const V1ResponseExamples = {
178-
'get-users-id-getDeviceSummary': {
178+
'get-users-{id}-getDeviceSummary': {
179179
'200': {
180180
'application/json': {
181181
'schema': {
@@ -329,18 +329,18 @@ const V1BodyExamples = {
329329
}
330330

331331
const V1ParamDescriptions = {
332-
'get-devices-id-points': {
332+
'get-devices-{id}-points': {
333333
'filter': 'Filter criteria for fetching device points.',
334334
},
335-
'get-devices-id-activateOnResellerPlan': {
335+
'get-devices-{id}-activateOnResellerPlan': {
336336
'id': 'The ID of the device to activate.',
337337
'resellerPlanId': 'The ID of the reseller plan, which must relate to your reseller account.',
338338
'expiry': 'The expiry date for the activation in milliseconds since epoch. The device will be deactivated at this time.',
339339
},
340340
}
341341

342342
const V1ParamSchemaFormats = {
343-
'get-devices-id-activateOnResellerPlan': {
343+
'get-devices-{id}-activateOnResellerPlan': {
344344
'resellerPlanId': 'integer',
345345
},
346346
}
@@ -371,15 +371,13 @@ export function loadSpec(version: number): any {
371371
}
372372
}
373373

374-
spec1.paths = normalizePaths(spec1.paths)
375-
376374
// override stuff
377375
for (const path of Object.keys(spec1.paths)) {
378376
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
383381
if (v1Removed.includes(operationId)) {
384382
delete spec1.paths[path][method]
385383
continue
@@ -477,24 +475,15 @@ export function loadSpec(version: number): any {
477475
if (spec2.servers) {
478476
spec2.servers = spec2.servers.filter((server: any) => !server.url.includes('localhost'))
479477
}
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+
}
481486
return spec2
482487
}
483488
return null
484489
}
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

Comments
 (0)