forked from go-swagger/go-swagger
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adds extra validations for operation parameters
- Loading branch information
Showing
8 changed files
with
216 additions
and
41 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,26 @@ | ||
# top-most EditorConfig file | ||
root = true | ||
|
||
# Unix-style newlines with a newline ending every file | ||
[*] | ||
end_of_line = lf | ||
insert_final_newline = true | ||
indent_style = space | ||
indent_size = 2 | ||
trim_trailing_whitespace = true | ||
|
||
# Set default charset | ||
[*.{js,py,go,scala,rb,java,html,css,less,sass,md}] | ||
charset = utf-8 | ||
|
||
# Tab indentation (no size specified) | ||
[*.go] | ||
indent_style = tab | ||
|
||
[*.md] | ||
trim_trailing_whitespace = false | ||
|
||
# Matches the exact files either package.json or .travis.yml | ||
[{package.json,.travis.yml}] | ||
indent_style = space | ||
indent_size = 2 |
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 |
---|---|---|
|
@@ -3,7 +3,6 @@ language: go | |
|
||
go: | ||
- 1.4.2 | ||
- tip | ||
|
||
before_install: | ||
# linting | ||
|
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,91 @@ | ||
package validate | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/casualjim/go-swagger/internal/testing/petstore" | ||
"github.com/casualjim/go-swagger/spec" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestValidateItems(t *testing.T) { | ||
|
||
} | ||
|
||
func TestValidateUniqueSecurityScopes(t *testing.T) { | ||
} | ||
|
||
func TestValidateUniqueScopesSecurityDefinitions(t *testing.T) { | ||
} | ||
|
||
func TestValidateReferenced(t *testing.T) { | ||
} | ||
|
||
func TestValidateRequiredDefinitions(t *testing.T) { | ||
} | ||
|
||
func TestValidateParameters(t *testing.T) { | ||
doc, api := petstore.NewAPI(t) | ||
validator := NewSpecValidator(spec.MustLoadSwagger20Schema(), api.Formats()) | ||
validator.spec = doc | ||
res := validator.validateParameters() | ||
assert.Empty(t, res.Errors) | ||
|
||
sw := doc.Spec() | ||
sw.Paths.Paths["/pets"].Get.Parameters = append(sw.Paths.Paths["/pets"].Get.Parameters, *spec.QueryParam("limit").Typed("string", "")) | ||
res = validator.validateParameters() | ||
assert.NotEmpty(t, res.Errors) | ||
|
||
doc, api = petstore.NewAPI(t) | ||
sw = doc.Spec() | ||
sw.Paths.Paths["/pets"].Post.Parameters = append(sw.Paths.Paths["/pets"].Post.Parameters, *spec.BodyParam("fake", spec.RefProperty("#/definitions/Pet"))) | ||
validator = NewSpecValidator(spec.MustLoadSwagger20Schema(), api.Formats()) | ||
validator.spec = doc | ||
res = validator.validateParameters() | ||
assert.NotEmpty(t, res.Errors) | ||
assert.Len(t, res.Errors, 1) | ||
assert.Contains(t, res.Errors[0].Error(), "has more than 1 body param") | ||
|
||
doc, api = petstore.NewAPI(t) | ||
sw = doc.Spec() | ||
pp := sw.Paths.Paths["/pets/{id}"] | ||
pp.Delete = nil | ||
var nameParams []spec.Parameter | ||
for _, p := range pp.Parameters { | ||
if p.Name == "id" { | ||
p.Name = "name" | ||
nameParams = append(nameParams, p) | ||
} | ||
} | ||
pp.Parameters = nameParams | ||
sw.Paths.Paths["/pets/{name}"] = pp | ||
doc.Reload() | ||
validator = NewSpecValidator(spec.MustLoadSwagger20Schema(), api.Formats()) | ||
validator.spec = doc | ||
res = validator.validateParameters() | ||
assert.NotEmpty(t, res.Errors) | ||
assert.Len(t, res.Errors, 1) | ||
assert.Contains(t, res.Errors[0].Error(), "overlaps with") | ||
|
||
doc, api = petstore.NewAPI(t) | ||
validator = NewSpecValidator(spec.MustLoadSwagger20Schema(), api.Formats()) | ||
validator.spec = doc | ||
sw = doc.Spec() | ||
pp = sw.Paths.Paths["/pets/{id}"] | ||
pp.Delete = nil | ||
pp.Get.Parameters = nameParams | ||
pp.Parameters = nil | ||
sw.Paths.Paths["/pets/{id}"] = pp | ||
doc.Reload() | ||
res = validator.validateParameters() | ||
assert.NotEmpty(t, res.Errors) | ||
assert.Len(t, res.Errors, 2) | ||
assert.Contains(t, res.Errors[1].Error(), "is not present in the path") | ||
assert.Contains(t, res.Errors[0].Error(), "has no parameter definition") | ||
} | ||
|
||
func TestValidateReferencesValid(t *testing.T) { | ||
} | ||
|
||
func TestValidateDefaultValueAgainstSchema(t *testing.T) { | ||
} |
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