Expose WordPressClient.HttpHelper and add Base.CustomFields - #430
Open
hakakou wants to merge 1 commit into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR makes the library more extensible for consumers building custom endpoints by (1) exposing the HttpHelper instance held by WordPressClient, and (2) allowing all models derived from Models.Base to retain and round-trip unknown REST fields via System.Text.Json extension data.
Changes:
- Added
WordPressClient.HttpHelperso customCRUDOperation<TClass, QClass>/CustomRequestimplementations can reuse the client’s configured HTTP/auth/serializer state. - Added
Base.CustomFieldsbacked by[JsonExtensionData]to collect unmapped REST payload fields and write them back as top-level properties. - Added self-hosted tests validating capture, non-interference with mapped properties, serialization shape, and round-trip behavior for
CustomFields.
Reviewed changes
Copilot reviewed 4 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| tests/WordPressPCL.Tests.Selfhosted/Models/BaseCustomFields_Tests.cs | Adds coverage for capturing and round-tripping unmapped JSON fields via Base.CustomFields. |
| src/WordPressPCL/WordPressPCL.xml | Updates API documentation for Base.CustomFields and WordPressClient.HttpHelper. |
| src/WordPressPCL/WordPressClient.cs | Exposes the existing _httpHelper via a read-only HttpHelper property. |
| src/WordPressPCL/Models/Base.cs | Introduces [JsonExtensionData]-backed CustomFields for unmapped REST fields. |
| CHANGELOG.md | Documents the new public API additions in the Unreleased section. |
Files not reviewed (1)
- src/WordPressPCL/WordPressPCL.xml: Generated file
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Expose WordPressClient.HttpHelper and add Base.CustomFields
Added
WordPressClient.HttpHelperCRUDOperation<TClass, QClass>ispublic abstractwith aprotectedconstructor taking anHttpHelper, andCustomRequestaccepts one as well, so the library is clearly designed to let consumers add custom post types and taxonomies. ButWordPressClientheld itsHttpHelperin a private field with no accessor, leaving no supported way to obtain one.The only workaround was constructing a second
HttpHelper, which brings its ownHttpClientand its own authentication state. Instead of this complexity, this adds a read-only property returning the existing instance:Added
Base.CustomFieldsWordPress responses routinely carry fields the models do not map — added by plugins, by
register_rest_field, or by custom endpoints. They were silently discarded during deserialization, with no way to read them short of declaring a derived model perentity type.
This adds a
[JsonExtensionData]member onBase, so unmapped fields are available onPost,Page,Comment,User,Term,MediaItemandPostRevision, and can be written back on create and update.Tests