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
About validating default: {}
for type: object
#673
Comments
Unit test to reproduce this issue using the latest master code: func TestIssue673(t *testing.T) {
specf := func(dflt string) string {
return `
openapi: 3.0.0
info:
title: "Hello World REST APIs"
version: "1.0"
paths: {}
components:
schemas:
SomeSchema:
type: object
default: {}
required:
- field
properties:
field:
type: string
default: ` + dflt + `
`
}
for _, testcase := range []struct {
dflt, err string
}{
{
dflt: `"foo"`,
err: "",
},
{
dflt: `""`,
err: "",
},
{
dflt: `1`,
err: "invalid components: invalid schema default: Field must be set to string or not be present",
},
} {
t.Run(testcase.dflt, func(t *testing.T) {
spec := specf(testcase.dflt)
sl := NewLoader()
doc, err := sl.LoadFromData([]byte(spec))
require.NoError(t, err)
err = doc.Validate(sl.Context)
if testcase.err == "" {
require.NoError(t, err)
} else {
require.Error(t, err, testcase.err)
}
})
}
} Output:
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I noticed with the introduction of #610, the following schema will fail (but it was not before #610):
According to my limited knowledge on OpenAPI v3, this yaml is valid, so could you help confirm if it's a regression?
BTW: removing
default: {}
can make kin validator happy, but I don't think that's mandatory in OpenAPI spec's POV.The text was updated successfully, but these errors were encountered: