Skip to content

Conversation

@andmatei
Copy link
Collaborator

@andmatei andmatei commented Dec 18, 2025

Proposed changes

This PR adds a new slice command to the foascli that enables users to slice/filter OpenAPI specifications by operation IDs, tags, or path patterns. This feature allows developers to create smaller, focused OpenAPI specs containing only the endpoints they need

Example usage:

# Extract only Alerts endpoints by tag
foascli slice -s openapi/.raw/v2.yaml -o alerts-only.yaml --tags Alerts

# Extract specific operations
foascli slice -s spec.yaml -o output.yaml --operation-ids "getUser,createUser"

# Extract by path pattern
foascli slice -s spec.yaml -o output.yaml --paths "/api/v1/users"

Jira ticket: CLOUDP-365849

Checklist

  • I have signed the MongoDB CLA
  • I have added tests that prove my fix is effective or that my feature works

Changes to Spectral

  • I have read the README file for Spectral Updates

Further comments

…ation IDs, and paths

- Add new 'extract' CLI command to slice OpenAPI specifications
- Support filtering by operation IDs, tags, and path patterns
- Implement SliceFilter with comprehensive test coverage
- Use Cobra's StringSliceVar for cleaner flag handling
- Include all referenced schemas and components in output
- Add validation for input parameters and output formats
- Support both YAML and JSON output formats
- Update command name from 'extract' to 'slice' for consistency
- Update all examples and documentation to use 'slice'
- All tests still pass
- Fix perfsprint linter error
- Use errors.New instead of fmt.Errorf when no formatting is needed
- Add errors import
- Replace fmt.Errorf with errors.New for non-formatted errors (perfsprint)
- Fix receiver naming consistency in SliceFilter.matches method (revive)
- Change receiver name from 'e' to 'f' to match other methods
@andmatei andmatei changed the title feat: add slice command to filter OpenAPI specs feat(foascli): add slice command to filter OpenAPI specs Dec 19, 2025
- Add ParametersFilter to remove unused parameters from OpenAPI specs
- Add comprehensive tests for ParametersFilter (7 test scenarios)
- Move slice functionality from filter package to dedicated slice package
- Update FiltersToCleanupRefs to include TagsFilter, ParametersFilter, and SchemasFilter
- Fix linting issues (import shadowing and missing period in comment)
- Slice command now cleans up unused tags, parameters, and schemas automatically
@andmatei andmatei changed the title feat(foascli): add slice command to filter OpenAPI specs feat: add slice command to filter OpenAPI specs Dec 19, 2025
@andmatei andmatei marked this pull request as ready for review December 19, 2025 09:47
@andmatei andmatei requested a review from a team as a code owner December 19, 2025 09:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants