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 json_schemer implementation #19

Merged
merged 3 commits into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,15 @@ jobs:
env:
CC: clang
CXX: clang++
BUNDLE_GEMFILE: ${{ github.workspace }}/implementations/json_schemer/Gemfile
steps:
- uses: actions/checkout@v4
- name: Install uv
run: pipx install uv
- uses: ruby/setup-ruby@v1
with:
ruby-version: '3.2.5'
bundler-cache: true

- run: make
- run: cat dist/report.csv
Expand Down
10 changes: 10 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,13 @@ dist/results/boon/%: \
| dist/results/boon
cargo run --manifest-path implementations/boon/Cargo.toml --release $(dir $(word 3,$^)) > $@

# JSON_SCHEMER

dist/results/json_schemer/%: \
implementations/json_schemer/main.rb \
implementations/json_schemer/Gemfile.lock \
schemas/%/schema.json \
schemas/%/instances.jsonl \
| dist/results/json_schemer
bundle exec --gemfile implementations/json_schemer/Gemfile ruby implementations/json_schemer/main.rb schemas/example $(dir $(word 3,$^)) > $@

4 changes: 4 additions & 0 deletions implementations/json_schemer/Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
source "https://rubygems.org"

gem 'json_schemer'
gem 'json'
23 changes: 23 additions & 0 deletions implementations/json_schemer/Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
GEM
remote: https://rubygems.org/
specs:
bigdecimal (3.1.8)
hana (1.3.7)
json (2.7.2)
json_schemer (2.3.0)
bigdecimal
hana (~> 1.3)
regexp_parser (~> 2.0)
simpleidn (~> 0.2)
regexp_parser (2.9.2)
simpleidn (0.2.3)

PLATFORMS
x86_64-linux

DEPENDENCIES
json
json_schemer

BUNDLED WITH
2.4.19
22 changes: 22 additions & 0 deletions implementations/json_schemer/main.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
require 'json_schemer'
require 'json'

michaelmior marked this conversation as resolved.
Show resolved Hide resolved
path = ARGV[0]

# Load the schema and build a validator
schema = JSON.parse(File.read(File.join(path, "schema.json")))
schemer = JSONSchemer.schema(schema)

# Read all instances into an array
instances = File.open(File.join(path, "instances.jsonl")).map do |line|
JSON.parse(line)
end

# Run the validation
start_time = Process.clock_gettime(Process::CLOCK_REALTIME, :nanosecond)
instances.each do |instance|
if !schemer.valid?(instance) then exit! end
end
end_time = Process.clock_gettime(Process::CLOCK_REALTIME, :nanosecond)

puts end_time - start_time
10 changes: 10 additions & 0 deletions implementations/json_schemer/version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/sh

set -o errexit
set -o nounset

# Extract the version of the package (json_schemer) from Gemfile.lock
json_schemer_version=$(grep -Po '(?<=json_schemer \().*(?=\))' implementations/json_schemer/Gemfile.lock)

# Output the version
echo "$json_schemer_version"
Loading