-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Tony Gorez <[email protected]>
- Loading branch information
Showing
6 changed files
with
141 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Use the official Golang image as a parent image | ||
FROM golang:1.23-alpine | ||
|
||
# Set the working directory in the container | ||
WORKDIR /app | ||
|
||
# Copy the current directory contents into the container | ||
COPY . . | ||
|
||
# Download dependencies | ||
RUN go mod download | ||
|
||
# Build the Go app | ||
RUN go build -o go_jsonschema_validator . | ||
|
||
# Run the binary | ||
ENTRYPOINT ["/app/go_jsonschema_validator"] | ||
CMD [] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module implementations/go-jsonschema | ||
|
||
go 1.23.0 | ||
|
||
require github.com/santhosh-tekuri/jsonschema/v6 v6.0.1 | ||
|
||
require golang.org/x/text v0.14.0 // indirect |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
github.com/dlclark/regexp2 v1.11.0 h1:G/nrcoOa7ZXlpoa/91N3X7mM3r8eIlMBBJZvsz/mxKI= | ||
github.com/dlclark/regexp2 v1.11.0/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8= | ||
github.com/santhosh-tekuri/jsonschema/v6 v6.0.1 h1:PKK9DyHxif4LZo+uQSgXNqs0jj5+xZwwfKHgph2lxBw= | ||
github.com/santhosh-tekuri/jsonschema/v6 v6.0.1/go.mod h1:JXeL+ps8p7/KNMjDQk3TCwPpBy0wYklyWTfbkIzdIFU= | ||
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= | ||
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package main | ||
|
||
import ( | ||
"bufio" | ||
"fmt" | ||
"log" | ||
"os" | ||
"path/filepath" | ||
"time" | ||
"encoding/json" | ||
"io" | ||
|
||
"github.com/santhosh-tekuri/jsonschema/v6" | ||
) | ||
|
||
func main() { | ||
if len(os.Args) < 2 { | ||
log.Fatal("Please provide the example folder path as an argument") | ||
} | ||
|
||
exampleFolder := os.Args[1] | ||
|
||
// Construct and canonicalize file paths | ||
schemaFile, err := filepath.Abs(filepath.Join(exampleFolder, "schema.json")) | ||
if err != nil { | ||
log.Fatalf("Error constructing schema file path: %v", err) | ||
} | ||
|
||
instanceFile, err := filepath.Abs(filepath.Join(exampleFolder, "instances.jsonl")) | ||
if err != nil { | ||
log.Fatalf("Error constructing instance file path: %v", err) | ||
} | ||
|
||
// Compile the JSON schema | ||
c := jsonschema.NewCompiler() | ||
sch, err := c.Compile(schemaFile) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
// Open the JSONL file | ||
f, err := os.Open(instanceFile) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
defer f.Close() | ||
|
||
|
||
// Step 1: Decode and store JSON objects | ||
var instances []interface{} | ||
reader := bufio.NewReader(f) | ||
decoder := json.NewDecoder(reader) | ||
|
||
for { | ||
var inst interface{} | ||
if err := decoder.Decode(&inst); err != nil { | ||
if err == io.EOF { | ||
break | ||
} | ||
log.Fatalf("Error decoding JSON: %v", err) | ||
} | ||
instances = append(instances, inst) | ||
} | ||
|
||
start := time.Now() | ||
|
||
// Step 2: Validation loop | ||
for _, inst := range instances { | ||
err = sch.Validate(inst) | ||
if err != nil { | ||
log.Fatalf("Validation failed: %v", err) | ||
} | ||
} | ||
|
||
// Stop timer and calculate duration | ||
duration := time.Since(start) | ||
|
||
// Print timing | ||
fmt.Printf("%d\n", duration.Nanoseconds()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
|
||
#!/bin/bash | ||
|
||
set -o errexit | ||
set -o nounset | ||
|
||
# Extract the version of the jsonschema module from go.mod | ||
jsonschema_version=$(grep 'github.com/santhosh-tekuri/jsonschema' implementations/go-jsonschema/go.mod | sed -E 's/.*\/jsonschema\/v[0-9]+ v([0-9\.]+)/\1/') | ||
|
||
# Output the version | ||
echo "$jsonschema_version" |