Skip to content

Commit

Permalink
MAN-1325 replace ajv with json schema validate method
Browse files Browse the repository at this point in the history
- Remove ajv from project
- Incorporate JSON::Validator.validate into specs
- Downgrade custom schemas to JSON schema Draft-06 because
  Ruby json-schema gem does not support Draft-07 or later.
  • Loading branch information
nomadicoder committed Sep 26, 2023
1 parent 43c7efd commit 18ba3d6
Show file tree
Hide file tree
Showing 19 changed files with 19 additions and 33 deletions.
6 changes: 0 additions & 6 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,6 @@ jobs:
sudo psql -c "create role manifold with createdb login password 'password';" -U postgres -h localhost
RAILS_ENV=test bundle exec rake db:setup
- run:
name: Install node packages required for tests
command: |
sudo npm install -g [email protected]
sudo npm install -g [email protected]
- run:
name: Install ImageMagick
command: |
Expand Down
8 changes: 0 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,6 @@ cd manifold
bundle install
```

* Install JSON validation tool

```
sudo apt-get -y install npm
sudo npm install -g [email protected]
sudo npm install -g [email protected]
```

* Create database tables

```
Expand Down
2 changes: 1 addition & 1 deletion app/schemas/alert_schema.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"definitions": {},
"$schema": "http://json-schema.org/draft-07/schema#",
"$schema": "http://json-schema.org/draft-06/schema#",
"$id": "http://example.com/root.json",
"type": "object",
"title": "The Root Schema",
Expand Down
2 changes: 1 addition & 1 deletion app/schemas/blog_schema.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"definitions": {},
"$schema": "http://json-schema.org/draft-07/schema#",
"$schema": "http://json-schema.org/draft-06/schema#",
"$id": "http://example.com/root.json",
"type": "object",
"title": "The Root Schema",
Expand Down
2 changes: 1 addition & 1 deletion app/schemas/building_schema.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"definitions": {},
"$schema": "http://json-schema.org/draft-07/schema#",
"$schema": "http://json-schema.org/draft-06/schema#",
"$id": "http://example.com/root.json",
"type": "object",
"title": "The Root Schema",
Expand Down
2 changes: 1 addition & 1 deletion app/schemas/category_schema.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"definitions": {},
"$schema": "http://json-schema.org/draft-07/schema#",
"$schema": "http://json-schema.org/draft-06/schema#",
"$id": "http://example.com/root.json",
"type": "object",
"title": "The Root Schema",
Expand Down
2 changes: 1 addition & 1 deletion app/schemas/collection_schema.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"definitions": {},
"$schema": "http://json-schema.org/draft-07/schema#",
"$schema": "http://json-schema.org/draft-06/schema#",
"$id": "http://example.com/root.json",
"type": "object",
"title": "The Root Schema",
Expand Down
2 changes: 1 addition & 1 deletion app/schemas/event_schema.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"definitions": {},
"$schema": "http://json-schema.org/draft-07/schema#",
"$schema": "http://json-schema.org/draft-06/schema#",
"$id": "http://example.com/root.json",
"type": "object",
"title": "The Root Schema",
Expand Down
2 changes: 1 addition & 1 deletion app/schemas/exhibition_schema.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"definitions": {},
"$schema": "http://json-schema.org/draft-07/schema#",
"$schema": "http://json-schema.org/draft-06/schema#",
"$id": "http://example.com/root.json",
"type": "object",
"title": "The Root Schema",
Expand Down
2 changes: 1 addition & 1 deletion app/schemas/finding_aid_schema.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"definitions": {},
"$schema": "http://json-schema.org/draft-07/schema#",
"$schema": "http://json-schema.org/draft-06/schema#",
"$id": "http://example.com/root.json",
"type": "object",
"title": "The Root Schema",
Expand Down
2 changes: 1 addition & 1 deletion app/schemas/group_schema.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"definitions": {},
"$schema": "http://json-schema.org/draft-07/schema#",
"$schema": "http://json-schema.org/draft-06/schema#",
"$id": "http://example.com/root.json",
"type": "object",
"title": "The Root Schema",
Expand Down
2 changes: 1 addition & 1 deletion app/schemas/highlight_schema.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"definitions": {},
"$schema": "http://json-schema.org/draft-07/schema#",
"$schema": "http://json-schema.org/draft-06/schema#",
"$id": "http://example.com/root.json",
"type": "object",
"title": "The Root Schema",
Expand Down
2 changes: 1 addition & 1 deletion app/schemas/person_schema.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"definitions": {},
"$schema": "http://json-schema.org/draft-07/schema#",
"$schema": "http://json-schema.org/draft-06/schema#",
"$id": "http://example.com/root.json",
"type": "object",
"title": "The Root Schema",
Expand Down
2 changes: 1 addition & 1 deletion app/schemas/policy_schema.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"definitions": {},
"$schema": "http://json-schema.org/draft-07/schema#",
"$schema": "http://json-schema.org/draft-06/schema#",
"$id": "http://example.com/root.json",
"type": "object",
"title": "The Root Schema",
Expand Down
2 changes: 1 addition & 1 deletion app/schemas/service_schema.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"definitions": {},
"$schema": "http://json-schema.org/draft-07/schema#",
"$schema": "http://json-schema.org/draft-06/schema#",
"$id": "http://example.com/root.json",
"type": "object",
"title": "The Root Schema",
Expand Down
2 changes: 1 addition & 1 deletion app/schemas/space_schema.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"definitions": {},
"$schema": "http://json-schema.org/draft-07/schema#",
"$schema": "http://json-schema.org/draft-06/schema#",
"$id": "http://example.com/root.json",
"type": "object",
"title": "The Root Schema",
Expand Down
2 changes: 1 addition & 1 deletion app/schemas/webpage_schema.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"definitions": {},
"$schema": "http://json-schema.org/draft-07/schema#",
"$schema": "http://json-schema.org/draft-06/schema#",
"$id": "http://example.com/root.json",
"type": "object",
"title": "The Root Schema",
Expand Down
4 changes: 2 additions & 2 deletions spec/support/serializable_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

require "spec_helper"
require "json-schema"

RSpec.shared_examples "serializable" do
imageClasses = ["person", "event"]
Expand All @@ -19,9 +20,8 @@
Tempfile.open(["serialized_#{factory_model.class.to_s.underscore.downcase}-", ".json"]) do |serialized|
serialized.write(response.body)
serialized.close
args = %W[validate -s app/schemas/#{factory_model.class.to_s.underscore.downcase}_schema.json -d #{serialized.path}]

expect(system("ajv", *args)).to be
expect(JSON::Validator.validate("app/schemas/#{factory_model.class.to_s.underscore.downcase}_schema.json", serialized.path)).to be
end
end

Expand Down
4 changes: 2 additions & 2 deletions spec/support/serializer_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

require "spec_helper"
require "json-schema"

RSpec.shared_examples "serializer" do
let(:model) { described_class.to_s.split("Serializer").first.underscore.downcase.singularize.to_sym } # the class that includes the concern
Expand All @@ -11,8 +12,7 @@
Tempfile.open(["serialized_#{model}", ".json"]) do |tempfile|
tempfile.write(serialized.to_json)
tempfile.close
args = %W[validate -s app/schemas/#{model}_schema.json -d #{tempfile.path}]
expect(system("ajv", *args)).to be
expect(JSON::Validator.validate!("app/schemas/#{model}_schema.json", tempfile.path)).to be
end
end

Expand Down

0 comments on commit 18ba3d6

Please sign in to comment.