Skip to content

Commit

Permalink
Add modernjsonschemavalidator
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelmior committed Sep 28, 2024
1 parent a4fc4d7 commit be2a900
Show file tree
Hide file tree
Showing 8 changed files with 100 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ jobs:
- uses: actions/setup-python@v5
with:
python-version: '3.12.5'
- uses: oven-sh/setup-bun@v2
with:
bun-version: latest

- name: Install uv
run: pipx install uv
Expand Down
23 changes: 23 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ define docker_run
@sed -i 's/$$/,$(.SHELLSTATUS)/' $@
endef

schemas/%/schema-2020-12.json: \
schemas/%/schema.json
bunx alterschema --from draft4 --to 2020-12 $< > $@

# JSON Toolkit

implementations/jsontoolkit/.dockertimestamp: \
Expand Down Expand Up @@ -134,3 +138,22 @@ dist/results/go-jsonschema/%: \
schemas/%/instances.jsonl \
| dist/results/go-jsonschema
@$(call docker_run,go-jsonschema,/workspace/$(dir $(word 2,$^)))

# MJS

implementations/mjs/.dockertimestamp: \
implementations/mjs/build.sbt \
implementations/mjs/Benchmark.scala \
implementations/mjs/project/build.properties \
implementations/mjs/project/plugins.sbt \
implementations/mjs/Dockerfile
docker build -t jsonschema-benchmark/mjs implementations/mjs
touch $@

dist/results/mjs/%: \
implementations/mjs/.dockertimestamp \
schemas/%/schema-2020-12.json \
schemas/%/instances.jsonl \
| dist/results/mjs
@$(call docker_run,mjs,/workspace/$(word 2,$^) /workspace/$(word 3,$^))

28 changes: 28 additions & 0 deletions implementations/mjs/Benchmark.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import main.MainClass

import scala.io.Source

object Benchmark {
def main(args: Array[String]): Unit = {
if (args.length != 2) {
System.exit(1)
}
val schemaPath = args(0)
val instancePath = args(1)

val schema = Source.fromFile(schemaPath).mkString
val registryMap = Map.empty[String, String]

val start = System.nanoTime()
for (instance <- Source.fromFile(instancePath).getLines()) {
val result = MainClass.validateInstance(schema, instance, registryMap)
if (!result) {
System.err.println("Invalid instance")
System.exit(1)
}
}
val finish = System.nanoTime()

println((finish - start).toString)
}
}
9 changes: 9 additions & 0 deletions implementations/mjs/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM sbtscala/scala-sbt:eclipse-temurin-17.0.4_1.7.2_2.13.10 AS builder

WORKDIR /app
COPY Benchmark.scala /app
COPY build.sbt /app
COPY project /app/project
RUN sbt assembly
ENTRYPOINT ["java", "-jar", "/app/target/scala-2.13/benchmarkMjs.jar"]
CMD []
29 changes: 29 additions & 0 deletions implementations/mjs/build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name := "mjs-validator"

ThisBuild / version := "1.0"
ThisBuild / scalaVersion := "2.13.10"

javacOptions ++= Seq("-source", "17", "-target", "17")

resolvers += Resolver.mavenCentral

libraryDependencies ++= Seq(
"org.scala-lang" % "scala-library" % "2.13.10"
)

val mjsVersion = "v0.1.0"
lazy val mjs = RootProject(
uri(s"https://gitlab.lip6.fr/jsonschema/modernjsonschemavalidator.git#$mjsVersion")
)
lazy val benchmarkMjs = (project in file(".")).dependsOn(mjs)
assembly / assemblyJarName := "benchmarkMjs.jar"
assembly / packageOptions := Seq(
Package.ManifestAttributes(
"Main-Class" -> "Benchmark",
"Implementation-Group" -> "org.up.mjs",
"Implementation-Name" -> "mjs",
"Implementation-Version" -> mjsVersion
)
)

scalacOptions += "-Ymacro-annotations"
1 change: 1 addition & 0 deletions implementations/mjs/project/build.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sbt.version=1.9.6
1 change: 1 addition & 0 deletions implementations/mjs/project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "2.1.5")
6 changes: 6 additions & 0 deletions implementations/mjs/version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/sh

set -o errexit
set -o nounset

grep '^val mjsVersion =' implementations/mjs/build.sbt | cut -d= -f2 | tr -d '" '

0 comments on commit be2a900

Please sign in to comment.