mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-01-05 07:27:21 +00:00
- Add GroupVersion as tags to OpenAPI spec
- Remove all end-point specs as they are not useful in light of GroupVersion tags in main spec
This commit is contained in:
@@ -24,7 +24,6 @@ import (
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
@@ -519,10 +518,6 @@ func TestValidOpenAPISpec(t *testing.T) {
|
||||
// TODO(mehdy): The actual validation part of these tests are timing out on jerkin but passing locally. Enable it after debugging timeout issue.
|
||||
disableValidation := true
|
||||
|
||||
// Saving specs to a temporary folder is a good way to debug spec generation without bringing up an actual
|
||||
// api server.
|
||||
saveSwaggerSpecs := false
|
||||
|
||||
// Validate OpenApi spec
|
||||
doc, err := loads.Spec(server.URL + "/swagger.json")
|
||||
if assert.NoError(err) {
|
||||
@@ -537,46 +532,4 @@ func TestValidOpenAPISpec(t *testing.T) {
|
||||
t.Logf("Validation is disabled because it is timing out on jenkins put passing locally.")
|
||||
}
|
||||
}
|
||||
|
||||
// validate specs on each end-point
|
||||
resp, err = http.Get(server.URL)
|
||||
if !assert.NoError(err) {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
assert.Equal(http.StatusOK, resp.StatusCode)
|
||||
var list unversioned.RootPaths
|
||||
if assert.NoError(decodeResponse(resp, &list)) {
|
||||
for _, path := range list.Paths {
|
||||
if !strings.HasPrefix(path, "/api") {
|
||||
continue
|
||||
}
|
||||
t.Logf("Validating open API spec on %v ...", path)
|
||||
|
||||
if saveSwaggerSpecs {
|
||||
resp, err = http.Get(server.URL + path + "/swagger.json")
|
||||
if !assert.NoError(err) {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
assert.Equal(http.StatusOK, resp.StatusCode)
|
||||
assert.NoError(writeResponseToFile(resp, "/tmp/swagger_"+strings.Replace(path, "/", "_", -1)+".json"))
|
||||
}
|
||||
|
||||
// Validate OpenApi spec on path
|
||||
doc, err := loads.Spec(server.URL + path + "/swagger.json")
|
||||
if assert.NoError(err) {
|
||||
validator := validate.NewSpecValidator(doc.Schema(), strfmt.Default)
|
||||
if !disableValidation {
|
||||
res, warns := validator.Validate(doc)
|
||||
assert.NoError(res.AsError())
|
||||
if !warns.IsValid() {
|
||||
t.Logf("Open API spec on %v has some warnings : %v", path, warns)
|
||||
}
|
||||
} else {
|
||||
t.Logf("Validation is disabled because it is timing out on jenkins but passing locally.")
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user