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 spec violation rules #141

Closed
wants to merge 24 commits into from
Closed

Conversation

richfab
Copy link
Contributor

@richfab richfab commented Oct 24, 2023

This PR follows #106.

  1. Brings all the code from Additional errors #106.
  2. Removes the validation rules that are not in the spec, as agreed in Additional errors #106 (comment). The code removed can be found in Additional errors #139.
  3. Collapses errors and warnings in the UI (they were expanded by default in Additional errors #106)
Before After
image image

Feed used for screenshots: https://acoruna.publicbikesystem.net/customer/gbfs/v2/gbfs.json

@netlify
Copy link

netlify bot commented Oct 24, 2023

Deploy Preview for gbfs-validator ready!

Name Link
🔨 Latest commit d271ba8
🔍 Latest deploy log https://app.netlify.com/sites/gbfs-validator/deploys/6544130a08b2b400080fbb26
😎 Deploy Preview https://deploy-preview-141--gbfs-validator.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@richfab richfab added the help wanted Extra attention is needed label Oct 24, 2023
@richfab richfab mentioned this pull request Oct 24, 2023
Copy link
Collaborator

@testower testower left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think a few non-trivial issues remain unresolved:

Taxonomy of validation result

Do we need to differentiate between schema and non-schema errors?

Multiple patterns in use for validation

The are several patterns in use:

  • original schema
  • patched schemas ("partials")
  • imperative rules (in JavaScript),
  • and some hybrid of the latter two it seems (in validation of additionalProperties).

I think this is problematic, and it should be clarified what we prefer, and the codebase needs to be clearer.

I think one benefit of using schemas and patched schemas only is that the validation itself is done by ajv and all the results is an output of ajv. It has been argued that these are harder to read than the imperative style, but after reading this PR I'm not 100% convinced.

Another problem with the imperative style is the unclear connection to the version(s) that the rule applies to. In the schema patching pattern it is explicit, whereas here you have to read the code (at least if it's not documented) - and mistakes are harder to spot.

Misc

The rest of the review is mostly technical and cosmetic.

One issue that stood out is inappropriate usage of Array methods, especially map where forEach would be better, and some others.

Some files are getting quite hard to read, and are in dire need of refactoring.

Some confusing folder structure introduced in test folder.

gbfs-validator/nonSchemaValidation/ttl.js Outdated Show resolved Hide resolved
@@ -1,5 +1,7 @@
const fastify = require('fastify')

const last_updated_fresh = Math.floor(Date.now() / 1000) - 30
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is good practice to not use real clocks in tests. It makes tests more reliable and readable. Jest has as of v27 the ability to do this neatly: https://jestjs.io/docs/jest-object#jestsetsystemtimenow-number--date

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a great idea, but this is beyond my knowledge unfortunately (even after reading the docs). Anyone, feel free to suggest an implementation. Thanks!

})
})

return errors
return { errors, nonSchemaErrors, warnings }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still think we need to review the taxonomy here. Why do we differentiate between errors and nonSchemaErrors? Would we not simply just have errors and warnings (where warnings are SHOULD violations)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to combine errors and nonSchemaErrors but was limited by my technical skills. Anyone, feel free to suggest an implementation.

gbfs-validator/__test__/fixtures/v3.0-RC/exaustive.js Outdated Show resolved Hide resolved
beforeAll(async () => {
const { MockRequests } = require('./fixtures/v3.0-RC/exaustive')

class InvalidMockRequests extends MockRequests {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really understand what is going on here? Why not just create a new fixture for this test?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is beyond my technical skills. Anyone, feel free to suggest an implementation.

}

for (const lang of languages) {
const filtered = data.filter((a) => a.language === lang)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Array#some is more efficient here (and condition can be inlined)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is beyond my technical knowledge. Anyone, feel free to suggest an implementation. Thanks!

gbfs-validator/versions/v1.0.js Outdated Show resolved Hide resolved
@testower
Copy link
Collaborator

One thing I should add in my quest for schema-centric validation is of course that the SHOULD/warning validations are hard to implement that way...

@richfab
Copy link
Contributor Author

richfab commented Nov 2, 2023

@testower I'm done applying the quick fixes from your suggestions. The other comments are beyond my technical knowledge. I will sync with @davidgamez about next steps. Thanks!

@richfab
Copy link
Contributor Author

richfab commented Nov 13, 2023

Thank you @tdelmas for the initial PR (#106) and @testower for the thorough PR review.

Based on the conversation following #153 (comment), we want to try doing the validation of these new rules by generating new schemas via a builder or a template instead of using imperative rules (eg: JavaScript).

For this reason, I believe this PR can be closed in favor of the following issues:

Thank you!

@richfab richfab closed this Nov 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants