Skip to content

Commit

Permalink
Fix Interactive Map API (#490)
Browse files Browse the repository at this point in the history
Fixed issues with  generated by codegen APIs.

Resolves: OLPSUP-16039

Signed-off-by: Oleksii Zubko <ext-oleksii.zubko@here.com>
  • Loading branch information
OleksiiZubko committed Sep 13, 2021
1 parent 63fe76e commit 70d7d87
Show file tree
Hide file tree
Showing 10 changed files with 807 additions and 395 deletions.
4 changes: 2 additions & 2 deletions @here/olp-sdk-authentication/tslint.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"severity": "none"
},
"eofline": true,
"forin": true,
"forin": false,
"import-blacklist": [
true,
"rxjs/Rx"
Expand Down Expand Up @@ -71,7 +71,7 @@
"no-duplicate-super": true,
"no-duplicate-switch-case": true,
"no-empty": false,
"no-empty-interface": true,
"no-empty-interface": false,
"no-eval": true,
"no-for-in-array": true,
"no-import-side-effect": true,
Expand Down
4 changes: 2 additions & 2 deletions @here/olp-sdk-core/tslint.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"severity": "warn"
},
"eofline": true,
"forin": true,
"forin": false,
"import-blacklist": [
true,
"rxjs/Rx"
Expand Down Expand Up @@ -71,7 +71,7 @@
"no-duplicate-super": true,
"no-duplicate-switch-case": true,
"no-empty": false,
"no-empty-interface": true,
"no-empty-interface": false,
"no-eval": true,
"no-for-in-array": true,
"no-import-side-effect": true,
Expand Down
50 changes: 40 additions & 10 deletions @here/olp-sdk-dataservice-api/lib/RequestBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export class UrlBuilder {
url: string,
separator: string,
key: string,
value: string | number | boolean | string[]
value: string | number | boolean | string[] | number[]
): string {
url += separator;
url += encodeURIComponent(key) + "=";
Expand All @@ -68,8 +68,13 @@ export class UrlBuilder {
url += `${value}`;
} else if (typeof value === "string") {
url += encodeURIComponent(value);
} else {
url += value.map(val => encodeURIComponent(val)).join(",");
} else if (Array.isArray(value)) {
const encodedValues: string[] = [];
value.forEach((val: string | number) => {
encodedValues.push(encodeURIComponent(val));
});

url += encodedValues.join(",");
}
return url;
}
Expand All @@ -93,16 +98,41 @@ export class UrlBuilder {
* @param key The key of the query parameter.
* @param value The value of the query parameter.
*/
appendQuery(key: string, value?: string | number | boolean | string[]) {
appendQuery(
key: string,
value?:
| string
| number
| boolean
| string[]
| number[]
| { [key: string]: string | number }
) {
if (value === undefined) {
return;
}
this.url = UrlBuilder.appendQueryString(
this.url,
this.hasQuery ? "&" : "?",
key,
value
);

if (value instanceof Object && !(value instanceof Array)) {
let queryString = "";
for (const propKey in value) {
queryString += UrlBuilder.appendQueryString(
"",
this.hasQuery ? "&" : "?",
propKey,
value[propKey]
);
}

this.url += queryString;
} else {
this.url = UrlBuilder.appendQueryString(
this.url,
this.hasQuery ? "&" : "?",
key,
value
);
}

this.hasQuery = true;
}
}
Expand Down
147 changes: 102 additions & 45 deletions @here/olp-sdk-dataservice-api/lib/interactive-api-v1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,29 @@ export interface ApiVersion {
apiVersion?: string;
}

/**
* True if the value is only an estimation; false otherwise.
*/
export type Estimated = boolean;

export type GetFeaturesBySpatialBody =
| Feature
| FeatureCollection
| Geometry
| LineString
| MultiLineString
| MultiPoint
| MultiPolygon
| Point
| Polygon;

export interface Feature extends GeoJSON {
/**
* The unique identifier of the feature.
*/
id?: string;
geometry?: GeoJSON;
geometry?: Geometry;
properties?: { [key: string]: any };
features?: Array<Feature>;
}

export interface FeatureCollection extends GeoJSON {
Expand Down Expand Up @@ -92,21 +107,45 @@ export interface GeoJSON {
* Describes the coordinate range of the GeoJSON object.
*/
bbox?: Array<number>;
coordinates?:
| LineString
| MultiLineString
| MultiPoint
| MultiPolygon
| Point
| Polygon;
}

export type LineString = Array<Array<number>>;
export type MultiLineString = Array<Array<Array<number>>>;
export type MultiPoint = Array<Array<number>>;
export type MultiPolygon = Array<Array<Array<Array<number>>>>;
export type Point = Array<number>;
export type Polygon = Array<Array<Array<number>>>;
/**
* A Geometry object represents points, curves, and surfaces in coordinate layer.
*/
export interface Geometry extends GeoJSON {}

export interface LineString extends Geometry {
coordinates?: Array<Array<number>>;
}

export interface ModelError {
title?: string;
status?: number;
code?: string;
cause?: string;
action?: string;
correlationId?: string;
}

export interface MultiLineString extends Geometry {
coordinates?: Array<Array<Array<number>>>;
}

export interface MultiPoint extends Geometry {
coordinates?: Array<Array<number>>;
}

export interface MultiPolygon extends Geometry {
coordinates?: Array<Array<Array<Array<number>>>>;
}

export interface Point extends Geometry {
coordinates?: Array<number>;
}

export interface Polygon extends Geometry {
coordinates?: Array<Array<Array<number>>>;
}

export interface Statistics {
count?: StatisticsCount;
Expand All @@ -120,22 +159,22 @@ export interface Statistics {

export interface StatisticsBbox {
value?: Array<number>;
estimated?: boolean;
estimated?: Estimated;
}

export interface StatisticsCount {
value?: number;
estimated?: boolean;
estimated?: Estimated;
}

export interface StatisticsGeometryTypes {
value?: Array<string>;
estimated?: boolean;
estimated?: Estimated;
}

export interface StatisticsProperties {
value?: Array<StatisticsPropertiesValue>;
estimated?: boolean;
estimated?: Estimated;
}

export interface StatisticsPropertiesValue {
Expand All @@ -146,7 +185,7 @@ export interface StatisticsPropertiesValue {

export interface StatisticsTags {
value?: Array<StatisticsTagsValue>;
estimated?: boolean;
estimated?: Estimated;
}

export interface StatisticsTagsValue {
Expand Down Expand Up @@ -212,7 +251,7 @@ export async function getFeature(
params: {
layerId: string;
featureId: string;
selection?: string;
selection?: string | Array<string>;
force2D?: boolean;
}
): Promise<Feature> {
Expand Down Expand Up @@ -257,8 +296,8 @@ export async function getFeatures(
builder: RequestBuilder,
params: {
layerId: string;
id: string;
selection?: string;
id: string | string[];
selection?: string | Array<string>;
force2D?: boolean;
}
): Promise<FeatureCollection> {
Expand Down Expand Up @@ -389,14 +428,14 @@ export async function getFeaturesByBBox(
builder: RequestBuilder,
params: {
layerId: string;
bbox?: string;
bbox?: Array<number>;
clip?: boolean;
limit?: number;
params?: string;
selection?: string;
params?: { [key: string]: string | number };
selection?: string | Array<string>;
skipCache?: boolean;
clustering?: string;
clusteringParams?: string;
clusteringParams?: { [key: string]: string | number };
force2D?: boolean;
}
): Promise<FeatureCollection> {
Expand All @@ -407,14 +446,23 @@ export async function getFeaturesByBBox(

const urlBuilder = new UrlBuilder(builder.baseUrl + baseUrl);
urlBuilder.appendQuery("bbox", params["bbox"]);
urlBuilder.appendQuery("clip", "true");
urlBuilder.appendQuery("clip", params["clip"]);
urlBuilder.appendQuery("limit", params["limit"]);
urlBuilder.appendQuery("params", params["params"]);
urlBuilder.appendQuery("selection", params["selection"]);
urlBuilder.appendQuery("skipCache", "true");
urlBuilder.appendQuery("skipCache", params["skipCache"]);
urlBuilder.appendQuery("clustering", params["clustering"]);
urlBuilder.appendQuery("clusteringParams", params["clusteringParams"]);
urlBuilder.appendQuery("force2D", "true");

if (params["clusteringParams"]) {
for (const clusteringParam in params["clusteringParams"]) {
urlBuilder.appendQuery(
`clustering.${clusteringParam}`,
params["clusteringParams"][clusteringParam]
);
}
}

urlBuilder.appendQuery("force2D", params["force2D"]);

const headers: { [header: string]: string } = {};
const options: RequestOptions = {
Expand Down Expand Up @@ -509,8 +557,8 @@ export async function getFeaturesBySpatial(
refFeatureId?: string;
radius?: number;
limit?: number;
params?: string;
selection?: string;
params?: { [key: string]: string | number };
selection?: string | Array<string>;
skipCache?: boolean;
force2D?: boolean;
}
Expand Down Expand Up @@ -606,11 +654,11 @@ export async function getFeaturesBySpatialPost(
builder: RequestBuilder,
params: {
layerId: string;
body?: GeoJSON;
body?: GetFeaturesBySpatialBody;
radius?: number;
limit?: number;
params?: string;
selection?: string;
params?: { [key: string]: string | number };
selection?: string | Array<string>;
skipCache?: boolean;
force2D?: boolean;
}
Expand Down Expand Up @@ -760,11 +808,11 @@ export async function getFeaturesByTile(
tileType: string;
tileId: string;
clip?: boolean;
params?: string;
selection?: string;
params?: { [key: string]: string | number };
selection?: string | Array<string>;
skipCache?: boolean;
clustering?: string;
clusteringParams?: string;
clusteringParams?: { [key: string]: string | number };
margin?: number;
limit?: number;
force2D?: boolean;
Expand All @@ -782,7 +830,16 @@ export async function getFeaturesByTile(
urlBuilder.appendQuery("selection", params["selection"]);
urlBuilder.appendQuery("skipCache", params["skipCache"]);
urlBuilder.appendQuery("clustering", params["clustering"]);
urlBuilder.appendQuery("clusteringParams", params["clusteringParams"]);

if (params["clusteringParams"]) {
for (const clusteringParam in params["clusteringParams"]) {
urlBuilder.appendQuery(
`clustering.${clusteringParam}`,
params["clusteringParams"][clusteringParam]
);
}
}

urlBuilder.appendQuery("margin", params["margin"]);
urlBuilder.appendQuery("limit", params["limit"]);
urlBuilder.appendQuery("force2D", params["force2D"]);
Expand Down Expand Up @@ -857,7 +914,7 @@ export async function iterateFeatures(
layerId: string;
limit?: number;
pageToken?: string;
selection?: string;
selection?: string | Array<string>;
skipCache?: boolean;
force2D?: boolean;
}
Expand Down Expand Up @@ -943,8 +1000,8 @@ export async function searchFeatures(
params: {
layerId: string;
limit?: number;
params?: string;
selection?: string;
params?: { [key: string]: string | number };
selection?: string | Array<string>;
skipCache?: boolean;
force2D?: boolean;
}
Expand All @@ -959,8 +1016,8 @@ export async function searchFeatures(
urlBuilder.appendQuery("limit", params["limit"]);
urlBuilder.appendQuery("params", params["params"]);
urlBuilder.appendQuery("selection", params["selection"]);
urlBuilder.appendQuery("skipCache", "true");
urlBuilder.appendQuery("force2D", "true");
urlBuilder.appendQuery("skipCache", params["skipCache"]);
urlBuilder.appendQuery("force2D", params["force2D"]);

const headers: { [header: string]: string } = {};
const options: RequestOptions = {
Expand Down
Loading

0 comments on commit 70d7d87

Please sign in to comment.