Skip to content

Commit 33af697

Browse files
wip
1 parent 03ec6de commit 33af697

File tree

4 files changed

+119
-52
lines changed

4 files changed

+119
-52
lines changed

server/schema.js

Lines changed: 47 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,11 @@ const queryStringJsonSchemaGeneral = {
1717
}
1818
},
1919
radiuses: {
20-
type: 'string',
21-
// TODO: pattern
20+
type: 'array',
21+
oneOf: [
22+
{ type: 'number', exclusiveMinimum: 0 },
23+
{ enum: ['unlimited'] }
24+
]
2225
},
2326
generate_hints: { type: 'boolean', default: true },
2427
hints: {
@@ -28,12 +31,17 @@ const queryStringJsonSchemaGeneral = {
2831
}
2932
},
3033
approaches: {
31-
type: 'string',
32-
// TODO: pattern
34+
type: 'array',
35+
items: {
36+
// TODO: default?
37+
enum: ['curb', 'unrestricted']
38+
}
3339
},
3440
exclude: {
35-
type: 'string',
36-
// TODO: pattern
41+
type: 'array',
42+
items: {
43+
type: 'string'
44+
}
3745
},
3846
snapping: {
3947
enum: ['any', 'default'],
@@ -83,17 +91,33 @@ const queryStringJsonSchemaTable = {
8391
type: 'object',
8492
properties: {
8593
...queryStringJsonSchemaGeneral.properties,
86-
// TODO: all
8794
sources: {
88-
type: 'string',
89-
// list of numbers separated by semicolon
90-
pattern: '^(\\d+(;\\d+)*)?$'
95+
oneOf: [
96+
{
97+
type: 'array',
98+
items: {
99+
type: 'integer',
100+
minimum: 0
101+
}
102+
},
103+
{
104+
enum: ['all']
105+
}
106+
]
91107
},
92-
// TODO: all
93108
destinations: {
94-
type: 'string',
95-
// list of numbers separated by semicolon
96-
pattern: '^(\\d+(;\\d+)*)?$'
109+
oneOf: [
110+
{
111+
type: 'array',
112+
items: {
113+
type: 'integer',
114+
minimum: 0
115+
}
116+
},
117+
{
118+
enum: ['all']
119+
}
120+
]
97121
},
98122
annotations: {
99123
type: 'string',
@@ -213,9 +237,18 @@ function parseQueryString(queryString) {
213237
if ('timestamps' in parsed) {
214238
parsed['timestamps'] = parseArray(parsed['timestamps'], ';');
215239
}
240+
if ('approaches' in parsed) {
241+
parsed['approaches'] = parseArray(parsed['approaches'], ';');
242+
}
216243
if ('waypoints' in parsed) {
217244
parsed['waypoints'] = parseArray(parsed['waypoints'], ';');
218245
}
246+
if ('sources' in parsed && parsed['sources'] !== 'all') {
247+
parsed['sources'] = parseArray(parsed['sources'], ';');
248+
}
249+
if ('destinations' in parsed && parsed['destinations'] !== 'all') {
250+
parsed['destinations'] = parseArray(parsed['destinations'], ';');
251+
}
219252
if ('hints' in parsed) {
220253
parsed['hints'] = parseArray(parsed['hints'], ';');
221254
}

server/schema.ts

Lines changed: 50 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,11 @@ const queryStringJsonSchemaGeneral = {
1515
}
1616
},
1717
radiuses: {
18-
type: 'string',
19-
// TODO: pattern
18+
type: 'array',
19+
oneOf: [
20+
{type: 'number', exclusiveMinimum: 0},
21+
{enum: ['unlimited']}
22+
]
2023
},
2124
generate_hints: { type: 'boolean', default: true },
2225
hints: {
@@ -26,12 +29,17 @@ const queryStringJsonSchemaGeneral = {
2629
}
2730
},
2831
approaches: {
29-
type: 'string',
30-
// TODO: pattern
32+
type: 'array',
33+
items: {
34+
// TODO: default?
35+
enum: ['curb', 'unrestricted']
36+
}
3137
},
3238
exclude: {
33-
type: 'string',
34-
// TODO: pattern
39+
type: 'array',
40+
items: {
41+
type: 'string'
42+
}
3543
},
3644
snapping: {
3745
enum: ['any', 'default'],
@@ -84,17 +92,35 @@ const queryStringJsonSchemaTable = {
8492
type: 'object',
8593
properties: {
8694
...queryStringJsonSchemaGeneral.properties,
87-
// TODO: all
8895
sources: {
89-
type: 'string',
90-
// list of numbers separated by semicolon
91-
pattern: '^(\\d+(;\\d+)*)?$'
96+
oneOf: [
97+
{
98+
type: 'array',
99+
items: {
100+
type: 'integer',
101+
minimum: 0
102+
}
103+
},
104+
{
105+
enum: ['all']
106+
}
107+
]
108+
92109
},
93-
// TODO: all
94110
destinations: {
95-
type: 'string',
96-
// list of numbers separated by semicolon
97-
pattern: '^(\\d+(;\\d+)*)?$'
111+
oneOf: [
112+
{
113+
type: 'array',
114+
items: {
115+
type: 'integer',
116+
minimum: 0
117+
}
118+
},
119+
{
120+
enum: ['all']
121+
}
122+
]
123+
98124
},
99125
annotations: {
100126
type: 'string',
@@ -229,9 +255,18 @@ export function parseQueryString(queryString: string): any {
229255
if ('timestamps' in parsed) {
230256
parsed['timestamps'] = parseArray(parsed['timestamps'], ';');
231257
}
258+
if ('approaches' in parsed) {
259+
parsed['approaches'] = parseArray(parsed['approaches'], ';');
260+
}
232261
if ('waypoints' in parsed) {
233262
parsed['waypoints'] = parseArray(parsed['waypoints'], ';');
234263
}
264+
if ('sources' in parsed && parsed['sources'] !== 'all') {
265+
parsed['sources'] = parseArray(parsed['sources'], ';');
266+
}
267+
if ('destinations' in parsed && parsed['destinations'] !== 'all') {
268+
parsed['destinations'] = parseArray(parsed['destinations'], ';');
269+
}
235270
if ('hints' in parsed) {
236271
parsed['hints'] = parseArray(parsed['hints'], ';');
237272
}
@@ -241,5 +276,6 @@ export function parseQueryString(queryString: string): any {
241276
if ('bearings' in parsed) {
242277
parsed['bearings'] = parseArray(parsed['bearings'], ';').map(bearingWithRange => { parseArray(bearingWithRange, ',') });
243278
}
279+
244280
return parsed;
245281
}

server/server.js

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -109,22 +109,21 @@ async function handleTable(osrm, coordinates, query, format) {
109109
};
110110
handleCommonParams(query, options, format);
111111
if (query.scale_factor) {
112-
options.scale_factor = parseFloat(query.scale_factor);
112+
options.scale_factor = query.scale_factor;
113113
}
114114
if (query.fallback_coordinate) {
115115
options.fallback_coordinate = query.fallback_coordinate;
116116
}
117117
if (query.fallback_speed) {
118-
options.fallback_speed = parseFloat(query.fallback_speed);
118+
options.fallback_speed = query.fallback_speed;
119119
}
120-
if (query.sources) {
121-
options.sources = query.sources.split(';').map((t) => parseInt(t));
120+
if (query.sources && query.sources !== 'all') {
121+
options.sources = query.sources;
122122
}
123-
if (query.destinations) {
124-
options.destinations = query.destinations.split(';').map((t) => parseInt(t));
123+
if (query.destinations && query.destinations !== 'all') {
124+
options.destinations = query.destinations;
125125
}
126-
const res = await table(osrm, options);
127-
return res;
126+
return table(osrm, options);
128127
}
129128
function handleCommonParams(query, options, format) {
130129
options.format = format;
@@ -154,11 +153,11 @@ function handleCommonParams(query, options, format) {
154153
options.snapping = query.snapping;
155154
}
156155
if (query.radiuses) {
157-
options.radiuses = query.radiuses.split(';').map((t) => {
158-
if (t === 'unlimited') {
156+
options.radiuses = query.radiuses.map((r) => {
157+
if (r === 'unlimited') {
159158
return null;
160159
}
161-
return parseFloat(t);
160+
return r;
162161
});
163162
}
164163
if (query.bearings) {
@@ -223,7 +222,7 @@ async function handleRoute(osrm, coordinates, query, format) {
223222
options.alternatives = query.alternatives;
224223
}
225224
if (query.approaches) {
226-
options.approaches = query.approaches.split(';');
225+
options.approaches = query.approaches;
227226
}
228227
if (query.waypoints) {
229228
options.waypoints = query.waypoints;

server/server.ts

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -109,22 +109,21 @@ async function handleTable(osrm: any, coordinates: [number, number][], query: an
109109
};
110110
handleCommonParams(query, options, format);
111111
if (query.scale_factor) {
112-
options.scale_factor = parseFloat(query.scale_factor);
112+
options.scale_factor = query.scale_factor;
113113
}
114114
if (query.fallback_coordinate) {
115115
options.fallback_coordinate = query.fallback_coordinate;
116116
}
117117
if (query.fallback_speed) {
118-
options.fallback_speed = parseFloat(query.fallback_speed);
118+
options.fallback_speed = query.fallback_speed;
119119
}
120-
if (query.sources) {
121-
options.sources = query.sources.split(';').map((t: string) => parseInt(t));
120+
if (query.sources && query.sources !== 'all') {
121+
options.sources = query.sources;
122122
}
123-
if (query.destinations) {
124-
options.destinations = query.destinations.split(';').map((t: string) => parseInt(t));
123+
if (query.destinations && query.destinations !== 'all') {
124+
options.destinations = query.destinations;
125125
}
126-
const res = await table(osrm, options);
127-
return res;
126+
return table(osrm, options);
128127
}
129128

130129
function handleCommonParams(query: any, options: any, format: Format) {
@@ -162,11 +161,11 @@ function handleCommonParams(query: any, options: any, format: Format) {
162161
}
163162

164163
if (query.radiuses) {
165-
options.radiuses = query.radiuses.split(';').map((t: string) => {
166-
if (t === 'unlimited') {
164+
options.radiuses = query.radiuses.map((r: string | 'unlimited') => {
165+
if (r === 'unlimited') {
167166
return null;
168167
}
169-
return parseFloat(t);
168+
return r;
170169
});
171170
}
172171

@@ -245,7 +244,7 @@ async function handleRoute(osrm: any, coordinates: [number, number][], query: an
245244
options.alternatives = query.alternatives;
246245
}
247246
if (query.approaches) {
248-
options.approaches = query.approaches.split(';');
247+
options.approaches = query.approaches;
249248
}
250249

251250
if (query.waypoints) {

0 commit comments

Comments
 (0)