MCPcopy Index your code
hub / github.com/oapi-codegen/oapi-codegen / removeOrphanedComponents

Function removeOrphanedComponents

pkg/codegen/prune.go:388–471  ·  view source on GitHub ↗
(swagger *openapi3.T, refs []string)

Source from the content-addressed store, hash-verified

386}
387
388func removeOrphanedComponents(swagger *openapi3.T, refs []string) int {
389 if swagger.Components == nil {
390 return 0
391 }
392
393 countRemoved := 0
394
395 for key := range swagger.Components.Schemas {
396 ref := fmt.Sprintf("#/components/schemas/%s", key)
397 if !slices.Contains(refs, ref) {
398 countRemoved++
399 delete(swagger.Components.Schemas, key)
400 }
401 }
402
403 for key := range swagger.Components.Parameters {
404 ref := fmt.Sprintf("#/components/parameters/%s", key)
405 if !slices.Contains(refs, ref) {
406 countRemoved++
407 delete(swagger.Components.Parameters, key)
408 }
409 }
410
411 // securitySchemes are an exception. definitions in securitySchemes
412 // are referenced directly by name. and not by $ref
413
414 // for key, _ := range swagger.Components.SecuritySchemes {
415 // ref := fmt.Sprintf("#/components/securitySchemes/%s", key)
416 // if !slices.Contains(refs, ref) {
417 // countRemoved++
418 // delete(swagger.Components.SecuritySchemes, key)
419 // }
420 // }
421
422 for key := range swagger.Components.RequestBodies {
423 ref := fmt.Sprintf("#/components/requestBodies/%s", key)
424 if !slices.Contains(refs, ref) {
425 countRemoved++
426 delete(swagger.Components.RequestBodies, key)
427 }
428 }
429
430 for key := range swagger.Components.Responses {
431 ref := fmt.Sprintf("#/components/responses/%s", key)
432 if !slices.Contains(refs, ref) {
433 countRemoved++
434 delete(swagger.Components.Responses, key)
435 }
436 }
437
438 for key := range swagger.Components.Headers {
439 ref := fmt.Sprintf("#/components/headers/%s", key)
440 if !slices.Contains(refs, ref) {
441 countRemoved++
442 delete(swagger.Components.Headers, key)
443 }
444 }
445

Callers 1

pruneUnusedComponentsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected