swagger-core icon indicating copy to clipboard operation
swagger-core copied to clipboard

fix(core): SpecFilter follows ApiResponse $ref to avoid pruning referenced schemas

Open kuntal1461 opened this issue 3 months ago • 0 comments

Fixes #4960

Pull Request

Thank you for contributing to swagger-core!


Description

Bug fix: SpecFilter.removeBrokenReferenceDefinitions did not follow ApiResponse.$ref, so schemas reachable only through #/components/responses/* were considered unreferenced and pruned.
This PR teaches the pruning pass to resolve ApiResponse.$ref and traverse the resolved response's headers and content to collect schema refs, ensuring those schemas are retained.

What changed (minimal patch):

  • In addApiResponseSchemaRef(...), add a $ref branch:
    • Resolve simple name via RefUtils.extractSimpleName(ref).getLeft()
    • Mark the referenced ApiResponse component as used
    • Traverse resolved headers and content to collect schema refs
  • No signature changes to existing helper methods; no behavioral changes outside pruning.

Fixes: #4960

Type of Change

  • [x] 🐛 Bug fix

Checklist

  • [x] The PR title is descriptive
  • [x] The code builds and passes tests locally (mvn clean install)
  • [ ] I have added/updated tests as needed (see Test Plan below)
  • [ ] I have added/updated documentation where applicable
  • [x] I have linked related issues (if any)

Test Plan

Manual verification:

  1. Define an operation with:
    @ApiResponse(responseCode = "404", ref = "#/components/responses/MyCustomSchema")
    

kuntal1461 avatar Sep 28 '25 09:09 kuntal1461