Skip to content
This repository was archived by the owner on Feb 26, 2025. It is now read-only.

Conversation

@nicwells
Copy link
Contributor

@nicwells nicwells commented Mar 15, 2022

Fixes BlueBrain/nexus#2974

Description

Fusion plugins rely on resource data conforming to a particular shape. When a plugin is active for a resource we therefore need to validate that the data conforms to our expected shape and present a user-friendly error message when it does not. In order to describe the shape we introduce the use of JSON Schema and the Ajv JSON schema validator package to validate that our data conforms to the shape.

Advantages

  • easier and more robust method to check that data conforms to our expected schema
  • better error messages to present to users
  • better documented - for both users and developers

We implement this for the Video plugin here to validate the technique with the intention of using it in all plugins.

For each plugin:

  • define a schema that we expect the data to conform to using JSON Schema. Note that we may have several for a single plugin.
  • use the SchemaValidationFallbackContainer component to handle displaying a user-friendly error message when the data does not conform or use the useJsonSchemaValidation hook directly

How has this been tested?

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist:

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added necessary unit and integration tests.
  • I have added screenshots (if applicable), in the comment section.

@codecov-commenter
Copy link

Codecov Report

❗ No coverage uploaded for pull request base (1.8.0-M1@2e668c2). Click here to learn what that means.
The diff coverage is n/a.

@@             Coverage Diff             @@
##             1.8.0-M1    #1064   +/-   ##
===========================================
  Coverage            ?   66.61%           
===========================================
  Files               ?       22           
  Lines               ?      668           
  Branches            ?      144           
===========================================
  Hits                ?      445           
  Misses              ?      223           
  Partials            ?        0           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2e668c2...bfaa8b9. Read the comment docs.

@nicwells nicwells requested review from dhaneshnm and smitfire March 15, 2022 18:55
@dhaneshnm dhaneshnm changed the base branch from 1.8.0-M1 to 1.7.1 March 16, 2022 14:40
@dhaneshnm dhaneshnm merged commit 9a1c0cd into 1.7.1 Mar 18, 2022
@dhaneshnm dhaneshnm deleted the 2974-handle-missing-metadata-in-plugins branch March 18, 2022 10:19
dhaneshnm pushed a commit that referenced this pull request May 20, 2022
* Use Json Schema to validate video plugin data

* Refactor validation into hook

* Add fallback component for schema validation
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants