openapi-aggregation: merge without clones

This commit is contained in:
Dr. Stefan Schimanski 2018-11-19 17:09:44 +01:00
parent 84f0629e95
commit 01bc4eff0e

View File

@ -196,13 +196,12 @@ func (s *specAggregator) buildOpenAPISpec() (specToReturn *spec.Swagger, err err
} }
sortByPriority(specs) sortByPriority(specs)
for _, specInfo := range specs { for _, specInfo := range specs {
// TODO: Make kube-openapi.MergeSpec(s) accept nil or empty spec as destination and just clone the spec in that case.
if specToReturn == nil { if specToReturn == nil {
specToReturn, err = aggregator.CloneSpec(specInfo.spec) specToReturn = &spec.Swagger{}
if err != nil { *specToReturn = *specInfo.spec
return nil, err // Paths and Definitions are set by MergeSpecsIgnorePathConflict
} specToReturn.Paths = nil
continue specToReturn.Definitions = nil
} }
if err := aggregator.MergeSpecsIgnorePathConflict(specToReturn, specInfo.spec); err != nil { if err := aggregator.MergeSpecsIgnorePathConflict(specToReturn, specInfo.spec); err != nil {
return nil, err return nil, err
@ -267,7 +266,7 @@ func (s *specAggregator) UpdateAPIServiceSpec(apiServiceName string, spec *spec.
// For APIServices (non-local) specs, only merge their /apis/ prefixed endpoint as it is the only paths // For APIServices (non-local) specs, only merge their /apis/ prefixed endpoint as it is the only paths
// proxy handler delegates. // proxy handler delegates.
if specInfo.apiService.Spec.Service != nil { if specInfo.apiService.Spec.Service != nil {
aggregator.FilterSpecByPaths(spec, []string{"/apis/"}) spec = aggregator.FilterSpecByPathsWithoutSideEffects(spec, []string{"/apis/"})
} }
return s.tryUpdatingServiceSpecs(&openAPISpecInfo{ return s.tryUpdatingServiceSpecs(&openAPISpecInfo{