Skip to content
Closed
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
4 changes: 2 additions & 2 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ jobs:
- name: golangci-lint
uses: golangci/golangci-lint-action@v8
with:
version: v2.8
version: v2.12
build:
name: Build
runs-on: ubuntu-latest
steps:
- name: Set up Go 1.x
uses: actions/setup-go@v3
with:
go-version: 1.25
go-version: 1.26
id: go

- name: Checkout code
Expand Down
2 changes: 1 addition & 1 deletion cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
package cache

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

// SchemaCacheEntry holds a compiled schema and its intermediate representations.
Expand Down
2 changes: 1 addition & 1 deletion content/content.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ import (
"strings"
"time"

"github.com/pb33f/go-yaml"
"github.com/pb33f/libopenapi/datamodel/high/base"
"go.yaml.in/yaml/v4"

v3 "github.com/pb33f/libopenapi/datamodel/high/v3"
)
Expand Down
2 changes: 1 addition & 1 deletion errors/parameter_errors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import (
"context"
"testing"

"github.com/pb33f/go-yaml"
"github.com/pb33f/libopenapi/datamodel/high/base"
"github.com/pb33f/libopenapi/datamodel/low"
"github.com/pb33f/libopenapi/orderedmap"
"github.com/pb33f/testify/require"
"go.yaml.in/yaml/v4"

v3 "github.com/pb33f/libopenapi/datamodel/high/v3"
lowbase "github.com/pb33f/libopenapi/datamodel/low/base"
Expand Down
2 changes: 1 addition & 1 deletion errors/request_errors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import (
"net/http"
"testing"

"github.com/pb33f/go-yaml"
"github.com/pb33f/libopenapi/datamodel/low"
"github.com/pb33f/libopenapi/orderedmap"
"github.com/pb33f/testify/require"
"go.yaml.in/yaml/v4"

v3 "github.com/pb33f/libopenapi/datamodel/high/v3"
lowv3 "github.com/pb33f/libopenapi/datamodel/low/v3"
Expand Down
2 changes: 1 addition & 1 deletion errors/response_errors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import (
"net/http"
"testing"

"github.com/pb33f/go-yaml"
"github.com/pb33f/libopenapi/datamodel/low"
"github.com/pb33f/libopenapi/orderedmap"
"github.com/pb33f/testify/require"
"go.yaml.in/yaml/v4"

v3 "github.com/pb33f/libopenapi/datamodel/high/v3"
lowv3 "github.com/pb33f/libopenapi/datamodel/low/v3"
Expand Down
2 changes: 1 addition & 1 deletion errors/spec_line_col.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
package errors

import (
"go.yaml.in/yaml/v4"
"github.com/pb33f/go-yaml"

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

Expand Down
14 changes: 7 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
module github.com/pb33f/libopenapi-validator

go 1.25.7
go 1.26.0

require (
github.com/basgys/goxml2json v1.1.1-0.20231018121955-e66ee54ceaad
github.com/dlclark/regexp2 v1.12.0
github.com/go-openapi/jsonpointer v0.23.2
github.com/goccy/go-yaml v1.19.2
github.com/pb33f/jsonpath v0.8.2
github.com/pb33f/libopenapi v0.38.6
github.com/pb33f/testify v0.1.0
github.com/pb33f/go-yaml v0.1.0
github.com/pb33f/jsonpath v0.8.4
github.com/pb33f/libopenapi v0.41.1
github.com/pb33f/testify v0.1.1
github.com/santhosh-tekuri/jsonschema/v6 v6.0.2
go.yaml.in/yaml/v4 v4.0.0-rc.6
golang.org/x/text v0.38.0
)

require (
github.com/bahlo/generic-list-go v0.2.0 // indirect
github.com/buger/jsonparser v1.1.2 // indirect
github.com/go-openapi/swag/jsonname v0.26.1 // indirect
github.com/pb33f/ordered-map/v2 v2.3.1 // indirect
github.com/pb33f/ordered-map/v2 v2.3.2 // indirect
golang.org/x/net v0.50.0 // indirect
golang.org/x/sync v0.21.0 // indirect
golang.org/x/sync v0.23.0 // indirect
)
24 changes: 12 additions & 12 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,16 @@ github.com/go-openapi/testify/v2 v2.6.0 h1:5PKH2HE7YJ/LuRPQGvSxBRlFXNQhSetBLlGAg
github.com/go-openapi/testify/v2 v2.6.0/go.mod h1:SgsVHtfooshd0tublTtJ50FPKhujf47YRqauXXOUxfw=
github.com/goccy/go-yaml v1.19.2 h1:PmFC1S6h8ljIz6gMRBopkjP1TVT7xuwrButHID66PoM=
github.com/goccy/go-yaml v1.19.2/go.mod h1:XBurs7gK8ATbW4ZPGKgcbrY1Br56PdM69F7LkFRi1kA=
github.com/pb33f/jsonpath v0.8.2 h1:Ou4C7zjYClBm97dfZjDCjdZGusJoynv/vrtiEKNfj2Y=
github.com/pb33f/jsonpath v0.8.2/go.mod h1:zBV5LJW4OQOPatmQE2QdKpGQJvhDTlE5IEj6ASaRNTo=
github.com/pb33f/libopenapi v0.38.6 h1:rnLshOSCSLx3JmN/MnftyYcdN1FfaeRkbaBE/ZHdIXg=
github.com/pb33f/libopenapi v0.38.6/go.mod h1:8yHl64vr+ICrnzSgiwJmZ54heRqCqrhI/JL1ge+CPIY=
github.com/pb33f/ordered-map/v2 v2.3.1 h1:5319HDO0aw4DA4gzi+zv4FXU9UlSs3xGZ40wcP1nBjY=
github.com/pb33f/ordered-map/v2 v2.3.1/go.mod h1:qxFQgd0PkVUtOMCkTapqotNgzRhMPL7VvaHKbd1HnmQ=
github.com/pb33f/testify v0.1.0 h1:g48/HDU/jn2COspS4nM0scptxiKTJ4DnbX/4ehK6IZ8=
github.com/pb33f/testify v0.1.0/go.mod h1:nq283P/jJ8hXMmdhAqfj7BJIz0y+6IOHj9q0044rKt4=
github.com/pb33f/go-yaml v0.1.0 h1:zZ6Gg+ATbumXlXZNLMHIe7+zTkVqe20lx+TSYRrXEuY=
github.com/pb33f/go-yaml v0.1.0/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.1 h1:k2TzRNoFWdwtgZK8LpmqIHIPxD/6nExHkmB7QZXBets=
github.com/pb33f/libopenapi v0.41.1/go.mod h1:okMH18Y4oyUXUSCr84u+hHe7t/gWDwoHv/f3CEls4SQ=
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=
Expand All @@ -36,8 +38,6 @@ github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
go.yaml.in/yaml/v4 v4.0.0-rc.6 h1:1h7H1ohdUh93/FyE4YaDa1Zh64K6VVbjF4K6WUxMtH4=
go.yaml.in/yaml/v4 v4.0.0-rc.6/go.mod h1:aZqd9kCMsGL7AuUv/m/PvWLdg5sjJsZ4oHDEnfPPfY0=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.11.0/go.mod h1:xgJhtzW8F9jGdVFWZESrid1U1bjeNy4zgy5cRr/CIio=
Expand All @@ -54,8 +54,8 @@ golang.org/x/net v0.50.0/go.mod h1:UgoSli3F/pBgdJBHCTc+tp3gmrU4XswgGRgtnwWTfyM=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.21.0 h1:HLII4xRRTtCRkxYp4HNFF0Js/Og6q2i++KXbg0gHCwM=
golang.org/x/sync v0.21.0/go.mod h1:9xrNwdLfx4jkKbNva9FpL6vEN7evnE43NNNJQ2LF3+0=
golang.org/x/sync v0.23.0 h1:KameEIfc1IkluZyXWLn39Wd4tURc6GbCiISGiZm2bQk=
golang.org/x/sync v0.23.0/go.mod h1:sUUOizhqBxiL6pEWpqNLUiaJn1ShEbZ6BBqskPbjZm0=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
Expand Down
2 changes: 1 addition & 1 deletion kin_parity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ import (
"sync/atomic"
"testing"

"github.com/pb33f/go-yaml"
"github.com/pb33f/libopenapi"
"github.com/pb33f/libopenapi/datamodel/high/base"
"github.com/pb33f/testify/assert"
"github.com/pb33f/testify/require"
"go.yaml.in/yaml/v4"

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

Expand Down
2 changes: 1 addition & 1 deletion request_defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (
"net/url"
"strings"

"github.com/pb33f/go-yaml"
"github.com/pb33f/libopenapi/datamodel/high/base"
"go.yaml.in/yaml/v4"

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

Expand Down
2 changes: 1 addition & 1 deletion requests/validate_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import (
"regexp"
"strconv"

"github.com/pb33f/go-yaml"
"github.com/pb33f/libopenapi/datamodel/high/base"
"github.com/santhosh-tekuri/jsonschema/v6"
"go.yaml.in/yaml/v4"
"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 @@ -14,9 +14,9 @@ import (
"regexp"
"strconv"

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

Expand Down
2 changes: 1 addition & 1 deletion schema_validation/directional_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import (
"fmt"
"math"

"github.com/pb33f/go-yaml"
"github.com/pb33f/libopenapi/datamodel/high/base"
"github.com/pb33f/libopenapi/utils"
"go.yaml.in/yaml/v4"
)

// SchemaValidationPurpose identifies the context in which a schema is compiled.
Expand Down
2 changes: 1 addition & 1 deletion schema_validation/directional_schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import (
"strings"
"testing"

"github.com/pb33f/go-yaml"
"github.com/pb33f/libopenapi"
"github.com/pb33f/libopenapi/datamodel/high/base"
"github.com/pb33f/testify/assert"
"github.com/pb33f/testify/require"
"go.yaml.in/yaml/v4"
)

func TestRenderSchemaForValidation_DirectionalRequiredProperties(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion schema_validation/locate_schema_property.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import (
"net/url"
"strings"

"github.com/pb33f/go-yaml"
"github.com/pb33f/jsonpath/pkg/jsonpath"
"github.com/pb33f/jsonpath/pkg/jsonpath/config"
"github.com/pb33f/libopenapi/utils"
"go.yaml.in/yaml/v4"
)

// LocateSchemaPropertyNodeByJSONPath will locate a schema property node by a JSONPath. It converts something like
Expand Down
2 changes: 1 addition & 1 deletion schema_validation/locate_schema_property_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ package schema_validation
import (
"testing"

"github.com/pb33f/go-yaml"
"github.com/pb33f/testify/assert"
"github.com/pb33f/testify/require"
"go.yaml.in/yaml/v4"
)

func TestLocateSchemaPropertyNodeByJSONPath_BadNode(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion schema_validation/property_locator.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"regexp"
"strings"

"github.com/pb33f/go-yaml"
"github.com/santhosh-tekuri/jsonschema/v6"
"go.yaml.in/yaml/v4"

liberrors "github.com/pb33f/libopenapi-validator/errors"
"github.com/pb33f/libopenapi-validator/helpers"
Expand Down
2 changes: 1 addition & 1 deletion schema_validation/property_locator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ package schema_validation
import (
"testing"

"github.com/pb33f/go-yaml"
"github.com/pb33f/libopenapi"
"github.com/pb33f/testify/assert"
"go.yaml.in/yaml/v4"
)

func TestExtractPropertyNameFromError_InvalidPropertyName(t *testing.T) {
Expand Down
33 changes: 29 additions & 4 deletions schema_validation/schema_resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import (
"strconv"
"strings"

"github.com/pb33f/go-yaml"
"github.com/pb33f/libopenapi/datamodel/high/base"
"github.com/pb33f/libopenapi/index"
"github.com/pb33f/libopenapi/utils"
"github.com/santhosh-tekuri/jsonschema/v6"
"go.yaml.in/yaml/v4"

"github.com/pb33f/libopenapi-validator/cache"
"github.com/pb33f/libopenapi-validator/config"
Expand Down Expand Up @@ -290,15 +290,14 @@ func buildSchemaDocumentResources(
return nil, nil
}

schemaIndex := schema.GoLow().GetIndex()
if schemaIndex == nil || schemaIndex.GetRootNode() == nil {
if schema.GoLow().GetIndex() == nil || schema.GoLow().GetIndex().GetRootNode() == nil {
return nil, nil
}
if !schemaHasReachableRefs(schema) {
return nil, nil
}

schemaPointer, ok := jsonPointerForNode(schemaIndex.GetRootNode(), schema.GoLow().GetRootNode())
schemaIndex, schemaPointer, ok := locateSchemaRootNodeIndex(schema)
if !ok {
return nil, fmt.Errorf("schema node was not found in its root document")
}
Expand Down Expand Up @@ -400,6 +399,32 @@ func addReachableSchemaResources(
return nil
}

// locateSchemaRootNodeIndex returns the index whose document contains the schema root node and its pointer.
//
// A component schema built from a $ref node reports the resolved file's index while its
// root node stays in the referring file, so other rolodex indexes are searched as a fallback.
func locateSchemaRootNodeIndex(schema *base.Schema) (*index.SpecIndex, string, bool) {
schemaIndex := schema.GoLow().GetIndex()
rootNode := schema.GoLow().GetRootNode()
if pointer, ok := jsonPointerForNode(schemaIndex.GetRootNode(), rootNode); ok {
return schemaIndex, pointer, true
}

rolodex := schemaIndex.GetRolodex()
if rolodex == nil {
return nil, "", false
}
for _, candidate := range append([]*index.SpecIndex{rolodex.GetRootIndex()}, rolodex.GetIndexes()...) {
if candidate == nil || candidate == schemaIndex {
continue
}
if pointer, ok := jsonPointerForNode(candidate.GetRootNode(), rootNode); ok {
return candidate, pointer, true
}
}
return nil, "", false
}

func schemaResourceIndex(foundRef *index.Reference, foundIndex *index.SpecIndex) *index.SpecIndex {
if foundIndex != nil {
return foundIndex
Expand Down
28 changes: 27 additions & 1 deletion schema_validation/schema_resources_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ import (
"strings"
"testing"

"github.com/pb33f/go-yaml"
"github.com/pb33f/libopenapi"
"github.com/pb33f/libopenapi/datamodel"
"github.com/pb33f/libopenapi/datamodel/high/base"
"github.com/pb33f/libopenapi/index"
"github.com/pb33f/testify/assert"
"github.com/pb33f/testify/require"
"go.yaml.in/yaml/v4"

lowbase "github.com/pb33f/libopenapi/datamodel/low/base"

Expand Down Expand Up @@ -196,6 +196,32 @@ components:
assert.Contains(t, err.Error(), "schema node was not found")
})

t.Run("schema root not found and index has no rolodex", func(t *testing.T) {
var root yaml.Node
require.NoError(t, yaml.Unmarshal([]byte(`components:
schemas:
Name:
type: string`), &root))

var detached yaml.Node
require.NoError(t, yaml.Unmarshal([]byte(`$ref: '#/components/schemas/Name'`), &detached))

lowSchema := &lowbase.Schema{}
require.NoError(t, lowSchema.Build(t.Context(), detached.Content[0], index.NewSpecIndex(&root)))
schema := base.NewSchema(lowSchema)
require.Nil(t, schema.GoLow().GetIndex().GetRolodex())

resourceSet, err := buildSchemaDocumentResources(
schema,
SchemaValidationPurposeGeneric,
nil,
)

assert.Nil(t, resourceSet)
require.Error(t, err)
assert.Contains(t, err.Error(), "schema node was not found")
})

t.Run("low schema with no index falls back to single schema compiler", func(t *testing.T) {
var root yaml.Node
require.NoError(t, yaml.Unmarshal([]byte(`$ref: '#/components/schemas/Name'`), &root))
Expand Down
2 changes: 1 addition & 1 deletion schema_validation/validate_document.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import (
"strconv"
"strings"

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

Expand Down
Loading
Loading