Skip to content
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

Fix following refs to non-openapi3 root documents (but that are sub-documents) #346

Merged
merged 17 commits into from
Apr 23, 2021
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