Closed samreid closed 7 years ago
Currently a parameter in the schema which has no defaultValue and is not supplied in the query string yields: Query String Machine Assertion failed: Value cannot be determined.
It would be better if this said: Query String Machine Assertion failed: query parameter must be supplied for '+keyName'.
I decided the API will be simplest if lack of a default value in the schema implies that the value is required. I improved the error message above and added automated tests for the new behavior. If a required query parameter is missing, it will throw an error and print a message like this one:
Query String Machine Assertion failed: missing value for "sim"
@pixelzoom can you review this as part of #2 ?
@samreid said
I decided the API will be simplest if lack of a default value in the schema implies that the value is required.
With one exception: schemas of type 'flag'. And that appears to work. But shouldn't providing defaultValue
for type 'flag' technically be treated as an error?
With one exception: schemas of type 'flag'. And that appears to work. But shouldn't providing
defaultValue
for type 'flag' technically be treated as an error?
I decided to allow flag defaults to be overriden. For example, we would like the scenery "webgl" query parameter to have the following values:
?webgl=true => true
?webgl => true
?webgl=false => false
(empty string) => true
So while the default flag behavior seems good for the majority of cases, it seems there are cases where we will want to override the default.
Got it, thanks for the clarification, and I now see that logic in parseElement
(line 208).
But just to confirm... Lack of a default value in the schema implies that the value is required, except for type 'flag'. Correct?
It appears the behavior is not as I prescribed in the previous comment. Assigned to me for investigation.
But just to confirm... Lack of a default value in the schema implies that the value is required, except for type 'flag'. Correct?
Yes, that's true.
👍 Closing.
Reassigned to me to investigate https://github.com/phetsims/query-string-machine/issues/7#issuecomment-246853497
Moved outstanding work to side issue, closing.
In some wrappers, some query parameters are required and the application should fail with a nice warning message if the query parameter is not supplied. (For instance ?sim in many of the sample wrappers). We should add support for required query parameters. Instead of providing
defaultValue
, it could haverequired: true
or just omitdefaultValue
, which would imply that support is required.