-
Notifications
You must be signed in to change notification settings - Fork 1
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 validation mode support #56
Conversation
including specs and styling
samples are now grouped according to usage (Opportunity Data or Booking). Also samples may have a validation mode associated with them so need to add that the link url. Plus tweak styling slightly to take groups into account in downdown.
as a way for a sample link to specify the validation mode it should run against
NB while tests pass until the 2.0.0 version of data-models (with the validation mode groups and updated format of examples) is released this will not run successfully. |
so guaranteed to have validation modes in metadata and new format of examples in spec
validate endpoint really expects a string containing the JSON data, rather than a neat JSON object
for better consistency - respond with errors early or get to end and give good response
to make naming convention with validateURL
it works out from body whether to get data to validate from passed JSON or remote url also allowed refactoring of ApiHelper to a share validate method with helpers for validateUrl and validateJSON
data-models, data-model-validator and rpde-validator have all been updated to allow this validation modes stuff to work in the site
for some reason ...data not working so cloning the argument and settings the extra data needed on the object
partly because validationMode is dependent on version (particularly the default one) and also to fix an issue with validationMode not returning to default if none is provided by a link
otherwise the list of examples gets too long very quickly for even larger screens
src/client/helpers/api-helper.js
Outdated
static validateURL(url, version) { | ||
return fetch(`/api/validateUrl/${version}`, { | ||
static validate(data, version, validationMode) { | ||
let body = JSON.parse(JSON.stringify(data)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems fishy?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is something I was going to pick up with Joe during review, for some reason it's not liking the spread operator as I was hoping to just to const body = { ...date, validationMode };
rather than clone the data object and add validationMode to it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the spread isn’t working for whatever reason (weird it doesn’t) I noticed jQuery is in the project, it has it’s own method for that kind of thing https://api.jquery.com/jquery.extend/
TL;DR
const body = $.extend({}, data, { validationMode });
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, Ben. Just seen this - we went for Object.assign
which looks like it's the same thing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! As long as that’s okay with browser support then that’s nice.
Basically no IE and in built Android browsers.
https://caniuse.com/#feat=mdn-javascript_builtins_object_assign
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the warning, Ben. The site is a tool for devs so IE unlikely to be used.
Spread operator is not available for object literals yet (experimental) and JSON stringify & parse to clone is a bit unnecessary
Final part of openactive/data-models#41
Adds a drop-down for selecting validation mode.
Samples drop-down now supports groups depending on usage type (e.g. RDPE or Booking) with optionally supplied associated validation mode for an example (selecting a sample with a validation mode associated with set the site's validation mode to it). The examples in each group are displayed via sub-menus to ensure the initial drop-down is now illegibly long.