Skip to content

Commit

Permalink
Fix linting issues & unnecessary empty lines
Browse files Browse the repository at this point in the history
Signed-off-by: Mathias Petermann <mathias.petermann@gmail.com>
  • Loading branch information
peschmae committed Apr 8, 2024
1 parent 94725f7 commit 7348f37
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 18 deletions.
2 changes: 1 addition & 1 deletion pkg/schema/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,7 @@ func (t *DocumentType) GetValidationMap() map[string]interface{} {
}

// GetValidationMap provides the OpenAPI validation for the type
func (t MapType) GetValidationMap() map[string]interface{} {
func (m MapType) GetValidationMap() map[string]interface{} {
panic("Not implemented because MapType doesn't support validations")
}

Expand Down
29 changes: 12 additions & 17 deletions pkg/validations/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,31 +57,29 @@ type validationKwargs struct {
oneOf starlark.Sequence
}

// VaklidationMap returns a map of the validationKwargs and their values.
func (n NodeValidation) ValidationMap() map[string]interface{} {
v := n.kwargs

// ValidationMap returns a map of the validationKwargs and their values.
func (v NodeValidation) ValidationMap() map[string]interface{} {
validations := make(map[string]interface{})

if v.minLength != nil {
value, _ := v.minLength.Int64()
if v.kwargs.minLength != nil {
value, _ := v.kwargs.minLength.Int64()
validations["minLength"] = value
}
if v.maxLength != nil {
value, _ := v.maxLength.Int64()
if v.kwargs.maxLength != nil {
value, _ := v.kwargs.maxLength.Int64()
validations["maxLength"] = value
}
if v.min != nil {
value, _ := strconv.Atoi(v.min.String())
if v.kwargs.min != nil {
value, _ := strconv.Atoi(v.kwargs.min.String())
validations["min"] = value
}
if v.max != nil {
value, _ := strconv.Atoi(v.max.String())
if v.kwargs.max != nil {
value, _ := strconv.Atoi(v.kwargs.max.String())
validations["max"] = value
}
if v.oneOf != nil {
if v.kwargs.oneOf != nil {
enum := []interface{}{}
iter := starlark.Iterate(v.oneOf)
iter := starlark.Iterate(v.kwargs.oneOf)
defer iter.Done()
var x starlark.Value
for iter.Next(&x) {
Expand All @@ -96,15 +94,12 @@ func (n NodeValidation) ValidationMap() map[string]interface{} {
}

enum = append(enum, val)

}

validations["oneOf"] = enum

}

return validations

}

// Run takes a root Node, and threadName, and validates each Node in the tree.
Expand Down

0 comments on commit 7348f37

Please sign in to comment.