Skip to content

bug(demo-android): PostEndpointType.Custom receives slug instead of restBase #442

@jkmassel

Description

@jkmassel

Context

In PR #433 (feat/demo-edit-existing-posts), the Android demo app maps PostTypeDetails to PostEndpointType for REST API calls. The mapping for custom post types passes the wrong value.

Bug

In both EditorActivity.persistPost() and PostsListActivity.loadPosts(), the else branch passes postType.postType (the slug, e.g. "product") to PostEndpointType.Custom():

else -> PostEndpointType.Custom(configuration.postType.postType)  // slug: "product"

However, PostEndpointType.Custom expects a restBase value (e.g. "products"), which is used directly as a URL path segment (/wp/v2/<value>/<id>). This is confirmed by the wordpress-rs source where PostEndpointType::Custom uses strum Display to serialize the inner string verbatim into the URL path.

The iOS demo correctly passes restBase:

endpointType = .custom(configuration.postType.restBase)  // restBase: "products"

Impact

For any custom post type where slug ≠ restBase (the common case, e.g. slug "product" vs restBase "products"), Android will construct URLs like /wp/v2/product/123 instead of /wp/v2/products/123, resulting in rest_no_route errors on both save and list operations.

Fix

Change postType.postType to postType.restBase in both locations:

  • EditorActivity.kt (~line 361)
  • PostsListActivity.kt (~line 181)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions