Skip to content

Commit

Permalink
fix alters by LGTM.com (#415)
Browse files Browse the repository at this point in the history
  • Loading branch information
fenollp committed Aug 31, 2021
1 parent c50a458 commit de8fc7e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 18 deletions.
12 changes: 6 additions & 6 deletions openapi3/loader.go
Expand Up @@ -780,7 +780,7 @@ func (loader *Loader) resolveSecuritySchemeRef(doc *T, component *SecurityScheme
if ref := component.Ref; ref != "" {
if isSingleRefElement(ref) {
var scheme SecurityScheme
if documentPath, err = loader.loadSingleElementFromURI(ref, documentPath, &scheme); err != nil {
if _, err = loader.loadSingleElementFromURI(ref, documentPath, &scheme); err != nil {
return err
}
component.Value = &scheme
Expand All @@ -794,7 +794,7 @@ func (loader *Loader) resolveSecuritySchemeRef(doc *T, component *SecurityScheme
return err
}
component.Value = resolved.Value
documentPath = loader.documentPathForRecursiveRef(documentPath, resolved.Ref)
_ = loader.documentPathForRecursiveRef(documentPath, resolved.Ref)
}
}
return nil
Expand All @@ -817,7 +817,7 @@ func (loader *Loader) resolveExampleRef(doc *T, component *ExampleRef, documentP
if ref := component.Ref; ref != "" {
if isSingleRefElement(ref) {
var example Example
if documentPath, err = loader.loadSingleElementFromURI(ref, documentPath, &example); err != nil {
if _, err = loader.loadSingleElementFromURI(ref, documentPath, &example); err != nil {
return err
}
component.Value = &example
Expand All @@ -831,7 +831,7 @@ func (loader *Loader) resolveExampleRef(doc *T, component *ExampleRef, documentP
return err
}
component.Value = resolved.Value
documentPath = loader.documentPathForRecursiveRef(documentPath, resolved.Ref)
_ = loader.documentPathForRecursiveRef(documentPath, resolved.Ref)
}
}
return nil
Expand Down Expand Up @@ -943,7 +943,7 @@ func (loader *Loader) resolveLinkRef(doc *T, component *LinkRef, documentPath *u
if ref := component.Ref; ref != "" {
if isSingleRefElement(ref) {
var link Link
if documentPath, err = loader.loadSingleElementFromURI(ref, documentPath, &link); err != nil {
if _, err = loader.loadSingleElementFromURI(ref, documentPath, &link); err != nil {
return err
}
component.Value = &link
Expand All @@ -957,7 +957,7 @@ func (loader *Loader) resolveLinkRef(doc *T, component *LinkRef, documentPath *u
return err
}
component.Value = resolved.Value
documentPath = loader.documentPathForRecursiveRef(documentPath, resolved.Ref)
_ = loader.documentPathForRecursiveRef(documentPath, resolved.Ref)
}
}
return nil
Expand Down
12 changes: 4 additions & 8 deletions openapi3/schema.go
Expand Up @@ -824,8 +824,7 @@ func (schema *Schema) visitSetOperations(settings *schemaValidationSettings, val
if v == nil {
return foundUnresolvedRef(ref.Ref)
}
err := v.visitJSON(settings, value)
if err == nil {
if err := v.visitJSON(settings, value); err == nil {
if settings.failfast {
return errSchema
}
Expand Down Expand Up @@ -865,8 +864,7 @@ func (schema *Schema) visitSetOperations(settings *schemaValidationSettings, val
continue
}

err := v.visitJSON(settings, value)
if err != nil {
if err := v.visitJSON(settings, value); err != nil {
validationErrors = append(validationErrors, err)
continue
}
Expand Down Expand Up @@ -910,8 +908,7 @@ func (schema *Schema) visitSetOperations(settings *schemaValidationSettings, val
if v == nil {
return foundUnresolvedRef(item.Ref)
}
err := v.visitJSON(settings, value)
if err == nil {
if err := v.visitJSON(settings, value); err == nil {
ok = true
break
}
Expand All @@ -933,8 +930,7 @@ func (schema *Schema) visitSetOperations(settings *schemaValidationSettings, val
if v == nil {
return foundUnresolvedRef(item.Ref)
}
err := v.visitJSON(settings, value)
if err != nil {
if err := v.visitJSON(settings, value); err != nil {
if settings.failfast {
return errSchema
}
Expand Down
14 changes: 10 additions & 4 deletions openapi3gen/openapi3gen_test.go
Expand Up @@ -2,7 +2,7 @@ package openapi3gen

import (
"encoding/json"
"fmt"
"errors"
"reflect"
"strconv"
"strings"
Expand Down Expand Up @@ -162,11 +162,17 @@ func TestSchemaCustomizer(t *testing.T) {
schemaRef, _, err := NewSchemaRefForValue(&Bla{}, UseAllExportedFields(), SchemaCustomizer(func(name string, ft reflect.Type, tag reflect.StructTag, schema *openapi3.Schema) error {
t.Logf("Field=%s,Tag=%s", name, tag)
if tag.Get("mymintag") != "" {
minVal, _ := strconv.ParseFloat(tag.Get("mymintag"), 64)
minVal, err := strconv.ParseFloat(tag.Get("mymintag"), 64)
if err != nil {
return err
}
schema.Min = &minVal
}
if tag.Get("mymaxtag") != "" {
maxVal, _ := strconv.ParseFloat(tag.Get("mymaxtag"), 64)
maxVal, err := strconv.ParseFloat(tag.Get("mymaxtag"), 64)
if err != nil {
return err
}
schema.Max = &maxVal
}
if tag.Get("myenumtag") != "" {
Expand Down Expand Up @@ -212,7 +218,7 @@ func TestSchemaCustomizer(t *testing.T) {
func TestSchemaCustomizerError(t *testing.T) {
type Bla struct{}
_, _, err := NewSchemaRefForValue(&Bla{}, UseAllExportedFields(), SchemaCustomizer(func(name string, ft reflect.Type, tag reflect.StructTag, schema *openapi3.Schema) error {
return fmt.Errorf("test error")
return errors.New("test error")
}))
require.EqualError(t, err, "test error")
}

0 comments on commit de8fc7e

Please sign in to comment.