Skip to content

Commit

Permalink
Fix following refs to non-openapi3 root documents (but that are sub-d…
Browse files Browse the repository at this point in the history
…ocuments) (#346)
  • Loading branch information
fenollp committed Apr 23, 2021
1 parent 349fb58 commit 751a395
Show file tree
Hide file tree
Showing 21 changed files with 198 additions and 239 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,3 @@

# IntelliJ / GoLand
.idea

2 changes: 1 addition & 1 deletion openapi3/callback.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ var _ jsonpointer.JSONPointable = (*Callbacks)(nil)

func (c Callbacks) JSONLookup(token string) (interface{}, error) {
ref, ok := c[token]
if ref == nil || ok == false {
if ref == nil || !ok {
return nil, fmt.Errorf("object has no field %q", token)
}

Expand Down
2 changes: 1 addition & 1 deletion openapi3/examples.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ var _ jsonpointer.JSONPointable = (*Examples)(nil)

func (e Examples) JSONLookup(token string) (interface{}, error) {
ref, ok := e[token]
if ref == nil || ok == false {
if ref == nil || !ok {
return nil, fmt.Errorf("object has no field %q", token)
}

Expand Down
2 changes: 1 addition & 1 deletion openapi3/header.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ var _ jsonpointer.JSONPointable = (*Headers)(nil)

func (h Headers) JSONLookup(token string) (interface{}, error) {
ref, ok := h[token]
if ref == nil || ok == false {
if ref == nil || !ok {
return nil, fmt.Errorf("object has no field %q", token)
}

Expand Down
20 changes: 20 additions & 0 deletions openapi3/issue344_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package openapi3

import (
"testing"

"github.com/stretchr/testify/require"
)

func TestIssue344(t *testing.T) {
sl := NewSwaggerLoader()
sl.IsExternalRefsAllowed = true

doc, err := sl.LoadSwaggerFromFile("testdata/spec.yaml")
require.NoError(t, err)

err = doc.Validate(sl.Context)
require.NoError(t, err)

require.Equal(t, "string", doc.Components.Schemas["Test"].Value.Properties["test"].Value.Properties["name"].Value.Type)
}
2 changes: 1 addition & 1 deletion openapi3/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -1266,7 +1266,7 @@ func (schema *Schema) visitJSONArray(settings *schemaValidationSettings, value [
Value: value,
Schema: schema,
SchemaField: "uniqueItems",
Reason: fmt.Sprintf("duplicate items found"),
Reason: "duplicate items found",
}
if !settings.multiError {
return err
Expand Down
Loading

0 comments on commit 751a395

Please sign in to comment.