Skip to content

Commit 955c842

Browse files
wip
1 parent 64f7bee commit 955c842

File tree

6 files changed

+86
-46
lines changed

6 files changed

+86
-46
lines changed

server/Format.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
export enum Format {
22
Json = 'json',
33
Flatbuffers = 'flatbuffers'
4-
}
4+
}

server/ServiceHandler.js

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,9 @@ class ServiceHandler {
3131
if (query.steps) {
3232
options.steps = query.steps;
3333
}
34+
// TODO: annotations is per-service option
3435
if (query.annotations) {
35-
let annotations;
36-
if (query.annotations === 'true') {
37-
annotations = true;
38-
}
39-
else if (typeof query.annotations === 'string') {
40-
annotations = query.annotations.split(',');
41-
}
42-
options.annotations = annotations;
36+
options.annotations = query.annotations;
4337
}
4438
if (query.exclude) {
4539
options.exclude = query.exclude;

server/ServiceHandler.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,9 @@ import {OSRMWrapper} from "./OSRMWrapper";
4444
options.steps = query.steps;
4545
}
4646

47-
47+
// TODO: annotations is per-service option
4848
if (query.annotations) {
49-
let annotations;
50-
if (query.annotations === 'true') {
51-
annotations = true;
52-
} else if (typeof query.annotations === 'string') {
53-
annotations = query.annotations.split(',');
54-
}
55-
options.annotations = annotations;
49+
options.annotations = query.annotations;
5650
}
5751

5852
if (query.exclude) {

server/schema.js

Lines changed: 39 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,22 @@
22
Object.defineProperty(exports, "__esModule", { value: true });
33
exports.parseQueryString = exports.tileSchema = exports.tripSchema = exports.matchSchema = exports.tableSchema = exports.nearestSchema = exports.routeSchema = void 0;
44
const querystring = require('querystring');
5+
function makeAnnotationsSchema(allowedAnnotations) {
6+
return {
7+
oneOf: [
8+
{
9+
type: 'array',
10+
items: {
11+
enum: allowedAnnotations
12+
}
13+
},
14+
{
15+
type: 'boolean'
16+
}
17+
],
18+
default: false
19+
};
20+
}
521
const queryStringJsonSchemaGeneral = {
622
type: 'object',
723
properties: {
@@ -18,10 +34,12 @@ const queryStringJsonSchemaGeneral = {
1834
},
1935
radiuses: {
2036
type: 'array',
21-
oneOf: [
22-
{ type: 'number', exclusiveMinimum: 0 },
23-
{ enum: ['unlimited'] }
24-
]
37+
items: {
38+
oneOf: [
39+
{ type: 'number', exclusiveMinimum: 0 },
40+
{ enum: ['unlimited'] }
41+
]
42+
}
2543
},
2644
generate_hints: { type: 'boolean', default: true },
2745
hints: {
@@ -50,16 +68,17 @@ const queryStringJsonSchemaGeneral = {
5068
skip_waypoints: { type: 'boolean', default: false },
5169
}
5270
};
71+
// annotations_type.add("duration", AnnotationsType::Duration)("nodes",
72+
// AnnotationsType::Nodes)(
73+
// "distance", AnnotationsType::Distance)("weight", AnnotationsType::Weight)(
74+
// "datasources", AnnotationsType::Datasources)("speed", AnnotationsType::Speed);
5375
const queryStringJsonSchemaRoute = {
5476
type: 'object',
5577
properties: {
5678
...queryStringJsonSchemaGeneral.properties,
5779
alternatives: { type: ['boolean', 'integer'], default: false },
5880
steps: { type: 'boolean', default: false },
59-
annotations: {
60-
type: 'string',
61-
// TODO: pattern
62-
},
81+
annotations: makeAnnotationsSchema(['duration', 'nodes', 'distance', 'weight', 'datasources', 'speed']),
6382
geometries: {
6483
enum: ['polyline', 'polyline6', 'geojson'],
6584
default: 'polyline'
@@ -120,8 +139,11 @@ const queryStringJsonSchemaTable = {
120139
]
121140
},
122141
annotations: {
123-
type: 'string',
124-
// TODO: pattern
142+
type: 'array',
143+
items: {
144+
enum: ['duration', 'distance'],
145+
default: 'duration'
146+
}
125147
},
126148
fallback_speed: {
127149
type: 'number',
@@ -167,6 +189,7 @@ const queryStringJsonSchemaMatch = {
167189
type: 'integer'
168190
}
169191
},
192+
annotations: makeAnnotationsSchema(['duration', 'nodes', 'distance', 'weight', 'datasources', 'speed'])
170193
}
171194
};
172195
const queryStringJsonSchemaTrip = {
@@ -182,10 +205,7 @@ const queryStringJsonSchemaTrip = {
182205
enum: ['any', 'last'],
183206
default: 'any'
184207
},
185-
annotations: {
186-
type: 'string',
187-
// TODO: pattern
188-
},
208+
annotations: makeAnnotationsSchema(['duration', 'nodes', 'distance', 'weight', 'datasources', 'speed']),
189209
steps: { type: 'boolean', default: false },
190210
geometries: {
191211
enum: ['polyline', 'polyline6', 'geojson'],
@@ -258,6 +278,11 @@ function parseQueryString(queryString) {
258278
if ('bearings' in parsed) {
259279
parsed['bearings'] = parseArray(parsed['bearings'], ';').map(bearingWithRange => { parseArray(bearingWithRange, ','); });
260280
}
281+
if ('annotations' in parsed) {
282+
if (!['true', 'false'].includes(parsed['annotations'])) {
283+
parsed['annotations'] = parseArray(parsed['annotations'], ',');
284+
}
285+
}
261286
return parsed;
262287
}
263288
exports.parseQueryString = parseQueryString;

server/schema.ts

Lines changed: 42 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,22 @@
11
const querystring = require('querystring');
22

3+
function makeAnnotationsSchema(allowedAnnotations: string[]): any {
4+
return {
5+
oneOf: [
6+
{
7+
type: 'array',
8+
items: {
9+
enum: allowedAnnotations
10+
}
11+
},
12+
{
13+
type: 'boolean'
14+
}
15+
],
16+
default: false
17+
}
18+
}
19+
320
const queryStringJsonSchemaGeneral = {
421
type: 'object',
522
properties: {
@@ -16,10 +33,12 @@ const queryStringJsonSchemaGeneral = {
1633
},
1734
radiuses: {
1835
type: 'array',
19-
oneOf: [
20-
{type: 'number', exclusiveMinimum: 0},
21-
{enum: ['unlimited']}
22-
]
36+
items: {
37+
oneOf: [
38+
{type: 'number', exclusiveMinimum: 0},
39+
{enum: ['unlimited']}
40+
]
41+
}
2342
},
2443
generate_hints: { type: 'boolean', default: true },
2544
hints: {
@@ -49,16 +68,18 @@ const queryStringJsonSchemaGeneral = {
4968
}
5069
};
5170

71+
// annotations_type.add("duration", AnnotationsType::Duration)("nodes",
72+
// AnnotationsType::Nodes)(
73+
// "distance", AnnotationsType::Distance)("weight", AnnotationsType::Weight)(
74+
// "datasources", AnnotationsType::Datasources)("speed", AnnotationsType::Speed);
75+
5276
const queryStringJsonSchemaRoute = {
5377
type: 'object',
5478
properties: {
5579
...queryStringJsonSchemaGeneral.properties,
5680
alternatives: { type: ['boolean', 'integer'], default: false },
5781
steps: { type: 'boolean', default: false },
58-
annotations: {
59-
type: 'string',
60-
// TODO: pattern
61-
},
82+
annotations: makeAnnotationsSchema(['duration', 'nodes', 'distance', 'weight', 'datasources', 'speed']),
6283
geometries: {
6384
enum: ['polyline', 'polyline6', 'geojson'],
6485
default: 'polyline'
@@ -123,8 +144,11 @@ const queryStringJsonSchemaTable = {
123144

124145
},
125146
annotations: {
126-
type: 'string',
127-
// TODO: pattern
147+
type: 'array',
148+
items: {
149+
enum: ['duration', 'distance'],
150+
default: 'duration'
151+
}
128152
},
129153
fallback_speed: {
130154
type: 'number',
@@ -174,6 +198,7 @@ const queryStringJsonSchemaMatch = {
174198
type: 'integer'
175199
}
176200
},
201+
annotations: makeAnnotationsSchema(['duration', 'nodes', 'distance', 'weight', 'datasources', 'speed'])
177202
}
178203
}
179204

@@ -191,10 +216,8 @@ const queryStringJsonSchemaTrip = {
191216
enum: ['any', 'last'],
192217
default: 'any'
193218
},
194-
annotations: {
195-
type: 'string',
196-
// TODO: pattern
197-
},
219+
220+
annotations: makeAnnotationsSchema(['duration', 'nodes', 'distance', 'weight', 'datasources', 'speed']),
198221
steps: { type: 'boolean', default: false },
199222
geometries: {
200223
enum: ['polyline', 'polyline6', 'geojson'],
@@ -276,6 +299,11 @@ export function parseQueryString(queryString: string): any {
276299
if ('bearings' in parsed) {
277300
parsed['bearings'] = parseArray(parsed['bearings'], ';').map(bearingWithRange => { parseArray(bearingWithRange, ',') });
278301
}
302+
if ('annotations' in parsed) {
303+
if (!['true', 'false'].includes(parsed['annotations'])) {
304+
parsed['annotations'] = parseArray(parsed['annotations'], ',');
305+
}
306+
}
279307

280308
return parsed;
281309
}

server/server.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ async function main() {
3535
.alias('h', 'help')
3636
.argv;
3737
if (argv.version) {
38-
console.log(argv.max_viaroute_size);
3938
// TODO: print real version
4039
process.stdout.write('v5.27.0\n');
4140
return;

0 commit comments

Comments
 (0)