Skip to content

bug: validation change the fail fast flag value  #283

@shaj13

Description

@shaj13

context:

fail fast flag value changed from internal visit validation and when error returned to the upper validation it return errSchema instead of detailed error since it check fail fast again.

goal:

no any validation options/setting passed to validation(visit*),
the default value of fail fast must be true and its value should not be changed until all recursive validations finished.

Got:
Input does not match the schema

Expected

Error at "/ownerName":Doesn't match schema "not"
Schema:
  {
    "not": {
      "type": "boolean"
    }
  }

Value:
  true

Reproduce:

package main

import (
	"fmt"

	"github.com/getkin/kin-openapi/openapi3"
)

func main() {
	data := map[string]interface{}{
		"name":      "kin-openapi",
		"ownerName": true,
	}
	s, err := openapi3.NewSwaggerLoader().LoadSwaggerFromData([]byte(api))
	if err != nil {
		panic(err)
	}
	err = s.Components.Schemas["Test"].Value.VisitJSON(data)
	fmt.Println(err)

	//
}

var api = `
openapi: "3.0.1"
components: 
  schemas: 
    Test: 
      properties: 
        name: 
          type: string
        ownerName: 
          not: 
            type: boolean
      type: object
`

Note:
in my use case the visit.JSON change failfast to true and return error
and the visitJSONObject check fail fast and return errSchema
i removed this if https://github.com/getkin/kin-openapi/blob/master/openapi3/schema.go#L1343 and it return error as expected,
when debuging the issue you will see visitJSON pass fail fast as false and when it return the value will be changed to true.

not sure why it changing the value, IMO settings must be by value not pointer even after fixing this one.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions