Skip to content

Commit

Permalink
Derive source type values from spec (#12449)
Browse files Browse the repository at this point in the history
  • Loading branch information
tristen committed Dec 7, 2022
1 parent a1b426d commit 3436af5
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/style-spec/validate/validate_source.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,23 @@ export default function validateSource(options: ValidationOptions): Array<Valida
return validateEnum({
key: `${key}.type`,
value: value.type,
valueSpec: {values: ['vector', 'raster', 'raster-dem', 'geojson', 'video', 'image']},
valueSpec: {values: getSourceTypeValues(styleSpec)},
style,
styleSpec
});
}
}

function getSourceTypeValues(styleSpec) {
return styleSpec.source.reduce((memo, source) => {
const sourceType = styleSpec[source];
if (sourceType.type.type === 'enum') {
memo = memo.concat(Object.keys(sourceType.type.values));
}
return memo;
}, []);
}

function validatePromoteId({key, value}) {
if (getType(value) === 'string') {
return validateString({key, value});
Expand Down

0 comments on commit 3436af5

Please sign in to comment.