Skip to content

Add openapiprocessor implementation #89

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ jobs:
report-corvus: ${{ steps.save-output.outputs.report-corvus }}
report-go-jsonschema: ${{ steps.save-output.outputs.report-go-jsonschema }}
report-hyperjump: ${{ steps.save-output.outputs.report-hyperjump }}
report-openapiprocessor: ${{ steps.save-output.outputs.report-openapiprocessor }}
report-json_schemer: ${{ steps.save-output.outputs.report-json_schemer }}
report-jsoncons: ${{ steps.save-output.outputs.report-jsoncons }}
report-jsonschemadotnet: ${{ steps.save-output.outputs.report-jsonschemadotnet }}
Expand Down
19 changes: 19 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -257,3 +257,22 @@ dist/results/kmp-json-schema-validator/%: \
schemas/%/instances.jsonl \
| dist/results/kmp-json-schema-validator
@$(call docker_run,kmp-json-schema-validator,/workspace/$(word 2,$^) /workspace/$(word 3,$^))

# openapiprocessor

implementations/openapiprocessor/.dockertimestamp: \
implementations/openapiprocessor/app/src/main/java/io/github/sourcemeta/App.java \
implementations/openapiprocessor/app/build.gradle.kts \
implementations/openapiprocessor/gradle/libs.versions.toml \
implementations/openapiprocessor/gradle/wrapper/gradle-wrapper.properties \
implementations/openapiprocessor/run.sh \
implementations/openapiprocessor/Dockerfile
docker build -t jsonschema-benchmark/openapiprocessor implementations/openapiprocessor
touch $@

dist/results/openapiprocessor/%: \
implementations/openapiprocessor/.dockertimestamp \
schemas/%/schema.json \
schemas/%/instances.jsonl \
| dist/results/openapiprocessor
@$(call docker_run,openapiprocessor,/workspace/$(word 2,$^) /workspace/$(word 3,$^))
9 changes: 9 additions & 0 deletions implementations/openapiprocessor/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#
# https://help.github.com/articles/dealing-with-line-endings/
#
# Linux start script should use lf
/gradlew text eol=lf

# These are Windows script files and should use crlf
*.bat text eol=crlf

5 changes: 5 additions & 0 deletions implementations/openapiprocessor/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Ignore Gradle project-specific cache directory
.gradle

# Ignore Gradle build output directory
build
16 changes: 16 additions & 0 deletions implementations/openapiprocessor/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# syntax=docker.io/docker/dockerfile:1.7-labs
FROM gradle:8.11.1-jdk21

COPY --exclude=./app/src . /app

WORKDIR /app

# Just download dependencies first
RUN gradle downloadDependencies

# Now copy in the source and compile
COPY ./app/src /app/app/src
RUN gradle compileJava

ENTRYPOINT ["/app/run.sh"]
CMD []
40 changes: 40 additions & 0 deletions implementations/openapiprocessor/app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
plugins {
// Apply the application plugin to add support for building a CLI application in Java.
application
}

repositories {
// Use Maven Central for resolving dependencies.
mavenCentral()
}

dependencies {
// This dependency is used by the application.
implementation(libs.openapiprocessor)
implementation(libs.interfaces)
implementation(libs.jackson)
}

// Apply a specific Java toolchain to ease working on different environments.
java {
toolchain {
languageVersion = JavaLanguageVersion.of(21)
}
}

application {
// Define the main class for the application.
mainClass = "io.github.sourcemeta.App"
}
//
// See https://stackoverflow.com/a/38528497/123695
fun ConfigurationContainer.resolveAll() = this
.filter { it.isCanBeResolved }
.forEach { it.resolve() }

tasks.register("downloadDependencies") {
doLast {
configurations.resolveAll()
buildscript.configurations.resolveAll()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
package io.github.sourcemeta;

// import dev.harrel.jsonschema.Validator;
// import dev.harrel.jsonschema.ValidatorFactory;
// import java.lang.Math;
// import java.net.URI;

import io.openapiprocessor.interfaces.Converter;
import io.openapiprocessor.interfaces.ConverterException;
import io.openapiprocessor.jackson.JacksonConverter;
import io.openapiprocessor.jsonschema.reader.UriReader;
import io.openapiprocessor.jsonschema.schema.DocumentLoader;
import io.openapiprocessor.jsonschema.schema.JsonInstance;
import io.openapiprocessor.jsonschema.schema.JsonSchema;
import io.openapiprocessor.jsonschema.schema.SchemaStore;
import io.openapiprocessor.jsonschema.validator.Validator;
import io.openapiprocessor.jsonschema.validator.ValidatorSettings;
import io.openapiprocessor.jsonschema.validator.steps.ValidationStep;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.List;
import java.util.stream.Collectors;

public class App {
static int WARMUP_ITERATIONS = 1000;
static long MAX_WARMUP_TIME = (long) 1e9 * 10;

public static boolean validateAll(
Validator validator, JsonSchema schema, List<JsonInstance> docs) {
boolean valid = true;
ValidationStep step;
for (JsonInstance doc : docs) {
step = validator.validate(schema, doc);
if (!step.isValid()) {
valid = false;
}
}
return valid;
}

public static void main(String[] args)
throws ConverterException, IOException, URISyntaxException {
UriReader reader = new UriReader();
Converter converter = new JacksonConverter();
DocumentLoader loader = new DocumentLoader(reader, converter);
SchemaStore store = new SchemaStore(loader);
URI schemaUri = new URI("file://" + args[0]);

// Register the schema
Long compileStart = System.nanoTime();
store.register(schemaUri);
JsonSchema schema = store.getSchema(schemaUri);
ValidatorSettings settings = new ValidatorSettings();
Validator validator = new Validator(settings);
Long compileEnd = System.nanoTime();

// Load all documents
List<JsonInstance> docs =
Files.readAllLines(Paths.get(args[1])).stream()
.map(
l -> {
try {
return new JsonInstance(converter.convert(l));
} catch (ConverterException e) {
throw new RuntimeException(e);
}
})
.collect(Collectors.toList());

Long coldStart = System.nanoTime();
boolean valid = validateAll(validator, schema, docs);
Long coldEnd = System.nanoTime();

if (!valid) {
System.exit(1);
}

// Warmup
long iterations = (long) Math.ceil(((double) MAX_WARMUP_TIME) / (coldEnd - coldStart));
for (int i = 0; i < WARMUP_ITERATIONS; i++) {
validateAll(validator, schema, docs);
}

Long warmStart = System.nanoTime();
validateAll(validator, schema, docs);
Long warmEnd = System.nanoTime();

System.out.println(
(coldEnd - coldStart) + "," + (warmEnd - warmStart) + "," + (compileEnd - compileStart));
}
}
7 changes: 7 additions & 0 deletions implementations/openapiprocessor/gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[versions]
openapiprocessor = "2024.5"

[libraries]
openapiprocessor = { module = "io.openapiprocessor:json-schema-validator", version.ref = "openapiprocessor" }
interfaces = { module = "io.openapiprocessor:io-interfaces", version.ref = "openapiprocessor" }
jackson = { module = "io.openapiprocessor:io-jackson", version.ref = "openapiprocessor" }
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading
Loading