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

v0.16.3 #621

Merged
merged 1 commit into from
Feb 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion functions/openapi/examples_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ func changeKeys(depth int, node *yaml.Node) {
if i%2 != 0 {
continue // keys only.
}
if no.Tag != "!!str" {
if node.Tag != "!!seq" && no.Tag != "!!str" {
no.Tag = "!!str"
}
if len(no.Content) > 0 {
Expand Down
52 changes: 52 additions & 0 deletions functions/openapi/examples_schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,20 @@ paths:

}

/*
components:
schemas:
Test:
type: array
description: Test array with numbers
items:
type: number
example:
- 0 # <- This gives a warning
- 0
- 0
*/

func TestExamplesSchema_HandleJSONTime(t *testing.T) {
yml := `openapi: 3.1
components:
Expand Down Expand Up @@ -538,3 +552,41 @@ components:

assert.Len(t, res, 0)
}

// https://github.com/daveshanley/vacuum/issues/615
func TestExamplesSchema_HandleArrays(t *testing.T) {
yml := `openapi: 3.1.0
components:
schemas:
Test:
type: array
description: Test array with numbers
items:
type: number
example:
- 0
- 0
- 0`

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)
}
Loading