Skip to content

Commit 81eb8e5

Browse files
committed
Add modernjsonschemavalidator
1 parent f1aad80 commit 81eb8e5

File tree

8 files changed

+100
-0
lines changed

8 files changed

+100
-0
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ jobs:
1717
- uses: actions/setup-python@v5
1818
with:
1919
python-version: '3.12.5'
20+
- uses: oven-sh/setup-bun@v2
21+
with:
22+
bun-version: latest
2023

2124
- name: Install uv
2225
run: pipx install uv

Makefile

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ define docker_run
3535
@sed -i 's/$$/,$(.SHELLSTATUS)/' $@
3636
endef
3737

38+
schemas/%/schema-2020-12.json: \
39+
schemas/%/schema.json
40+
bunx alterschema --from draft4 --to 2020-12 $< > $@
41+
3842
# JSON Toolkit
3943

4044
implementations/jsontoolkit/.dockertimestamp: \
@@ -134,3 +138,22 @@ dist/results/go-jsonschema/%: \
134138
schemas/%/instances.jsonl \
135139
| dist/results/go-jsonschema
136140
@$(call docker_run,go-jsonschema,/workspace/$(dir $(word 2,$^)))
141+
142+
# MJS
143+
144+
implementations/mjs/.dockertimestamp: \
145+
implementations/mjs/build.sbt \
146+
implementations/mjs/Benchmark.scala \
147+
implementations/mjs/project/build.properties \
148+
implementations/mjs/project/plugins.sbt \
149+
implementations/mjs/Dockerfile
150+
docker build -t jsonschema-benchmark/mjs implementations/mjs
151+
touch $@
152+
153+
dist/results/mjs/%: \
154+
implementations/mjs/.dockertimestamp \
155+
schemas/%/schema-2020-12.json \
156+
schemas/%/instances.jsonl \
157+
| dist/results/mjs
158+
@$(call docker_run,mjs,/workspace/$(word 2,$^) /workspace/$(word 3,$^))
159+

implementations/mjs/Benchmark.scala

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import main.MainClass
2+
3+
import scala.io.Source
4+
5+
object Benchmark {
6+
def main(args: Array[String]): Unit = {
7+
if (args.length != 2) {
8+
System.exit(1)
9+
}
10+
val schemaPath = args(0)
11+
val instancePath = args(1)
12+
13+
val schema = Source.fromFile(schemaPath).mkString
14+
val registryMap = Map.empty[String, String]
15+
16+
val start = System.nanoTime()
17+
for (instance <- Source.fromFile(instancePath).getLines()) {
18+
val result = MainClass.validateInstance(schema, instance, registryMap)
19+
if (!result) {
20+
System.err.println("Invalid instance")
21+
System.exit(1)
22+
}
23+
}
24+
val finish = System.nanoTime()
25+
26+
println((finish - start).toString)
27+
}
28+
}

implementations/mjs/Dockerfile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
FROM sbtscala/scala-sbt:eclipse-temurin-17.0.4_1.7.2_2.13.10 AS builder
2+
3+
WORKDIR /app
4+
COPY Benchmark.scala /app
5+
COPY build.sbt /app
6+
COPY project /app/project
7+
RUN sbt assembly
8+
ENTRYPOINT ["java", "-jar", "/app/target/scala-2.13/benchmarkMjs.jar"]
9+
CMD []

implementations/mjs/build.sbt

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name := "mjs-validator"
2+
3+
ThisBuild / version := "1.0"
4+
ThisBuild / scalaVersion := "2.13.10"
5+
6+
javacOptions ++= Seq("-source", "17", "-target", "17")
7+
8+
resolvers += Resolver.mavenCentral
9+
10+
libraryDependencies ++= Seq(
11+
"org.scala-lang" % "scala-library" % "2.13.10"
12+
)
13+
14+
val mjsVersion = "v0.1.0"
15+
lazy val mjs = RootProject(
16+
uri(s"https://gitlab.lip6.fr/jsonschema/modernjsonschemavalidator.git#$mjsVersion")
17+
)
18+
lazy val benchmarkMjs = (project in file(".")).dependsOn(mjs)
19+
assembly / assemblyJarName := "benchmarkMjs.jar"
20+
assembly / packageOptions := Seq(
21+
Package.ManifestAttributes(
22+
"Main-Class" -> "Benchmark",
23+
"Implementation-Group" -> "org.up.mjs",
24+
"Implementation-Name" -> "mjs",
25+
"Implementation-Version" -> mjsVersion
26+
)
27+
)
28+
29+
scalacOptions += "-Ymacro-annotations"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
sbt.version=1.9.6
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "2.1.5")

implementations/mjs/version.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/sh
2+
3+
set -o errexit
4+
set -o nounset
5+
6+
grep '^val mjsVersion =' implementations/mjs/build.sbt | cut -d= -f2 | tr -d '" '

0 commit comments

Comments
 (0)