You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Generate AppendUrlQueryPairs & FromUrlQueryPairs trait implementations from WpDeriveParamsField (#871)
* Add pagination attribute parsing and comprehensive error handling
Implement #[pagination(true/false)] container attribute support for
WpDeriveParamsField macro with complete error validation.
Changes:
- Register pagination attribute in proc_macro_derive definition
- Add pagination parsing logic with proper boolean value validation
- Update ParsedParamsStruct to include pagination field for future trait generation
- Add field_type to ParsedField for upcoming automatic type detection
- Implement comprehensive error handling for all pagination scenarios
- Add complete test coverage for all error cases
New error types:
- PaginationAttributeRequired: when #[pagination] is missing
- DuplicatePaginationAttribute: when multiple #[pagination] exist
- PaginationRequiresValue: when #[pagination] has no value
- PaginationMustBeBool: when #[pagination] value is not boolean
Test coverage: 6 tests (2 passing, 4 error scenarios)
* Implement AppendUrlQueryPairs and FromUrlQueryPairs trait generation
Complete the WpDeriveParamsField macro by adding automatic trait implementations
for URL query parameter handling.
Changes:
- Add AppendUrlQueryPairs trait implementation generation with automatic method selection
- Add FromUrlQueryPairs trait implementation with pagination support
- Implement type detection for Option<T>, Vec<T>, and Option<WpGmtDateTime> fields
- Use proc_macro_crate to resolve correct module paths for trait references
- Make generated enum public for external access
- Add comprehensive unit tests for type detection logic
* Rename pagination attribute to supports_pagination
Update all references from #[pagination] to #[supports_pagination] for clarity.
Changes:
- Update attribute name constant and error messages
- Update all test files to use new attribute name
- Update expected error messages in stderr files
* Replace manual trait implementations with macro-generated traits
Complete the migration from manual AppendUrlQueryPairs and FromUrlQueryPairs
implementations to macro-generated ones for all standard parameter structs.
Changes:
- Add #[supports_pagination(true/false)] attributes based on existing supports_pagination() methods
- Remove all manual AppendUrlQueryPairs and FromUrlQueryPairs implementations
- Keep users.rs with manual implementation (requires override attributes for WpApiParamUsersWho)
- Net result: -461 lines of boilerplate code, +12 lines of attributes
All files now use macro-generated traits except users.rs which needs special handling.
The macro correctly handles:
- Option<T> fields -> get() and append_option_query_value_pair()
- Vec<T> fields -> get_csv() and append_vec_query_value_pair()
- Option<WpGmtDateTime> fields -> get_wp_date_time() and append_option_query_value_pair()
- Custom field names via #[field_name("name")] attributes
* Fix wp_derive tests with minimal mock trait implementations
Add minimal mock trait and method implementations to test files to enable
compilation and testing of the macro-generated code.
Changes:
- Add minimal AppendUrlQueryPairs and FromUrlQueryPairs traits
- Add mock QueryPairs and UrlQueryPairsMap structs
- Add required method implementations with minimal signatures
- Tests now pass and validate macro functionality without requiring wp_api dependency
All wp_derive tests now pass: ✅
* Add override attributes support for WpDeriveParamsField macro
Implement `from_query_method` and `append_query_custom` attributes
to handle special field mappings that require custom serialization.
Changes:
- Add parsing for `from_query_method` and `append_query_custom` attributes
- Update macro to generate custom method calls when overrides are specified
- Replace manual UserListParams trait implementations with macro-generated ones
- Add special handling for `who` field using override attributes
- All existing tests pass confirming backward compatibility
* Fix clippy warnings in WpDeriveParamsField macro
Address clippy issues identified in cargo clippy --tests:
Changes:
- Remove redundant enum variant prefixes (AppendQueryMethod variants)
- Collapse nested if statements in is_wp_date_time_option method using let-chain patterns
- Update all enum variant references and test assertions
* Update MediaListParams test expectations to match generated field order
Fix failing tests by updating expected query parameter ordering to match
the macro-generated trait implementations which follow struct field order.
Changes:
- Move parent_exclude parameter to appear directly after parent parameter
- Update both media.rs and media_endpoint.rs test expectations
- No functional change - only reordering of query string parameters
- All 812 unit tests now pass
The generated macro correctly follows MediaListParams struct field order:
parent → parent_exclude → search_columns → slug → status
0 commit comments