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.
Deterministic validation (getkin#602)
- Loading branch information
Showing
17 changed files
with
1,284 additions
and
81 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
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
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
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
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,34 @@ | ||
package openapi3 | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestIssue601(t *testing.T) { | ||
// Document is invalid: first validation error returned is because | ||
// schema: | ||
// example: {key: value} | ||
// is not how schema examples are defined (but how components' examples are defined. Components are maps.) | ||
// Correct code should be: | ||
// schema: {example: value} | ||
sl := NewLoader() | ||
doc, err := sl.LoadFromFile("testdata/lxkns.yaml") | ||
require.NoError(t, err) | ||
|
||
err = doc.Validate(sl.Context) | ||
require.Contains(t, err.Error(), `invalid components: invalid schema example: Error at "/type": property "type" is missing`) | ||
require.Contains(t, err.Error(), `| Error at "/nsid": property "nsid" is missing`) | ||
|
||
err = doc.Validate(sl.Context, DisableExamplesValidation()) | ||
require.NoError(t, err) | ||
|
||
// Now let's remove all the invalid parts | ||
for _, schema := range doc.Components.Schemas { | ||
schema.Value.Example = nil | ||
} | ||
|
||
err = doc.Validate(sl.Context) | ||
require.NoError(t, 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
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
Oops, something went wrong.