Skip to content

Commit

Permalink
Add validation
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanhamley committed Sep 11, 2021
1 parent 48de483 commit 9f4a3c4
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/data/array_types.js
Original file line number Diff line number Diff line change
Expand Up @@ -1166,8 +1166,8 @@ export {
StructArrayLayout4f16,
StructArrayLayout2i4 as PosArray,
StructArrayLayout4i8 as RasterBoundsArray,
StructArrayLayout2i4 as CircleLayoutArray,
StructArrayLayout4i8 as TileBoundsArray,
StructArrayLayout2i4 as CircleLayoutArray,
StructArrayLayout2i4 as FillLayoutArray,
StructArrayLayout4i8 as FillExtrusionLayoutArray,
StructArrayLayout2i4 as HeatmapLayoutArray,
Expand Down
4 changes: 3 additions & 1 deletion src/style-spec/validate/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import validateFog from './validate_fog.js';
import validateString from './validate_string.js';
import validateFormatted from './validate_formatted.js';
import validateImage from './validate_image.js';
import validateProjection from './validate_projection.js';

const VALIDATORS = {
'*'() {
Expand All @@ -43,7 +44,8 @@ const VALIDATORS = {
'fog': validateFog,
'string': validateString,
'formatted': validateFormatted,
'resolvedImage': validateImage
'resolvedImage': validateImage,
'projection': validateProjection
};

// Main recursive validation function. Tracks:
Expand Down
30 changes: 30 additions & 0 deletions src/style-spec/validate/validate_projection.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import ValidationError from '../error/validation_error.js';
import getType from '../util/get_type.js';
import validate from './validate.js';

export default function validateImage(options) {
const projection = options.value;
const styleSpec = options.styleSpec;
const projectionSpec = styleSpec.projection;
const style = options.style;

let errors = [];

const rootType = getType(projection);

if (rootType === 'object') {
for (const key in projection) {
errors = errors.concat(validate({
key,
value: projection[key],
valueSpec: projectionSpec[key],
style,
styleSpec
}));
}
} else if (rootType !== 'string') {
errors = errors.concat([new ValidationError('projection', projection, `object or string expected, ${rootType} found`)]);
}

return errors;
}

0 comments on commit 9f4a3c4

Please sign in to comment.