Skip to content

feat(cli): support filtered OpenAPI specs#10

Merged
miclle merged 12 commits into
mainfrom
feature/openapi-filters
May 9, 2026
Merged

feat(cli): support filtered OpenAPI specs#10
miclle merged 12 commits into
mainfrom
feature/openapi-filters

Conversation

@miclle
Copy link
Copy Markdown
Member

@miclle miclle commented May 9, 2026

Summary

Add a post-generation filter pipeline so fox-openapi can derive narrower OpenAPI documents from the full generated contract.

Changes

  • Add reusable Go filters for operation predicates and unused component pruning.
  • Add repeatable --filter / filters: expressions with =, ==, !=, and || support.
  • Keep legacy --filter-extension / --exclude-extension-value flags as hidden compatibility options.
  • Wire filters through entry-based driver generation and route manifest generation.
  • Refresh English and Chinese README guidance around auto-discovered entries, filtered specs, and CLI flags.

Validation

  • go test ./...

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.
@miclle miclle marked this pull request as ready for review May 9, 2026 03:38
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread filter.go
Comment thread openapi.go
Comment thread filter.go Outdated
Comment thread filter.go Outdated
Comment thread openapi.go
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.
@miclle
Copy link
Copy Markdown
Member Author

miclle commented May 9, 2026

/gemini review

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread filter.go
Comment thread openapi.go
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.
@miclle
Copy link
Copy Markdown
Member Author

miclle commented May 9, 2026

/gemini review

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread filter.go
Comment thread openapi.go
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.
@miclle
Copy link
Copy Markdown
Member Author

miclle commented May 9, 2026

/gemini review

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread filter.go
Use scalarEqual when excluding operations by extension value so map and slice extension values cannot panic.
@miclle
Copy link
Copy Markdown
Member Author

miclle commented May 9, 2026

/gemini review

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread filter.go
Compare cross-type scalar extension values with explicit bool, string, and numeric handling instead of fmt.Sprint.
@miclle
Copy link
Copy Markdown
Member Author

miclle commented May 9, 2026

/gemini review

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread filter.go
Comment thread openapi.go
Support numeric operation filter expressions while keeping Spec backward-compatible on generation errors.
@miclle
Copy link
Copy Markdown
Member Author

miclle commented May 9, 2026

/gemini review

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread filter.go
Treat simple discriminator mapping values as local component schema names during unused component pruning.
@miclle
Copy link
Copy Markdown
Member Author

miclle commented May 9, 2026

/gemini review

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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'.

Comment thread filter.go Outdated
Only treat mapping fields as discriminator mappings when the parent object has a propertyName.
@miclle
Copy link
Copy Markdown
Member Author

miclle commented May 9, 2026

/gemini review

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread filter.go
Rely on same-type DeepEqual and only allow cross-type comparisons for numeric scalar values.
@miclle
Copy link
Copy Markdown
Member Author

miclle commented May 9, 2026

/gemini review

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread README.md
Comment thread README.zh-CN.md
Explain that Config in supported entry signatures represents the user's own application config type.
@miclle
Copy link
Copy Markdown
Member Author

miclle commented May 9, 2026

/gemini review

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread filter.go
Comment thread openapi.go
Separate operation exclusion from extension cleanup and document that Spec ignores generation errors.
@miclle
Copy link
Copy Markdown
Member Author

miclle commented May 9, 2026

/gemini review

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread openapi.go
@miclle miclle merged commit af8050b into main May 9, 2026
1 check passed
@miclle miclle deleted the feature/openapi-filters branch May 9, 2026 11:53
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.

1 participant