feat: add clean and optimize commands for OpenAPI specifications - #36
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR adds two powerful new CLI commands for OpenAPI specification management: clean to remove unused components and optimize to deduplicate inline schemas. The implementation includes comprehensive walking infrastructure, interactive UI features, and extensive test coverage.
Key changes:
- Clean Command: Removes unused components while tracking all reference types including security scheme name references
- Optimize Command: Finds duplicate inline schemas and extracts them to reusable components with interactive naming
- Enhanced Walking Infrastructure: Added
SetAtLocationutility and updated location context naming for consistency
Reviewed Changes
Copilot reviewed 37 out of 38 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| walk/set.go | Core utility for setting values at specific locations in complex data structures |
| walk/set_test.go | Comprehensive test suite for the SetAtLocation functionality |
| openapi/clean.go | Implementation of the Clean function to remove unused components |
| openapi/optimize.go | Implementation of the Optimize function for schema deduplication |
| openapi/cmd/clean.go | CLI interface for the clean command with progress reporting |
| openapi/cmd/optimize.go | CLI interface for optimize command with interactive schema naming |
| walk/locations.go | Renamed Parent field to ParentMatchFunc for clarity |
| Multiple walk files | Updated to use new ParentMatchFunc naming convention |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
Contributor
📊 Test Coverage ReportCurrent Coverage: Coverage Change: ✅ No change Coverage by Package
Generated by GitHub Actions |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add Clean and Optimize Commands for OpenAPI Specifications
Overview
This PR introduces two powerful new CLI commands for OpenAPI specification management:
openapi spec clean- Remove unused components from specificationsopenapi spec optimize- Deduplicate inline schemas into reusable componentsFeatures
Clean Command (
openapi spec clean)$refand security scheme referencesOptimize Command (
openapi spec optimize)Implementation Details
openapi.Clean()andopenapi.Optimize()with comprehensive APIswalk/set.goutilities for schema replacement operationsDocumentation Updates
README.mdwith complete command listings for all CLI tools (SEO optimization)openapi/cmd/README.mdwith examples and use casesBenefits
Testing
Breaking Changes
None - this is a purely additive feature enhancement.