Skip to content

Expose WordPressClient.HttpHelper and add Base.CustomFields - #430

Open
hakakou wants to merge 1 commit into
wp-net:mainfrom
hakakou:main
Open

Expose WordPressClient.HttpHelper and add Base.CustomFields#430
hakakou wants to merge 1 commit into
wp-net:mainfrom
hakakou:main

Conversation

@hakakou

@hakakou hakakou commented Aug 16, 2026

Copy link
Copy Markdown

Expose WordPressClient.HttpHelper and add Base.CustomFields

Added WordPressClient.HttpHelper

CRUDOperation<TClass, QClass> is public abstract with a protected constructor taking an HttpHelper, and CustomRequest accepts one as well, so the library is clearly designed to let consumers add custom post types and taxonomies. But WordPressClient held its HttpHelper in a private field with no accessor, leaving no supported way to obtain one.

The only workaround was constructing a second HttpHelper, which brings its own HttpClient and its own authentication state. Instead of this complexity, this adds a read-only property returning the existing instance:

var taxonomy = new MyCustomTaxonomy(client.HttpHelper, "my-taxonomy");

Added Base.CustomFields

WordPress 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 per
entity type.

This adds a [JsonExtensionData] member on Base, so unmapped fields are available on Post, Page, Comment, User, Term, MediaItem and PostRevision, and can be written back on create and update.

Tests

  • Added unit tests covering CustomFields.
  • The self-hosted integration suite passes in full against a dockerized WordPress.

Copilot AI lite review requested due to automatic review settings August 16, 2026 12:17

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.HttpHelper so custom CRUDOperation<TClass, QClass> / CustomRequest implementations can reuse the client’s configured HTTP/auth/serializer state.
  • Added Base.CustomFields backed 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.

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