-
-
Notifications
You must be signed in to change notification settings - Fork 432
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
openapi3: allow YAML-marshaling invalid specs (#977)
* openapi3: allow YAML-marshaling invalid specs Signed-off-by: Pierre Fenoll <pierrefenoll@gmail.com> * fixes Signed-off-by: Pierre Fenoll <pierrefenoll@gmail.com> --------- Signed-off-by: Pierre Fenoll <pierrefenoll@gmail.com>
- Loading branch information
Showing
8 changed files
with
93 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package openapi3 | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"gopkg.in/yaml.v3" | ||
) | ||
|
||
func TestIssue972(t *testing.T) { | ||
type testcase struct { | ||
spec string | ||
validationErrorContains string | ||
} | ||
|
||
base := ` | ||
openapi: 3.0.2 | ||
paths: {} | ||
components: {} | ||
` | ||
|
||
for _, tc := range []testcase{{ | ||
spec: base, | ||
validationErrorContains: "invalid info: must be an object", | ||
}, { | ||
spec: base + ` | ||
info: | ||
title: "Hello World REST APIs" | ||
version: "1.0" | ||
`, | ||
}, { | ||
spec: base + ` | ||
info: null | ||
`, | ||
validationErrorContains: "invalid info: must be an object", | ||
}, { | ||
spec: base + ` | ||
info: {} | ||
`, | ||
validationErrorContains: "invalid info: value of version must be a non-empty string", | ||
}, { | ||
spec: base + ` | ||
info: | ||
title: "Hello World REST APIs" | ||
`, | ||
validationErrorContains: "invalid info: value of version must be a non-empty string", | ||
}} { | ||
t.Logf("spec: %s", tc.spec) | ||
|
||
loader := &Loader{} | ||
doc, err := loader.LoadFromData([]byte(tc.spec)) | ||
assert.NoError(t, err) | ||
assert.NotNil(t, doc) | ||
|
||
err = doc.Validate(loader.Context) | ||
if e := tc.validationErrorContains; e != "" { | ||
assert.ErrorContains(t, err, e) | ||
} else { | ||
assert.NoError(t, err) | ||
} | ||
|
||
txt, err := yaml.Marshal(doc) | ||
assert.NoError(t, err) | ||
assert.NotEmpty(t, txt) | ||
} | ||
} |
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