Skip to content

Commit

Permalink
Fixed glitch with multi example validation.
Browse files Browse the repository at this point in the history
discovered when running some specs through the doctor.
  • Loading branch information
daveshanley committed Apr 9, 2024
1 parent 2294f6c commit 61573d5
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
3 changes: 1 addition & 2 deletions functions/openapi/examples_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,8 @@ func (es ExamplesSchema) RunRule(_ []*yaml.Node, context model.RuleFunctionConte
}
}

var example map[string]interface{}
var example any
_ = ex.Decode(&example)

result := validateSchema(&x, "", "examples",
s, s, s.Value.GoLow().Examples.Value[x].ValueNode,
s.Value.GoLow().Examples.GetKeyNode(), example)
Expand Down
38 changes: 38 additions & 0 deletions functions/openapi/examples_schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,44 @@ components:

}

func TestExamplesSchema_TrainTravel(t *testing.T) {
yml := `openapi: 3.1
components:
schemas:
Station:
type: object
properties:
id:
type: string
format: uuid
examples:
- efdbb9d1-02c2-4bc3-afb7-6788d8782b1e
- b2e783e1-c824-4d63-b37a-d8d698862f1d`

document, err := libopenapi.NewDocument([]byte(yml))
if err != nil {
panic(fmt.Sprintf("cannot create new document: %e", err))
}

m, _ := document.BuildV3Model()
path := "$"

drDocument := drModel.NewDrDocument(m)

rule := buildOpenApiTestRuleAction(path, "examples_schema", "", nil)
ctx := buildOpenApiTestContext(model.CastToRuleAction(rule.Then), nil)

ctx.Document = document
ctx.DrDocument = drDocument
ctx.Rule = &rule

def := ExamplesSchema{}
res := def.RunRule(nil, ctx)

assert.Len(t, res, 0)

}

func TestExamplesSchema_Invalid(t *testing.T) {
yml := `openapi: 3.1
components:
Expand Down

0 comments on commit 61573d5

Please sign in to comment.