swagger-core
swagger-core copied to clipboard
fix(core): SpecFilter follows ApiResponse $ref to avoid pruning referenced schemas
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$refbranch:- Resolve simple name via
RefUtils.extractSimpleName(ref).getLeft() - Mark the referenced ApiResponse component as used
- Traverse resolved
headersandcontentto collect schema refs
- Resolve simple name via
- 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:
- Define an operation with:
@ApiResponse(responseCode = "404", ref = "#/components/responses/MyCustomSchema")