-
Notifications
You must be signed in to change notification settings - Fork 8
feat: add sanitize command to remove extensions and clean OpenAPI specs #59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
📊 Test Coverage ReportCurrent Coverage: Coverage Change: ✅ No change Coverage by Package
Generated by GitHub Actions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR implements a new sanitize command for the OpenAPI CLI that removes vendor-specific extensions and cleans OpenAPI specifications to create standards-compliant documents.
Key changes:
- Adds comprehensive sanitization functionality with configurable options for extension removal, unknown property cleanup, and unused component removal
- Implements CLI command with YAML configuration file support and flexible output options
- Enhances the unmarshaller to track unknown properties during parsing for precise cleanup
Reviewed Changes
Copilot reviewed 21 out of 21 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
openapi/sanitize.go |
Core sanitization logic with three-phase cleanup process and configuration loading |
openapi/sanitize_test.go |
Comprehensive unit tests covering all sanitization scenarios |
openapi/cmd/sanitize.go |
CLI command implementation with config file support and smart reporting |
openapi/cmd/root.go |
Registration of new sanitize command |
openapi/cmd/README.md |
Detailed documentation with usage examples and configuration options |
marshaller/unmarshaller.go |
Enhanced to track unknown properties during parsing |
marshaller/coremodel.go |
Added UnknownProperties tracking to CoreModel |
openapi/testdata/sanitize/* |
Test data files for various sanitization scenarios |
mise-tasks/test-* |
Updated test scripts to include sanitize command and filter coverage |
.github/workflows/ci.yaml |
Updated CI to filter coverage for cmd/tests folders |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
- Simplify nested conditions in removeExtensions by consolidating checks
- Add SanitizeResult type to collect and return warnings for invalid glob patterns
- Pre-allocate unknownProperties slice capacity for better performance
- Use map[string]struct{} instead of map[string]bool for memory efficiency
- Add PrintWarning method to OpenAPIProcessor for warning display
- Update all tests and CLI to handle new return signature
Addresses Copilot review feedback in PR #59
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 22 out of 22 changed files in this pull request and generated 4 comments.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
- Track pattern usage throughout document walk to provide better warnings - Warn about invalid glob patterns (syntax errors) - Warn about patterns that never matched any extensions - Fix reportSanitizationResults to distinguish between nil (remove all) and empty slice (keep all) for ExtensionPatterns - Remove unused matchesAnyPattern and contains helper functions - Inline pattern matching logic in removeExtensions for better tracking This addresses Copilot PR feedback comments about: 1. Invalid patterns being lost after first match 2. Incorrect reporting logic for extension patterns
Co-authored-by: Blake Preston <Blake.Preston@hotmail.com>
Co-authored-by: Blake Preston <Blake.Preston@hotmail.com>
Summary
Implements a new
sanitizecommand for the OpenAPI CLI that removes vendor-specific extensions and cleans OpenAPI specifications. This addresses #46.Changes
Core Functionality
openapi.Sanitize(): Main function with three sanitization phases:CLI Command
openapi spec sanitize: New command with YAML config file support--config/-c(optional config file),--write/-w(in-place modification)Architecture Enhancements
UnknownPropertiestracking tomarshaller.CoreModelMatcherpattern for consistencyConfiguration
Flexible sanitization via YAML config:
Testing
mise-tasks/test-cliUsage Examples
Documentation
Updated
openapi/cmd/README.mdwith:Testing
✅ All 637 tests passing
✅ CLI integration tests passing
✅ Validates output as valid OpenAPI specs