forked from getkin/kin-openapi
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Validate default values against schema (getkin#610)
- Loading branch information
Showing
2 changed files
with
59 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package openapi3 | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestIssue136(t *testing.T) { | ||
specf := func(dflt string) string { | ||
return ` | ||
openapi: 3.0.2 | ||
info: | ||
title: "Hello World REST APIs" | ||
version: "1.0" | ||
paths: {} | ||
components: | ||
schemas: | ||
SomeSchema: | ||
type: string | ||
default: ` + dflt + ` | ||
` | ||
} | ||
|
||
for _, testcase := range []struct { | ||
dflt, err string | ||
}{ | ||
{ | ||
dflt: `"foo"`, | ||
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) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters