Skip to content
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
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ Document validation is explicitly covered for OpenAPI 3.0, 3.1, and 3.2.

👉👉 [Check out the full documentation](https://pb33f.io/libopenapi/validation/) 👈👈

## JSON Schema dependency

The validator uses the maintained [`pb33f/jsonschema/v6`](https://github.com/pb33f/jsonschema) fork.
If you pass compiled schemas, implement a schema cache, configure a regex engine, or inspect
`OriginalJsonSchemaError`, update direct imports from `github.com/santhosh-tekuri/jsonschema/v6`
to `github.com/pb33f/jsonschema/v6` (including `/kind` imports). Types from the two module
paths have different Go identities. Standard validator calls need no code changes.

## Runtime validation features

The validator now includes a standalone OpenAPI router, authentication callbacks with route context and replayable bodies, immutable custom body codecs, opt-in request defaults, `Parameter.content` decoding, validation policy switches, and explicit OpenAPI 3.2 document validation.
Expand Down
2 changes: 1 addition & 1 deletion cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ package cache

import (
"github.com/pb33f/go-yaml"
"github.com/pb33f/jsonschema/v6"
"github.com/pb33f/libopenapi/datamodel/high/base"
"github.com/santhosh-tekuri/jsonschema/v6"
)

// SchemaCacheEntry holds a compiled schema and its intermediate representations.
Expand Down
2 changes: 1 addition & 1 deletion cache/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import (
"sync"
"testing"

"github.com/pb33f/jsonschema/v6"
"github.com/pb33f/libopenapi/datamodel/high/base"
"github.com/pb33f/testify/assert"
"github.com/pb33f/testify/require"
"github.com/santhosh-tekuri/jsonschema/v6"
)

func TestNewDefaultCache(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion cmd/validate/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (

"github.com/dlclark/regexp2"
"github.com/goccy/go-yaml"
"github.com/pb33f/jsonschema/v6"
"github.com/pb33f/libopenapi"
"github.com/santhosh-tekuri/jsonschema/v6"

validator "github.com/pb33f/libopenapi-validator"
"github.com/pb33f/libopenapi-validator/config"
Expand Down
2 changes: 1 addition & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
"log/slog"
"net/http"

"github.com/pb33f/jsonschema/v6"
"github.com/pb33f/libopenapi/datamodel/high/base"
"github.com/santhosh-tekuri/jsonschema/v6"

v3 "github.com/pb33f/libopenapi/datamodel/high/v3"

Expand Down
2 changes: 1 addition & 1 deletion config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import (
"sync"
"testing"

"github.com/pb33f/jsonschema/v6"
"github.com/pb33f/libopenapi/datamodel/high/base"
"github.com/pb33f/testify/assert"
"github.com/pb33f/testify/require"
"github.com/santhosh-tekuri/jsonschema/v6"

v3 "github.com/pb33f/libopenapi/datamodel/high/v3"

Expand Down
4 changes: 2 additions & 2 deletions errors/validation_error.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// Copyright 2023 Princess B33f Heavy Industries / Dave Shanley
// Copyright 2023-2026 Princess Beef Heavy Industries, LLC / Dave Shanley
// SPDX-License-Identifier: MIT

package errors

import (
"fmt"

"github.com/pb33f/jsonschema/v6"
"github.com/pb33f/libopenapi-validator/helpers"
"github.com/santhosh-tekuri/jsonschema/v6"
)

// SchemaValidationFailure describes any failure that occurs when validating data
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ require (
github.com/goccy/go-yaml v1.19.2
github.com/pb33f/go-yaml v0.1.1
github.com/pb33f/jsonpath v0.8.4
github.com/pb33f/libopenapi v0.41.2
github.com/pb33f/jsonschema/v6 v6.0.3
github.com/pb33f/libopenapi v0.41.3
github.com/pb33f/testify v0.1.1
github.com/santhosh-tekuri/jsonschema/v6 v6.0.2
golang.org/x/text v0.42.0
)

Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@ github.com/pb33f/go-yaml v0.1.1 h1:yWGmhVdwzionRnSc/hEJwcfq6PaZL2QdYzyReXBbX7Q=
github.com/pb33f/go-yaml v0.1.1/go.mod h1:QvWdkHP5VjFYAeHMQUkaPQqREaQnBNOXmWzAjNrnSdo=
github.com/pb33f/jsonpath v0.8.4 h1:Yx7fxsKl8scgERL22WhKDs2c6gYNNUonPSWEG8Y194s=
github.com/pb33f/jsonpath v0.8.4/go.mod h1:eO6mgdhw5RgzCxm/bXTi75VUs0/cCYJzdGjMCCUEI6M=
github.com/pb33f/libopenapi v0.41.2 h1:7/KNzJJ0o5fC/tYxDYcHjziKfg0bkBpFUfI2UDbChAo=
github.com/pb33f/libopenapi v0.41.2/go.mod h1:mUldESjO6ownR1TCcywvoYp7e4v/bCdQyiiIqsgWne0=
github.com/pb33f/jsonschema/v6 v6.0.3 h1:TMIkE1xCmnF8Cy+anIBs+r4ASfGtwzfFxYsrrIn0wSU=
github.com/pb33f/jsonschema/v6 v6.0.3/go.mod h1:cYPShw+w1Jrs0YgpE2rk1FLdIAsKfWcotv/54G6ddFo=
github.com/pb33f/libopenapi v0.41.3 h1:XfLiw0iHjl2mGBG51SSIU62etiHTYYmGUelFtI7at8M=
github.com/pb33f/libopenapi v0.41.3/go.mod h1:mUldESjO6ownR1TCcywvoYp7e4v/bCdQyiiIqsgWne0=
github.com/pb33f/ordered-map/v2 v2.3.2 h1:wDyaZ2Pv9QLh64X4utCeD5Zoi9nIv2aW3lwv172O5PQ=
github.com/pb33f/ordered-map/v2 v2.3.2/go.mod h1:1OhFrXu3OYw3kM+FXF+Ug3ugmmZ9LE8z0JfQMLvtV0w=
github.com/pb33f/testify v0.1.1 h1:mnHe7uxKt8dyNYEGUspow72VjD264DB5rOJq4bz5tJw=
github.com/pb33f/testify v0.1.1/go.mod h1:keghMqOLECF1ENzESnfM+cwPcKN5uhTOpvbtjgL6aZg=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/santhosh-tekuri/jsonschema/v6 v6.0.2 h1:KRzFb2m7YtdldCEkzs6KqmJw4nqEVZGK7IN2kJkjTuQ=
github.com/santhosh-tekuri/jsonschema/v6 v6.0.2/go.mod h1:JXeL+ps8p7/KNMjDQk3TCwPpBy0wYklyWTfbkIzdIFU=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
Expand Down
4 changes: 2 additions & 2 deletions helpers/path_finder.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023-2025 Princess Beef Heavy Industries, LLC / Dave Shanley
// Copyright 2023-2026 Princess Beef Heavy Industries, LLC / Dave Shanley
// https://pb33f.io

package helpers
Expand All @@ -8,7 +8,7 @@ import (
"strings"
"unicode"

"github.com/santhosh-tekuri/jsonschema/v6"
"github.com/pb33f/jsonschema/v6"
)

// ExtractJSONPathFromValidationError traverses and processes a ValidationError to construct a JSONPath string representation of its instance location.
Expand Down
4 changes: 2 additions & 2 deletions helpers/path_finder_test.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// Copyright 2023-2025 Princess Beef Heavy Industries, LLC / Dave Shanley
// Copyright 2023-2026 Princess Beef Heavy Industries, LLC / Dave Shanley
// https://pb33f.io

package helpers

import (
"testing"

"github.com/pb33f/jsonschema/v6"
"github.com/pb33f/testify/assert"
"github.com/santhosh-tekuri/jsonschema/v6"
)

func TestDiveIntoValidationError(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion helpers/schema_compiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"sort"
"strconv"

"github.com/santhosh-tekuri/jsonschema/v6"
"github.com/pb33f/jsonschema/v6"

"github.com/pb33f/libopenapi-validator/config"
"github.com/pb33f/libopenapi-validator/openapi_vocabulary"
Expand Down
2 changes: 1 addition & 1 deletion helpers/schema_output.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

package helpers

import "github.com/santhosh-tekuri/jsonschema/v6"
import "github.com/pb33f/jsonschema/v6"

// FlattenSchemaOutputErrors returns every output unit that carries an actual validation error.
func FlattenSchemaOutputErrors(output *jsonschema.OutputUnit) []jsonschema.OutputUnit {
Expand Down
2 changes: 1 addition & 1 deletion helpers/schema_output_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ package helpers
import (
"testing"

"github.com/pb33f/jsonschema/v6"
"github.com/pb33f/testify/assert"
"github.com/santhosh-tekuri/jsonschema/v6"
)

func TestFlattenSchemaOutputErrors(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions helpers/url_loader.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023-2024 Princess Beef Heavy Industries, LLC / Dave Shanley
// Copyright 2023-2026 Princess Beef Heavy Industries, LLC / Dave Shanley
// https://pb33f.io

package helpers
Expand All @@ -9,7 +9,7 @@ import (
"net/http"
"time"

"github.com/santhosh-tekuri/jsonschema/v6"
"github.com/pb33f/jsonschema/v6"
)

// HTTPURLLoader is a type that implements the Loader interface for loading schemas from HTTP URLs.
Expand Down
4 changes: 2 additions & 2 deletions openapi_vocabulary/coercion.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2025 Princess B33f Heavy Industries / Dave Shanley
// Copyright 2023-2026 Princess Beef Heavy Industries, LLC / Dave Shanley
// SPDX-License-Identifier: MIT

package openapi_vocabulary
Expand All @@ -7,7 +7,7 @@ import (
"regexp"
"strconv"

"github.com/santhosh-tekuri/jsonschema/v6"
"github.com/pb33f/jsonschema/v6"
)

// coercionExtension handles Jackson-style scalar coercion (string->boolean/number)
Expand Down
4 changes: 2 additions & 2 deletions openapi_vocabulary/coercion_simple_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2025 Princess B33f Heavy Industries / Dave Shanley
// Copyright 2023-2026 Princess Beef Heavy Industries, LLC / Dave Shanley
// SPDX-License-Identifier: MIT

package openapi_vocabulary
Expand All @@ -8,8 +8,8 @@ import (
"strings"
"testing"

"github.com/pb33f/jsonschema/v6"
"github.com/pb33f/testify/assert"
"github.com/santhosh-tekuri/jsonschema/v6"
)

func TestCoercion_Vocabulary_CompilationSuccess(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions openapi_vocabulary/discriminator.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// Copyright 2025 Princess B33f Heavy Industries / Dave Shanley
// Copyright 2023-2026 Princess Beef Heavy Industries, LLC / Dave Shanley
// SPDX-License-Identifier: MIT

package openapi_vocabulary

import (
"github.com/santhosh-tekuri/jsonschema/v6"
"github.com/pb33f/jsonschema/v6"
)

// discriminatorExtension handles the OpenAPI discriminator keyword
Expand Down
4 changes: 2 additions & 2 deletions openapi_vocabulary/metadata.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// Copyright 2025 Princess B33f Heavy Industries / Dave Shanley
// Copyright 2023-2026 Princess Beef Heavy Industries, LLC / Dave Shanley
// SPDX-License-Identifier: MIT

package openapi_vocabulary

import (
"github.com/santhosh-tekuri/jsonschema/v6"
"github.com/pb33f/jsonschema/v6"
)

// exampleExtension handles the OpenAPI example keyword (metadata only)
Expand Down
4 changes: 2 additions & 2 deletions openapi_vocabulary/nullable.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// Copyright 2025 Princess B33f Heavy Industries / Dave Shanley
// Copyright 2023-2026 Princess Beef Heavy Industries, LLC / Dave Shanley
// SPDX-License-Identifier: MIT

package openapi_vocabulary

import (
"github.com/santhosh-tekuri/jsonschema/v6"
"github.com/pb33f/jsonschema/v6"
)

// compileNullable compiles the nullable keyword based on OpenAPI version
Expand Down
4 changes: 2 additions & 2 deletions openapi_vocabulary/vocabulary.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// Copyright 2025 Princess B33f Heavy Industries / Dave Shanley
// Copyright 2023-2026 Princess Beef Heavy Industries, LLC / Dave Shanley
// SPDX-License-Identifier: MIT

package openapi_vocabulary

import (
"github.com/santhosh-tekuri/jsonschema/v6"
"github.com/pb33f/jsonschema/v6"
)

// OpenAPIVocabularyURL is the vocabulary URL for OpenAPI-specific keywords
Expand Down
4 changes: 2 additions & 2 deletions openapi_vocabulary/vocabulary_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2025 Princess B33f Heavy Industries / Dave Shanley
// Copyright 2023-2026 Princess Beef Heavy Industries, LLC / Dave Shanley
// SPDX-License-Identifier: MIT

package openapi_vocabulary
Expand All @@ -7,8 +7,8 @@ import (
"strings"
"testing"

"github.com/pb33f/jsonschema/v6"
"github.com/pb33f/testify/assert"
"github.com/santhosh-tekuri/jsonschema/v6"
"golang.org/x/text/message"
)

Expand Down
2 changes: 1 addition & 1 deletion parameters/validate_parameter.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
"reflect"
"strings"

"github.com/pb33f/jsonschema/v6"
"github.com/pb33f/libopenapi/datamodel/high/base"
"github.com/santhosh-tekuri/jsonschema/v6"
"golang.org/x/text/language"
"golang.org/x/text/message"

Expand Down
2 changes: 1 addition & 1 deletion parameters/validate_parameter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ import (
"sync"
"testing"

"github.com/pb33f/jsonschema/v6"
"github.com/pb33f/libopenapi"
"github.com/pb33f/libopenapi/datamodel"
"github.com/pb33f/libopenapi/datamodel/high/base"
lowv3 "github.com/pb33f/libopenapi/datamodel/low/v3"
"github.com/pb33f/testify/assert"
"github.com/pb33f/testify/require"
"github.com/santhosh-tekuri/jsonschema/v6"
"golang.org/x/text/message"

"github.com/pb33f/libopenapi-validator/cache"
Expand Down
2 changes: 1 addition & 1 deletion requests/validate_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import (
"strconv"

"github.com/pb33f/go-yaml"
"github.com/pb33f/jsonschema/v6"
"github.com/pb33f/libopenapi/datamodel/high/base"
"github.com/santhosh-tekuri/jsonschema/v6"
"golang.org/x/text/language"
"golang.org/x/text/message"

Expand Down
2 changes: 1 addition & 1 deletion responses/validate_response.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import (
"strconv"

"github.com/pb33f/go-yaml"
"github.com/pb33f/jsonschema/v6"
"github.com/pb33f/libopenapi/datamodel/high/base"
"github.com/santhosh-tekuri/jsonschema/v6"
"golang.org/x/text/language"
"golang.org/x/text/message"

Expand Down
Loading
Loading