Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add protected field to API supported validation #10968

Merged
merged 3 commits into from Aug 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/style-spec/validate_mapbox_api_supported.js
Expand Up @@ -94,7 +94,7 @@ function getRootErrors(style: Object, specKeys: Array<any>): Array<?ValidationEr
/*
* The following keys are optional but fully managed by the Mapbox Styles
* API. Values on stylesheet on POST or PATCH will be ignored: "owner",
* "id", "cacheControl", "draft", "created", "modified"
* "id", "cacheControl", "draft", "created", "modified", "protected"
*
* The following keys are optional. The Mapbox Styles API respects value on
* stylesheet on PATCH, but ignores the value on POST: "visibility"
Expand All @@ -106,7 +106,8 @@ function getRootErrors(style: Object, specKeys: Array<any>): Array<?ValidationEr
'draft',
'created',
'modified',
'visibility'
'visibility',
'protected'
];

const allowedKeyErrors = getAllowedKeyErrors(style, [...specKeys, ...optionalRootProperties]);
Expand Down Expand Up @@ -147,6 +148,10 @@ function getRootErrors(style: Object, specKeys: Array<any>): Array<?ValidationEr
errors.push(new ValidationError('visibility', style.visibility, 'Style visibility must be public or private'));
}

if (style.protected !== undefined && getType(style.protected) !== 'boolean') {
errors.push(new ValidationError('protected', style.protected, 'Style protection must be true or false'));
}

return errors;
}

Expand Down Expand Up @@ -177,3 +182,4 @@ export default function validateMapboxApiSupported(style: Object): Array<?Valida

return errors;
}

6 changes: 6 additions & 0 deletions test/unit/style-spec/fixture/bad-style-api.input.json
@@ -0,0 +1,6 @@
{
"version": 8,
"protected": "no",
"sources": {},
"layers": []
}
@@ -0,0 +1,6 @@
[
{
"message": "protected: Style protection must be true or false",
"line": 3
}
]
1 change: 1 addition & 0 deletions test/unit/style-spec/fixture/bad-style-api.output.json
@@ -0,0 +1 @@
[]
3 changes: 2 additions & 1 deletion test/unit/style-spec/fixture/style-api.input.json
Expand Up @@ -56,5 +56,6 @@
"owner": "Cyrus",
"visibility": "private",
"cacheControl": "s-max-age=200",
"draft": true
"draft": true,
"protected": true
}