Added custom AJV coordinates format
MODIFY
src/assets/server/rest/v1/schemas/chargingstation/chargingstations-get.json
src/assets/server/rest/v1/schemas/chargingstation/chargingstations-get.json
},
"LocLongitude": {
"type": "number",
+ "format": "coordinates",
"sanitize": "mongo"
},
"LocLatitude": {
"type": "number",
+ "format": "coordinates",
"sanitize": "mongo"
},
"LocMaxDistanceMeters": {

MODIFY
src/server/rest/v1/validator/ChargingStationValidator.ts
src/server/rest/v1/validator/ChargingStationValidator.ts
@@ -53,7 +53,7 @@ export default class ChargingStationValidator extends SchemaValidator {
public validateChargingStationsGetReq(data: any): HttpChargingStationsRequest {
// Validate schema
this.validate(this.chargingStationsGet, data);
- if (Utils.containsGPSCoordinates([data.LocLongitude, data.LocLatitude])) {
+ if (data.LocLongitude && data.LocLatitude) {
data.LocCoordinates = [
Utils.convertToFloat(data.LocLongitude),
Utils.convertToFloat(data.LocLatitude)

MODIFY
src/server/rest/v1/validator/SchemaValidator.ts
src/server/rest/v1/validator/SchemaValidator.ts
@@ -31,6 +31,10 @@ export default class SchemaValidator {
coerceTypes: true
}) {
this.ajv = ajvSanitizer(new Ajv(config), extraSanitizers);
+ this.ajv.addFormat('coordinates', {
+ type: 'number',
+ validate: (c) => Constants.REGEX_VALIDATION_LATITUDE.test(c.toString()) || Constants.REGEX_VALIDATION_LONGITUDE.test(c.toString())
+ });
this.ajv.addSchema(this.commonSchema);
this.ajv.addSchema(this.tenantComponentSchema);
this.ajv.addSchema(this.chargingStationSchema);

Added custom AJV coordinates format