Use Swagger#UnmarshalJSON rather than json.Unmarshal

Since we're now using the experimental json code to deserialize
spec.Swagger, we should rather use UnmarshalJSON since this has a much
lower CPU overhead.
This commit is contained in:
Antoine Pelisse 2022-10-25 10:51:19 -07:00
parent 449c46258b
commit 5be7430fe3

View File

@ -22,7 +22,6 @@ import (
"net/http"
"strings"
utiljson "k8s.io/apimachinery/pkg/util/json"
"k8s.io/apiserver/pkg/authentication/user"
"k8s.io/apiserver/pkg/endpoints/request"
"k8s.io/kube-openapi/pkg/validation/spec"
@ -79,7 +78,7 @@ func (s *Downloader) Download(handler http.Handler, etag string) (returnSpec *sp
return nil, "", http.StatusNotFound, nil
case http.StatusOK:
openAPISpec := &spec.Swagger{}
if err := utiljson.Unmarshal(writer.data, openAPISpec); err != nil {
if err := openAPISpec.UnmarshalJSON(writer.data); err != nil {
return nil, "", 0, err
}
newEtag = writer.Header().Get("Etag")