Skip to content

Commit 587e832

Browse files
committed
Built test for libopenapi issue
pb33f/libopenapi#415 I believe the users understanding of `dependentSchema` to be false. Here is my evidence.
1 parent 739ee26 commit 587e832

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

schema_validation/validate_schema_test.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -680,3 +680,53 @@ paths:
680680
// assert.Len(t, errors, 0)
681681
//
682682
//}
683+
684+
// https://github.com/pb33f/libopenapi/issues/415
685+
func TestValidateSchema_v3_1_DependentSchemas(t *testing.T) {
686+
spec := `openapi: 3.1.0
687+
paths:
688+
/burgers/createBurger:
689+
post:
690+
requestBody:
691+
content:
692+
application/json:
693+
schema:
694+
type: object
695+
properties:
696+
fishCake:
697+
type: object
698+
properties:
699+
bones:
700+
type: boolean
701+
dependentSchemas:
702+
fishCake:
703+
type: object
704+
properties:
705+
cream:
706+
type: number
707+
format: double
708+
required:
709+
- cream`
710+
711+
doc, _ := libopenapi.NewDocument([]byte(spec))
712+
713+
m, _ := doc.BuildV3Model()
714+
715+
exp := `{
716+
"fishCake": {
717+
"bones": true,
718+
"cream": 2.5
719+
}
720+
}`
721+
722+
sch := m.Model.Paths.PathItems.GetOrZero("/burgers/createBurger").Post.RequestBody.Content.GetOrZero("application/json").Schema
723+
724+
// create a schema validator
725+
v := NewSchemaValidator()
726+
727+
// validate!
728+
valid, errors := v.ValidateSchemaString(sch.Schema(), exp)
729+
730+
assert.True(t, valid)
731+
assert.Empty(t, errors)
732+
}

0 commit comments

Comments
 (0)