feat(cli): support filtered OpenAPI specs#10
Conversation
Add a post-generation filter pipeline with operation expression filters and unused component pruning. Wire repeatable CLI/config filters through entry and route-manifest generation while keeping legacy extension flags compatible.
There was a problem hiding this comment.
Code Review
This pull request introduces a post-generation filtering system for OpenAPI specifications, allowing users to exclude operations based on extension values and prune unused components. Key changes include new CLI flags, updated configuration schemas, and documentation for these features. Feedback identifies performance inefficiencies in the reachability analysis due to repeated marshaling and points out fragile string parsing in the filter and JSON pointer logic. Additionally, the reviewer noted that errors from the generation pipeline are currently ignored in several public methods, which could result in silent failures.
Expose generation errors through SpecErr, Err, and WarningsErr so filter failures are visible to library and CLI callers. Handle quoted OR literals in filter expressions and prune components from a single JSON traversal while preserving subpath component references.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces a post-generation filtering system for OpenAPI specifications, allowing operations to be excluded based on extension values and unused components to be pruned. These features are exposed via new CLI flags (--filter, --prune-unused-components) and a WithFilters option in the Go API. The update also includes a new filter expression parser, enhanced error handling in the generation pipeline, and updated documentation. Review feedback suggests improving the filter parser to handle escaped single quotes and notes that the generator's state management should be verified to prevent inconsistent cached specifications when filters fail.
Run filters against a cloned generated spec and only publish the filtered document after all filters succeed. Handle escaped single quotes in filter expression literals.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces post-generation filtering for OpenAPI specifications, allowing users to exclude operations based on extension values (e.g., x-public) and prune resulting unused components. The changes include a new expression-based filter language, CLI flags (--filter, --prune-unused-components), and library support via the WithFilters option and SpecErr method. Feedback indicates that the component pruning logic currently misses references within discriminator.mapping and link.operationRef fields. Additionally, there is a concern that the Spec() method's silent error handling may return unfiltered specifications if a filter fails, which could be misleading for users.
Keep components referenced by discriminator mappings and operationRef values during unused component pruning. Make Spec return nil when generation fails so callers do not accidentally consume an unfiltered spec.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces a post-generation filtering system for OpenAPI specifications, enabling users to exclude operations based on extension values and prune unused components via new CLI flags and configuration options. Documentation has been updated to reflect these changes. Feedback was provided regarding a potential panic in the filtering logic when comparing non-comparable extension types, suggesting the use of the scalarEqual helper for safety.
Use scalarEqual when excluding operations by extension value so map and slice extension values cannot panic.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces a post-generation filtering system for OpenAPI specifications, allowing operations to be excluded based on extension values and unused components to be pruned. The implementation includes new CLI flags, configuration options, and updated documentation in English and Chinese. Additionally, the Generator now provides enhanced error handling for the generation process. Feedback was provided regarding the scalarEqual function in filter.go, suggesting the use of type switches instead of string-based comparisons to ensure more robust equality checks across different scalar types.
Compare cross-type scalar extension values with explicit bool, string, and numeric handling instead of fmt.Sprint.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces a post-generation filtering system for OpenAPI specifications, enabling users to exclude operations based on extension values and prune unused components. Key additions include new CLI flags (--filter, --prune-unused-components), corresponding configuration fields, and a library API via the WithFilters option. The documentation has been extensively updated to reflect these features and clarify entry function discovery. Review feedback highlights an opportunity to improve numeric filtering by adding numeric parsing to the expression evaluator and notes that the modification to Spec() returning nil on failure constitutes a breaking change for library consumers.
Support numeric operation filter expressions while keeping Spec backward-compatible on generation errors.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces a post-generation filtering system for OpenAPI specifications, enabling users to exclude operations based on extension values and prune unused components. It adds new CLI flags, updates the configuration schema, and enhances the library API with filtering options. Documentation has been updated to reflect these changes. Feedback identified a bug in the reachability analysis where simple schema names in discriminator mappings are not correctly resolved, which could lead to incorrect pruning of referenced components.
Treat simple discriminator mapping values as local component schema names during unused component pruning.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces a post-generation filtering system for OpenAPI specifications, enabling the exclusion of operations based on extension values and the pruning of unused components. These features are supported via new CLI flags, configuration options, and an updated generation pipeline. Documentation has been expanded to cover these additions. Feedback was provided concerning the reachability analysis used for pruning, specifically suggesting that the logic for identifying discriminator mappings be tightened to avoid false positives from regular properties named 'mapping'.
Only treat mapping fields as discriminator mappings when the parent object has a propertyName.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces a post-generation filtering system for OpenAPI specifications, allowing users to exclude operations based on extension values and prune unused components. It adds new CLI flags (--filter, --prune-unused-components), updates the configuration schema, and enhances the Generator API with error-aware methods like SpecErr. Documentation in both English and Chinese has been updated to reflect these features and improved entry function discovery. Feedback was provided to simplify the scalarEqual logic in filter.go to improve readability by consolidating type checks.
Rely on same-type DeepEqual and only allow cross-type comparisons for numeric scalar values.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces a post-generation filtering system for OpenAPI specifications, allowing operations to be excluded based on extension values and unused components to be pruned. It adds new CLI flags, updates the configuration schema, and provides a programmatic Go API for these features. Documentation in both English and Chinese has been updated accordingly. Feedback suggests clarifying that *Config in entry function signatures is a placeholder for user-defined types to avoid ambiguity for new users.
Explain that Config in supported entry signatures represents the user's own application config type.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request implements a post-generation filtering system for OpenAPI specifications, allowing for the exclusion of operations based on extension values and the pruning of unused components. The changes include new CLI flags (--filter, --prune-unused-components), updated configuration structures, and an enhanced Generator API with improved error handling. Review feedback points out that the ExcludeOperationsWithExtensionValue helper's automatic deletion of extensions is inconsistent with the non-destructive behavior of CLI filters. Additionally, it was suggested to document or deprecate the Spec() method, as it now suppresses generation errors that may occur during the filtering stage.
Separate operation exclusion from extension cleanup and document that Spec ignores generation errors.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces a post-generation filtering system for OpenAPI specifications, enabling users to exclude operations based on extension values and prune unused components through new CLI flags and configuration options. The Generator API has been updated to support these filters and provides enhanced error handling via new methods like SpecErr. Feedback was provided regarding the performance impact of using JSON serialization for specification cloning, suggesting a more direct traversal to avoid overhead in performance-sensitive environments.
Summary
Add a post-generation filter pipeline so fox-openapi can derive narrower OpenAPI documents from the full generated contract.
Changes
--filter/filters:expressions with=,==,!=, and||support.--filter-extension/--exclude-extension-valueflags as hidden compatibility options.Validation
go test ./...