Skip to content

Commit 70d7d87

Browse files
authored
Fix Interactive Map API (#490)
Fixed issues with generated by codegen APIs. Resolves: OLPSUP-16039 Signed-off-by: Oleksii Zubko <ext-oleksii.zubko@here.com>
1 parent 63fe76e commit 70d7d87

File tree

10 files changed

+807
-395
lines changed

10 files changed

+807
-395
lines changed

@here/olp-sdk-authentication/tslint.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"severity": "none"
2121
},
2222
"eofline": true,
23-
"forin": true,
23+
"forin": false,
2424
"import-blacklist": [
2525
true,
2626
"rxjs/Rx"
@@ -71,7 +71,7 @@
7171
"no-duplicate-super": true,
7272
"no-duplicate-switch-case": true,
7373
"no-empty": false,
74-
"no-empty-interface": true,
74+
"no-empty-interface": false,
7575
"no-eval": true,
7676
"no-for-in-array": true,
7777
"no-import-side-effect": true,

@here/olp-sdk-core/tslint.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"severity": "warn"
2121
},
2222
"eofline": true,
23-
"forin": true,
23+
"forin": false,
2424
"import-blacklist": [
2525
true,
2626
"rxjs/Rx"
@@ -71,7 +71,7 @@
7171
"no-duplicate-super": true,
7272
"no-duplicate-switch-case": true,
7373
"no-empty": false,
74-
"no-empty-interface": true,
74+
"no-empty-interface": false,
7575
"no-eval": true,
7676
"no-for-in-array": true,
7777
"no-import-side-effect": true,

@here/olp-sdk-dataservice-api/lib/RequestBuilder.ts

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export class UrlBuilder {
5858
url: string,
5959
separator: string,
6060
key: string,
61-
value: string | number | boolean | string[]
61+
value: string | number | boolean | string[] | number[]
6262
): string {
6363
url += separator;
6464
url += encodeURIComponent(key) + "=";
@@ -68,8 +68,13 @@ export class UrlBuilder {
6868
url += `${value}`;
6969
} else if (typeof value === "string") {
7070
url += encodeURIComponent(value);
71-
} else {
72-
url += value.map(val => encodeURIComponent(val)).join(",");
71+
} else if (Array.isArray(value)) {
72+
const encodedValues: string[] = [];
73+
value.forEach((val: string | number) => {
74+
encodedValues.push(encodeURIComponent(val));
75+
});
76+
77+
url += encodedValues.join(",");
7378
}
7479
return url;
7580
}
@@ -93,16 +98,41 @@ export class UrlBuilder {
9398
* @param key The key of the query parameter.
9499
* @param value The value of the query parameter.
95100
*/
96-
appendQuery(key: string, value?: string | number | boolean | string[]) {
101+
appendQuery(
102+
key: string,
103+
value?:
104+
| string
105+
| number
106+
| boolean
107+
| string[]
108+
| number[]
109+
| { [key: string]: string | number }
110+
) {
97111
if (value === undefined) {
98112
return;
99113
}
100-
this.url = UrlBuilder.appendQueryString(
101-
this.url,
102-
this.hasQuery ? "&" : "?",
103-
key,
104-
value
105-
);
114+
115+
if (value instanceof Object && !(value instanceof Array)) {
116+
let queryString = "";
117+
for (const propKey in value) {
118+
queryString += UrlBuilder.appendQueryString(
119+
"",
120+
this.hasQuery ? "&" : "?",
121+
propKey,
122+
value[propKey]
123+
);
124+
}
125+
126+
this.url += queryString;
127+
} else {
128+
this.url = UrlBuilder.appendQueryString(
129+
this.url,
130+
this.hasQuery ? "&" : "?",
131+
key,
132+
value
133+
);
134+
}
135+
106136
this.hasQuery = true;
107137
}
108138
}

@here/olp-sdk-dataservice-api/lib/interactive-api-v1.ts

Lines changed: 102 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,29 @@ export interface ApiVersion {
4040
apiVersion?: string;
4141
}
4242

43+
/**
44+
* True if the value is only an estimation; false otherwise.
45+
*/
46+
export type Estimated = boolean;
47+
48+
export type GetFeaturesBySpatialBody =
49+
| Feature
50+
| FeatureCollection
51+
| Geometry
52+
| LineString
53+
| MultiLineString
54+
| MultiPoint
55+
| MultiPolygon
56+
| Point
57+
| Polygon;
58+
4359
export interface Feature extends GeoJSON {
4460
/**
4561
* The unique identifier of the feature.
4662
*/
4763
id?: string;
48-
geometry?: GeoJSON;
64+
geometry?: Geometry;
4965
properties?: { [key: string]: any };
50-
features?: Array<Feature>;
5166
}
5267

5368
export interface FeatureCollection extends GeoJSON {
@@ -92,21 +107,45 @@ export interface GeoJSON {
92107
* Describes the coordinate range of the GeoJSON object.
93108
*/
94109
bbox?: Array<number>;
95-
coordinates?:
96-
| LineString
97-
| MultiLineString
98-
| MultiPoint
99-
| MultiPolygon
100-
| Point
101-
| Polygon;
102110
}
103111

104-
export type LineString = Array<Array<number>>;
105-
export type MultiLineString = Array<Array<Array<number>>>;
106-
export type MultiPoint = Array<Array<number>>;
107-
export type MultiPolygon = Array<Array<Array<Array<number>>>>;
108-
export type Point = Array<number>;
109-
export type Polygon = Array<Array<Array<number>>>;
112+
/**
113+
* A Geometry object represents points, curves, and surfaces in coordinate layer.
114+
*/
115+
export interface Geometry extends GeoJSON {}
116+
117+
export interface LineString extends Geometry {
118+
coordinates?: Array<Array<number>>;
119+
}
120+
121+
export interface ModelError {
122+
title?: string;
123+
status?: number;
124+
code?: string;
125+
cause?: string;
126+
action?: string;
127+
correlationId?: string;
128+
}
129+
130+
export interface MultiLineString extends Geometry {
131+
coordinates?: Array<Array<Array<number>>>;
132+
}
133+
134+
export interface MultiPoint extends Geometry {
135+
coordinates?: Array<Array<number>>;
136+
}
137+
138+
export interface MultiPolygon extends Geometry {
139+
coordinates?: Array<Array<Array<Array<number>>>>;
140+
}
141+
142+
export interface Point extends Geometry {
143+
coordinates?: Array<number>;
144+
}
145+
146+
export interface Polygon extends Geometry {
147+
coordinates?: Array<Array<Array<number>>>;
148+
}
110149

111150
export interface Statistics {
112151
count?: StatisticsCount;
@@ -120,22 +159,22 @@ export interface Statistics {
120159

121160
export interface StatisticsBbox {
122161
value?: Array<number>;
123-
estimated?: boolean;
162+
estimated?: Estimated;
124163
}
125164

126165
export interface StatisticsCount {
127166
value?: number;
128-
estimated?: boolean;
167+
estimated?: Estimated;
129168
}
130169

131170
export interface StatisticsGeometryTypes {
132171
value?: Array<string>;
133-
estimated?: boolean;
172+
estimated?: Estimated;
134173
}
135174

136175
export interface StatisticsProperties {
137176
value?: Array<StatisticsPropertiesValue>;
138-
estimated?: boolean;
177+
estimated?: Estimated;
139178
}
140179

141180
export interface StatisticsPropertiesValue {
@@ -146,7 +185,7 @@ export interface StatisticsPropertiesValue {
146185

147186
export interface StatisticsTags {
148187
value?: Array<StatisticsTagsValue>;
149-
estimated?: boolean;
188+
estimated?: Estimated;
150189
}
151190

152191
export interface StatisticsTagsValue {
@@ -212,7 +251,7 @@ export async function getFeature(
212251
params: {
213252
layerId: string;
214253
featureId: string;
215-
selection?: string;
254+
selection?: string | Array<string>;
216255
force2D?: boolean;
217256
}
218257
): Promise<Feature> {
@@ -257,8 +296,8 @@ export async function getFeatures(
257296
builder: RequestBuilder,
258297
params: {
259298
layerId: string;
260-
id: string;
261-
selection?: string;
299+
id: string | string[];
300+
selection?: string | Array<string>;
262301
force2D?: boolean;
263302
}
264303
): Promise<FeatureCollection> {
@@ -389,14 +428,14 @@ export async function getFeaturesByBBox(
389428
builder: RequestBuilder,
390429
params: {
391430
layerId: string;
392-
bbox?: string;
431+
bbox?: Array<number>;
393432
clip?: boolean;
394433
limit?: number;
395-
params?: string;
396-
selection?: string;
434+
params?: { [key: string]: string | number };
435+
selection?: string | Array<string>;
397436
skipCache?: boolean;
398437
clustering?: string;
399-
clusteringParams?: string;
438+
clusteringParams?: { [key: string]: string | number };
400439
force2D?: boolean;
401440
}
402441
): Promise<FeatureCollection> {
@@ -407,14 +446,23 @@ export async function getFeaturesByBBox(
407446

408447
const urlBuilder = new UrlBuilder(builder.baseUrl + baseUrl);
409448
urlBuilder.appendQuery("bbox", params["bbox"]);
410-
urlBuilder.appendQuery("clip", "true");
449+
urlBuilder.appendQuery("clip", params["clip"]);
411450
urlBuilder.appendQuery("limit", params["limit"]);
412451
urlBuilder.appendQuery("params", params["params"]);
413452
urlBuilder.appendQuery("selection", params["selection"]);
414-
urlBuilder.appendQuery("skipCache", "true");
453+
urlBuilder.appendQuery("skipCache", params["skipCache"]);
415454
urlBuilder.appendQuery("clustering", params["clustering"]);
416-
urlBuilder.appendQuery("clusteringParams", params["clusteringParams"]);
417-
urlBuilder.appendQuery("force2D", "true");
455+
456+
if (params["clusteringParams"]) {
457+
for (const clusteringParam in params["clusteringParams"]) {
458+
urlBuilder.appendQuery(
459+
`clustering.${clusteringParam}`,
460+
params["clusteringParams"][clusteringParam]
461+
);
462+
}
463+
}
464+
465+
urlBuilder.appendQuery("force2D", params["force2D"]);
418466

419467
const headers: { [header: string]: string } = {};
420468
const options: RequestOptions = {
@@ -509,8 +557,8 @@ export async function getFeaturesBySpatial(
509557
refFeatureId?: string;
510558
radius?: number;
511559
limit?: number;
512-
params?: string;
513-
selection?: string;
560+
params?: { [key: string]: string | number };
561+
selection?: string | Array<string>;
514562
skipCache?: boolean;
515563
force2D?: boolean;
516564
}
@@ -606,11 +654,11 @@ export async function getFeaturesBySpatialPost(
606654
builder: RequestBuilder,
607655
params: {
608656
layerId: string;
609-
body?: GeoJSON;
657+
body?: GetFeaturesBySpatialBody;
610658
radius?: number;
611659
limit?: number;
612-
params?: string;
613-
selection?: string;
660+
params?: { [key: string]: string | number };
661+
selection?: string | Array<string>;
614662
skipCache?: boolean;
615663
force2D?: boolean;
616664
}
@@ -760,11 +808,11 @@ export async function getFeaturesByTile(
760808
tileType: string;
761809
tileId: string;
762810
clip?: boolean;
763-
params?: string;
764-
selection?: string;
811+
params?: { [key: string]: string | number };
812+
selection?: string | Array<string>;
765813
skipCache?: boolean;
766814
clustering?: string;
767-
clusteringParams?: string;
815+
clusteringParams?: { [key: string]: string | number };
768816
margin?: number;
769817
limit?: number;
770818
force2D?: boolean;
@@ -782,7 +830,16 @@ export async function getFeaturesByTile(
782830
urlBuilder.appendQuery("selection", params["selection"]);
783831
urlBuilder.appendQuery("skipCache", params["skipCache"]);
784832
urlBuilder.appendQuery("clustering", params["clustering"]);
785-
urlBuilder.appendQuery("clusteringParams", params["clusteringParams"]);
833+
834+
if (params["clusteringParams"]) {
835+
for (const clusteringParam in params["clusteringParams"]) {
836+
urlBuilder.appendQuery(
837+
`clustering.${clusteringParam}`,
838+
params["clusteringParams"][clusteringParam]
839+
);
840+
}
841+
}
842+
786843
urlBuilder.appendQuery("margin", params["margin"]);
787844
urlBuilder.appendQuery("limit", params["limit"]);
788845
urlBuilder.appendQuery("force2D", params["force2D"]);
@@ -857,7 +914,7 @@ export async function iterateFeatures(
857914
layerId: string;
858915
limit?: number;
859916
pageToken?: string;
860-
selection?: string;
917+
selection?: string | Array<string>;
861918
skipCache?: boolean;
862919
force2D?: boolean;
863920
}
@@ -943,8 +1000,8 @@ export async function searchFeatures(
9431000
params: {
9441001
layerId: string;
9451002
limit?: number;
946-
params?: string;
947-
selection?: string;
1003+
params?: { [key: string]: string | number };
1004+
selection?: string | Array<string>;
9481005
skipCache?: boolean;
9491006
force2D?: boolean;
9501007
}
@@ -959,8 +1016,8 @@ export async function searchFeatures(
9591016
urlBuilder.appendQuery("limit", params["limit"]);
9601017
urlBuilder.appendQuery("params", params["params"]);
9611018
urlBuilder.appendQuery("selection", params["selection"]);
962-
urlBuilder.appendQuery("skipCache", "true");
963-
urlBuilder.appendQuery("force2D", "true");
1019+
urlBuilder.appendQuery("skipCache", params["skipCache"]);
1020+
urlBuilder.appendQuery("force2D", params["force2D"]);
9641021

9651022
const headers: { [header: string]: string } = {};
9661023
const options: RequestOptions = {

0 commit comments

Comments
 (0)