Blame vendor/github.com/deepmap/oapi-codegen/pkg/codegen/prune.go

Packit Service 3a6627
package codegen
Packit Service 3a6627
Packit Service 3a6627
import (
Packit Service 3a6627
	"fmt"
Packit Service 3a6627
Packit Service 3a6627
	"github.com/getkin/kin-openapi/openapi3"
Packit Service 3a6627
)
Packit Service 3a6627
Packit Service 3a6627
func stringInSlice(a string, list []string) bool {
Packit Service 3a6627
	for _, b := range list {
Packit Service 3a6627
		if b == a {
Packit Service 3a6627
			return true
Packit Service 3a6627
		}
Packit Service 3a6627
	}
Packit Service 3a6627
	return false
Packit Service 3a6627
}
Packit Service 3a6627
Packit Service 3a6627
type RefWrapper struct {
Packit Service 3a6627
	Ref       string
Packit Service 3a6627
	HasValue  bool
Packit Service 3a6627
	SourceRef interface{}
Packit Service 3a6627
}
Packit Service 3a6627
Packit Service 3a6627
func walkSwagger(swagger *openapi3.Swagger, doFn func(RefWrapper) (bool, error)) error {
Packit Service 3a6627
	if swagger == nil {
Packit Service 3a6627
		return nil
Packit Service 3a6627
	}
Packit Service 3a6627
Packit Service 3a6627
	for _, p := range swagger.Paths {
Packit Service 3a6627
		for _, param := range p.Parameters {
Packit Service 3a6627
			walkParameterRef(param, doFn)
Packit Service 3a6627
		}
Packit Service 3a6627
		for _, op := range p.Operations() {
Packit Service 3a6627
			walkOperation(op, doFn)
Packit Service 3a6627
		}
Packit Service 3a6627
	}
Packit Service 3a6627
Packit Service 3a6627
	walkComponents(&swagger.Components, doFn)
Packit Service 3a6627
Packit Service 3a6627
	return nil
Packit Service 3a6627
}
Packit Service 3a6627
Packit Service 3a6627
func walkOperation(op *openapi3.Operation, doFn func(RefWrapper) (bool, error)) error {
Packit Service 3a6627
	// Not a valid ref, ignore it and continue
Packit Service 3a6627
	if op == nil {
Packit Service 3a6627
		return nil
Packit Service 3a6627
	}
Packit Service 3a6627
Packit Service 3a6627
	for _, param := range op.Parameters {
Packit Service 3a6627
		_ = walkParameterRef(param, doFn)
Packit Service 3a6627
	}
Packit Service 3a6627
Packit Service 3a6627
	_ = walkRequestBodyRef(op.RequestBody, doFn)
Packit Service 3a6627
Packit Service 3a6627
	for _, response := range op.Responses {
Packit Service 3a6627
		walkResponseRef(response, doFn)
Packit Service 3a6627
	}
Packit Service 3a6627
Packit Service 3a6627
	for _, callback := range op.Callbacks {
Packit Service 3a6627
		walkCallbackRef(callback, doFn)
Packit Service 3a6627
	}
Packit Service 3a6627
Packit Service 3a6627
	return nil
Packit Service 3a6627
}
Packit Service 3a6627
Packit Service 3a6627
func walkComponents(components *openapi3.Components, doFn func(RefWrapper) (bool, error)) error {
Packit Service 3a6627
	// Not a valid ref, ignore it and continue
Packit Service 3a6627
	if components == nil {
Packit Service 3a6627
		return nil
Packit Service 3a6627
	}
Packit Service 3a6627
Packit Service 3a6627
	for _, schema := range components.Schemas {
Packit Service 3a6627
		_ = walkSchemaRef(schema, doFn)
Packit Service 3a6627
	}
Packit Service 3a6627
Packit Service 3a6627
	for _, param := range components.Parameters {
Packit Service 3a6627
		_ = walkParameterRef(param, doFn)
Packit Service 3a6627
	}
Packit Service 3a6627
Packit Service 3a6627
	for _, header := range components.Headers {
Packit Service 3a6627
		_ = walkHeaderRef(header, doFn)
Packit Service 3a6627
	}
Packit Service 3a6627
Packit Service 3a6627
	for _, requestBody := range components.RequestBodies {
Packit Service 3a6627
		_ = walkRequestBodyRef(requestBody, doFn)
Packit Service 3a6627
	}
Packit Service 3a6627
Packit Service 3a6627
	for _, response := range components.Responses {
Packit Service 3a6627
		_ = walkResponseRef(response, doFn)
Packit Service 3a6627
	}
Packit Service 3a6627
Packit Service 3a6627
	for _, securityScheme := range components.SecuritySchemes {
Packit Service 3a6627
		_ = walkSecuritySchemeRef(securityScheme, doFn)
Packit Service 3a6627
	}
Packit Service 3a6627
Packit Service 3a6627
	for _, example := range components.Examples {
Packit Service 3a6627
		_ = walkExampleRef(example, doFn)
Packit Service 3a6627
	}
Packit Service 3a6627
Packit Service 3a6627
	for _, link := range components.Links {
Packit Service 3a6627
		_ = walkLinkRef(link, doFn)
Packit Service 3a6627
	}
Packit Service 3a6627
Packit Service 3a6627
	for _, callback := range components.Callbacks {
Packit Service 3a6627
		_ = walkCallbackRef(callback, doFn)
Packit Service 3a6627
	}
Packit Service 3a6627
Packit Service 3a6627
	return nil
Packit Service 3a6627
}
Packit Service 3a6627
Packit Service 3a6627
func walkSchemaRef(ref *openapi3.SchemaRef, doFn func(RefWrapper) (bool, error)) error {
Packit Service 3a6627
	// Not a valid ref, ignore it and continue
Packit Service 3a6627
	if ref == nil {
Packit Service 3a6627
		return nil
Packit Service 3a6627
	}
Packit Service 3a6627
	refWrapper := RefWrapper{Ref: ref.Ref, HasValue: ref.Value != nil, SourceRef: ref}
Packit Service 3a6627
	shouldContinue, err := doFn(refWrapper)
Packit Service 3a6627
	if err != nil {
Packit Service 3a6627
		return err
Packit Service 3a6627
	}
Packit Service 3a6627
	if !shouldContinue {
Packit Service 3a6627
		return nil
Packit Service 3a6627
	}
Packit Service 3a6627
	if ref.Value == nil {
Packit Service 3a6627
		return nil
Packit Service 3a6627
	}
Packit Service 3a6627
Packit Service 3a6627
	for _, ref := range ref.Value.OneOf {
Packit Service 3a6627
		walkSchemaRef(ref, doFn)
Packit Service 3a6627
	}
Packit Service 3a6627
Packit Service 3a6627
	for _, ref := range ref.Value.AnyOf {
Packit Service 3a6627
		walkSchemaRef(ref, doFn)
Packit Service 3a6627
	}
Packit Service 3a6627
Packit Service 3a6627
	for _, ref := range ref.Value.AllOf {
Packit Service 3a6627
		walkSchemaRef(ref, doFn)
Packit Service 3a6627
	}
Packit Service 3a6627
Packit Service 3a6627
	walkSchemaRef(ref.Value.Not, doFn)
Packit Service 3a6627
	walkSchemaRef(ref.Value.Items, doFn)
Packit Service 3a6627
Packit Service 3a6627
	for _, ref := range ref.Value.Properties {
Packit Service 3a6627
		walkSchemaRef(ref, doFn)
Packit Service 3a6627
	}
Packit Service 3a6627
Packit Service 3a6627
	walkSchemaRef(ref.Value.AdditionalProperties, doFn)
Packit Service 3a6627
Packit Service 3a6627
	return nil
Packit Service 3a6627
}
Packit Service 3a6627
Packit Service 3a6627
func walkParameterRef(ref *openapi3.ParameterRef, doFn func(RefWrapper) (bool, error)) error {
Packit Service 3a6627
	// Not a valid ref, ignore it and continue
Packit Service 3a6627
	if ref == nil {
Packit Service 3a6627
		return nil
Packit Service 3a6627
	}
Packit Service 3a6627
	refWrapper := RefWrapper{Ref: ref.Ref, HasValue: ref.Value != nil, SourceRef: ref}
Packit Service 3a6627
	shouldContinue, err := doFn(refWrapper)
Packit Service 3a6627
	if err != nil {
Packit Service 3a6627
		return err
Packit Service 3a6627
	}
Packit Service 3a6627
	if !shouldContinue {
Packit Service 3a6627
		return nil
Packit Service 3a6627
	}
Packit Service 3a6627
	if ref.Value == nil {
Packit Service 3a6627
		return nil
Packit Service 3a6627
	}
Packit Service 3a6627
Packit Service 3a6627
	walkSchemaRef(ref.Value.Schema, doFn)
Packit Service 3a6627
Packit Service 3a6627
	for _, example := range ref.Value.Examples {
Packit Service 3a6627
		walkExampleRef(example, doFn)
Packit Service 3a6627
	}
Packit Service 3a6627
Packit Service 3a6627
	for _, mediaType := range ref.Value.Content {
Packit Service 3a6627
		if mediaType == nil {
Packit Service 3a6627
			continue
Packit Service 3a6627
		}
Packit Service 3a6627
		walkSchemaRef(mediaType.Schema, doFn)
Packit Service 3a6627
Packit Service 3a6627
		for _, example := range mediaType.Examples {
Packit Service 3a6627
			walkExampleRef(example, doFn)
Packit Service 3a6627
		}
Packit Service 3a6627
	}
Packit Service 3a6627
Packit Service 3a6627
	return nil
Packit Service 3a6627
}
Packit Service 3a6627
Packit Service 3a6627
func walkRequestBodyRef(ref *openapi3.RequestBodyRef, doFn func(RefWrapper) (bool, error)) error {
Packit Service 3a6627
	// Not a valid ref, ignore it and continue
Packit Service 3a6627
	if ref == nil {
Packit Service 3a6627
		return nil
Packit Service 3a6627
	}
Packit Service 3a6627
	refWrapper := RefWrapper{Ref: ref.Ref, HasValue: ref.Value != nil, SourceRef: ref}
Packit Service 3a6627
	shouldContinue, err := doFn(refWrapper)
Packit Service 3a6627
	if err != nil {
Packit Service 3a6627
		return err
Packit Service 3a6627
	}
Packit Service 3a6627
	if !shouldContinue {
Packit Service 3a6627
		return nil
Packit Service 3a6627
	}
Packit Service 3a6627
	if ref.Value == nil {
Packit Service 3a6627
		return nil
Packit Service 3a6627
	}
Packit Service 3a6627
Packit Service 3a6627
	for _, mediaType := range ref.Value.Content {
Packit Service 3a6627
		if mediaType == nil {
Packit Service 3a6627
			continue
Packit Service 3a6627
		}
Packit Service 3a6627
		walkSchemaRef(mediaType.Schema, doFn)
Packit Service 3a6627
Packit Service 3a6627
		for _, example := range mediaType.Examples {
Packit Service 3a6627
			walkExampleRef(example, doFn)
Packit Service 3a6627
		}
Packit Service 3a6627
	}
Packit Service 3a6627
Packit Service 3a6627
	return nil
Packit Service 3a6627
}
Packit Service 3a6627
Packit Service 3a6627
func walkResponseRef(ref *openapi3.ResponseRef, doFn func(RefWrapper) (bool, error)) error {
Packit Service 3a6627
	// Not a valid ref, ignore it and continue
Packit Service 3a6627
	if ref == nil {
Packit Service 3a6627
		return nil
Packit Service 3a6627
	}
Packit Service 3a6627
	refWrapper := RefWrapper{Ref: ref.Ref, HasValue: ref.Value != nil, SourceRef: ref}
Packit Service 3a6627
	shouldContinue, err := doFn(refWrapper)
Packit Service 3a6627
	if err != nil {
Packit Service 3a6627
		return err
Packit Service 3a6627
	}
Packit Service 3a6627
	if !shouldContinue {
Packit Service 3a6627
		return nil
Packit Service 3a6627
	}
Packit Service 3a6627
	if ref.Value == nil {
Packit Service 3a6627
		return nil
Packit Service 3a6627
	}
Packit Service 3a6627
Packit Service 3a6627
	for _, header := range ref.Value.Headers {
Packit Service 3a6627
		walkHeaderRef(header, doFn)
Packit Service 3a6627
	}
Packit Service 3a6627
Packit Service 3a6627
	for _, mediaType := range ref.Value.Content {
Packit Service 3a6627
		if mediaType == nil {
Packit Service 3a6627
			continue
Packit Service 3a6627
		}
Packit Service 3a6627
		walkSchemaRef(mediaType.Schema, doFn)
Packit Service 3a6627
Packit Service 3a6627
		for _, example := range mediaType.Examples {
Packit Service 3a6627
			walkExampleRef(example, doFn)
Packit Service 3a6627
		}
Packit Service 3a6627
	}
Packit Service 3a6627
Packit Service 3a6627
	for _, link := range ref.Value.Links {
Packit Service 3a6627
		walkLinkRef(link, doFn)
Packit Service 3a6627
	}
Packit Service 3a6627
Packit Service 3a6627
	return nil
Packit Service 3a6627
}
Packit Service 3a6627
Packit Service 3a6627
func walkCallbackRef(ref *openapi3.CallbackRef, doFn func(RefWrapper) (bool, error)) error {
Packit Service 3a6627
	// Not a valid ref, ignore it and continue
Packit Service 3a6627
	if ref == nil {
Packit Service 3a6627
		return nil
Packit Service 3a6627
	}
Packit Service 3a6627
	refWrapper := RefWrapper{Ref: ref.Ref, HasValue: ref.Value != nil, SourceRef: ref}
Packit Service 3a6627
	shouldContinue, err := doFn(refWrapper)
Packit Service 3a6627
	if err != nil {
Packit Service 3a6627
		return err
Packit Service 3a6627
	}
Packit Service 3a6627
	if !shouldContinue {
Packit Service 3a6627
		return nil
Packit Service 3a6627
	}
Packit Service 3a6627
	if ref.Value == nil {
Packit Service 3a6627
		return nil
Packit Service 3a6627
	}
Packit Service 3a6627
Packit Service 3a6627
	for _, pathItem := range *ref.Value {
Packit Service 3a6627
		for _, parameter := range pathItem.Parameters {
Packit Service 3a6627
			walkParameterRef(parameter, doFn)
Packit Service 3a6627
		}
Packit Service 3a6627
		walkOperation(pathItem.Connect, doFn)
Packit Service 3a6627
		walkOperation(pathItem.Delete, doFn)
Packit Service 3a6627
		walkOperation(pathItem.Get, doFn)
Packit Service 3a6627
		walkOperation(pathItem.Head, doFn)
Packit Service 3a6627
		walkOperation(pathItem.Options, doFn)
Packit Service 3a6627
		walkOperation(pathItem.Patch, doFn)
Packit Service 3a6627
		walkOperation(pathItem.Post, doFn)
Packit Service 3a6627
		walkOperation(pathItem.Put, doFn)
Packit Service 3a6627
		walkOperation(pathItem.Trace, doFn)
Packit Service 3a6627
	}
Packit Service 3a6627
Packit Service 3a6627
	return nil
Packit Service 3a6627
}
Packit Service 3a6627
Packit Service 3a6627
func walkHeaderRef(ref *openapi3.HeaderRef, doFn func(RefWrapper) (bool, error)) error {
Packit Service 3a6627
	// Not a valid ref, ignore it and continue
Packit Service 3a6627
	if ref == nil {
Packit Service 3a6627
		return nil
Packit Service 3a6627
	}
Packit Service 3a6627
	refWrapper := RefWrapper{Ref: ref.Ref, HasValue: ref.Value != nil, SourceRef: ref}
Packit Service 3a6627
	shouldContinue, err := doFn(refWrapper)
Packit Service 3a6627
	if err != nil {
Packit Service 3a6627
		return err
Packit Service 3a6627
	}
Packit Service 3a6627
	if !shouldContinue {
Packit Service 3a6627
		return nil
Packit Service 3a6627
	}
Packit Service 3a6627
	if ref.Value == nil {
Packit Service 3a6627
		return nil
Packit Service 3a6627
	}
Packit Service 3a6627
Packit Service 3a6627
	walkSchemaRef(ref.Value.Schema, doFn)
Packit Service 3a6627
Packit Service 3a6627
	return nil
Packit Service 3a6627
}
Packit Service 3a6627
Packit Service 3a6627
func walkSecuritySchemeRef(ref *openapi3.SecuritySchemeRef, doFn func(RefWrapper) (bool, error)) error {
Packit Service 3a6627
	// Not a valid ref, ignore it and continue
Packit Service 3a6627
	if ref == nil {
Packit Service 3a6627
		return nil
Packit Service 3a6627
	}
Packit Service 3a6627
	refWrapper := RefWrapper{Ref: ref.Ref, HasValue: ref.Value != nil, SourceRef: ref}
Packit Service 3a6627
	shouldContinue, err := doFn(refWrapper)
Packit Service 3a6627
	if err != nil {
Packit Service 3a6627
		return err
Packit Service 3a6627
	}
Packit Service 3a6627
	if !shouldContinue {
Packit Service 3a6627
		return nil
Packit Service 3a6627
	}
Packit Service 3a6627
	if ref.Value == nil {
Packit Service 3a6627
		return nil
Packit Service 3a6627
	}
Packit Service 3a6627
Packit Service 3a6627
	// NOTE: `SecuritySchemeRef`s don't contain any children that can contain refs
Packit Service 3a6627
Packit Service 3a6627
	return nil
Packit Service 3a6627
}
Packit Service 3a6627
Packit Service 3a6627
func walkLinkRef(ref *openapi3.LinkRef, doFn func(RefWrapper) (bool, error)) error {
Packit Service 3a6627
	// Not a valid ref, ignore it and continue
Packit Service 3a6627
	if ref == nil {
Packit Service 3a6627
		return nil
Packit Service 3a6627
	}
Packit Service 3a6627
	refWrapper := RefWrapper{Ref: ref.Ref, HasValue: ref.Value != nil, SourceRef: ref}
Packit Service 3a6627
	shouldContinue, err := doFn(refWrapper)
Packit Service 3a6627
	if err != nil {
Packit Service 3a6627
		return err
Packit Service 3a6627
	}
Packit Service 3a6627
	if !shouldContinue {
Packit Service 3a6627
		return nil
Packit Service 3a6627
	}
Packit Service 3a6627
	if ref.Value == nil {
Packit Service 3a6627
		return nil
Packit Service 3a6627
	}
Packit Service 3a6627
Packit Service 3a6627
	return nil
Packit Service 3a6627
}
Packit Service 3a6627
Packit Service 3a6627
func walkExampleRef(ref *openapi3.ExampleRef, doFn func(RefWrapper) (bool, error)) error {
Packit Service 3a6627
	// Not a valid ref, ignore it and continue
Packit Service 3a6627
	if ref == nil {
Packit Service 3a6627
		return nil
Packit Service 3a6627
	}
Packit Service 3a6627
	refWrapper := RefWrapper{Ref: ref.Ref, HasValue: ref.Value != nil, SourceRef: ref}
Packit Service 3a6627
	shouldContinue, err := doFn(refWrapper)
Packit Service 3a6627
	if err != nil {
Packit Service 3a6627
		return err
Packit Service 3a6627
	}
Packit Service 3a6627
	if !shouldContinue {
Packit Service 3a6627
		return nil
Packit Service 3a6627
	}
Packit Service 3a6627
	if ref.Value == nil {
Packit Service 3a6627
		return nil
Packit Service 3a6627
	}
Packit Service 3a6627
Packit Service 3a6627
	// NOTE: `ExampleRef`s don't contain any children that can contain refs
Packit Service 3a6627
Packit Service 3a6627
	return nil
Packit Service 3a6627
}
Packit Service 3a6627
Packit Service 3a6627
func findComponentRefs(swagger *openapi3.Swagger) []string {
Packit Service 3a6627
	refs := []string{}
Packit Service 3a6627
Packit Service 3a6627
	walkSwagger(swagger, func(ref RefWrapper) (bool, error) {
Packit Service 3a6627
		if ref.Ref != "" {
Packit Service 3a6627
			refs = append(refs, ref.Ref)
Packit Service 3a6627
			return false, nil
Packit Service 3a6627
		}
Packit Service 3a6627
		return true, nil
Packit Service 3a6627
	})
Packit Service 3a6627
Packit Service 3a6627
	return refs
Packit Service 3a6627
}
Packit Service 3a6627
Packit Service 3a6627
func removeOrphanedComponents(swagger *openapi3.Swagger, refs []string) int {
Packit Service 3a6627
	countRemoved := 0
Packit Service 3a6627
Packit Service 3a6627
	for key, _ := range swagger.Components.Schemas {
Packit Service 3a6627
		ref := fmt.Sprintf("#/components/schemas/%s", key)
Packit Service 3a6627
		if !stringInSlice(ref, refs) {
Packit Service 3a6627
			countRemoved++
Packit Service 3a6627
			delete(swagger.Components.Schemas, key)
Packit Service 3a6627
		}
Packit Service 3a6627
	}
Packit Service 3a6627
Packit Service 3a6627
	for key, _ := range swagger.Components.Parameters {
Packit Service 3a6627
		ref := fmt.Sprintf("#/components/parameters/%s", key)
Packit Service 3a6627
		if !stringInSlice(ref, refs) {
Packit Service 3a6627
			countRemoved++
Packit Service 3a6627
			delete(swagger.Components.Parameters, key)
Packit Service 3a6627
		}
Packit Service 3a6627
	}
Packit Service 3a6627
Packit Service 3a6627
	// securitySchemes are an exception. definitions in securitySchemes
Packit Service 3a6627
	// are referenced directly by name. and not by $ref
Packit Service 3a6627
Packit Service 3a6627
	// for key, _ := range swagger.Components.SecuritySchemes {
Packit Service 3a6627
	// 	ref := fmt.Sprintf("#/components/securitySchemes/%s", key)
Packit Service 3a6627
	// 	if !stringInSlice(ref, refs) {
Packit Service 3a6627
	// 		countRemoved++
Packit Service 3a6627
	// 		delete(swagger.Components.SecuritySchemes, key)
Packit Service 3a6627
	// 	}
Packit Service 3a6627
	// }
Packit Service 3a6627
Packit Service 3a6627
	for key, _ := range swagger.Components.RequestBodies {
Packit Service 3a6627
		ref := fmt.Sprintf("#/components/requestBodies/%s", key)
Packit Service 3a6627
		if !stringInSlice(ref, refs) {
Packit Service 3a6627
			countRemoved++
Packit Service 3a6627
			delete(swagger.Components.RequestBodies, key)
Packit Service 3a6627
		}
Packit Service 3a6627
	}
Packit Service 3a6627
Packit Service 3a6627
	for key, _ := range swagger.Components.Responses {
Packit Service 3a6627
		ref := fmt.Sprintf("#/components/responses/%s", key)
Packit Service 3a6627
		if !stringInSlice(ref, refs) {
Packit Service 3a6627
			countRemoved++
Packit Service 3a6627
			delete(swagger.Components.Responses, key)
Packit Service 3a6627
		}
Packit Service 3a6627
	}
Packit Service 3a6627
Packit Service 3a6627
	for key, _ := range swagger.Components.Headers {
Packit Service 3a6627
		ref := fmt.Sprintf("#/components/headers/%s", key)
Packit Service 3a6627
		if !stringInSlice(ref, refs) {
Packit Service 3a6627
			countRemoved++
Packit Service 3a6627
			delete(swagger.Components.Headers, key)
Packit Service 3a6627
		}
Packit Service 3a6627
	}
Packit Service 3a6627
Packit Service 3a6627
	for key, _ := range swagger.Components.Examples {
Packit Service 3a6627
		ref := fmt.Sprintf("#/components/examples/%s", key)
Packit Service 3a6627
		if !stringInSlice(ref, refs) {
Packit Service 3a6627
			countRemoved++
Packit Service 3a6627
			delete(swagger.Components.Examples, key)
Packit Service 3a6627
		}
Packit Service 3a6627
	}
Packit Service 3a6627
Packit Service 3a6627
	for key, _ := range swagger.Components.Links {
Packit Service 3a6627
		ref := fmt.Sprintf("#/components/links/%s", key)
Packit Service 3a6627
		if !stringInSlice(ref, refs) {
Packit Service 3a6627
			countRemoved++
Packit Service 3a6627
			delete(swagger.Components.Links, key)
Packit Service 3a6627
		}
Packit Service 3a6627
	}
Packit Service 3a6627
Packit Service 3a6627
	for key, _ := range swagger.Components.Callbacks {
Packit Service 3a6627
		ref := fmt.Sprintf("#/components/callbacks/%s", key)
Packit Service 3a6627
		if !stringInSlice(ref, refs) {
Packit Service 3a6627
			countRemoved++
Packit Service 3a6627
			delete(swagger.Components.Callbacks, key)
Packit Service 3a6627
		}
Packit Service 3a6627
	}
Packit Service 3a6627
Packit Service 3a6627
	return countRemoved
Packit Service 3a6627
}
Packit Service 3a6627
Packit Service 3a6627
func pruneUnusedComponents(swagger *openapi3.Swagger) {
Packit Service 3a6627
	for {
Packit Service 3a6627
		refs := findComponentRefs(swagger)
Packit Service 3a6627
		countRemoved := removeOrphanedComponents(swagger, refs)
Packit Service 3a6627
		if countRemoved < 1 {
Packit Service 3a6627
			break
Packit Service 3a6627
		}
Packit Service 3a6627
	}
Packit Service 3a6627
}