Make WordPress Core

Opened 8 years ago

Closed 8 years ago

Last modified 8 years ago

#39561 closed defect (bug) (fixed)

REST API JavaScript client: Correct name route discovery for custom namespaces

Reported by: adamsilverstein's profile adamsilverstein Owned by: adamsilverstein's profile adamsilverstein
Milestone: 4.7.3 Priority: normal
Severity: normal Version: 4.7
Component: REST API Keywords: fixed-major
Focuses: javascript Cc:

Description (last modified by adamsilverstein)

When users initialize the WP API JavaScript client with a custom namespace, the route discovery code does a poor job parsing the endpoints. This ticket aims to improve the parsing of custom namespaces. Originally raised by @westonruter and @jazbek, see https://github.com/WP-API/client-js/pull/152.

Attachments (5)

39561.diff (8.1 KB) - added by adamsilverstein 8 years ago.
39561.2.diff (7.3 KB) - added by adamsilverstein 8 years ago.
39561.3.diff (36.4 KB) - added by adamsilverstein 8 years ago.
39561.4.diff (37.4 KB) - added by adamsilverstein 8 years ago.
39561.5.diff (36.4 KB) - added by jnylen0 8 years ago.
Just the new tests (and the QUnit fix)

Download all attachments as: .zip

Change History (24)

#1 @adamsilverstein
8 years ago

  • Owner set to adamsilverstein
  • Status changed from new to assigned

#2 @adamsilverstein
8 years ago

  • Description modified (diff)

#3 @adamsilverstein
8 years ago

  • Description modified (diff)

This ticket was mentioned in Slack in #core by jeffpaul. View the logs.


8 years ago

This ticket was mentioned in Slack in #core-restapi by ocean90. View the logs.


8 years ago

#6 @adamsilverstein
8 years ago

39561.2.diff is a slight cleanup of the code and doc blocks. This code got some testing by the original reporter and others via the plugin, this is ready to commit.

#7 @adamsilverstein
8 years ago

  • Keywords commit added; has-patch has-unit-tests needs-testing removed

#8 @adamsilverstein
8 years ago

  • Resolution set to fixed
  • Status changed from assigned to closed

In 40074:

REST API: JavaScript client - improve route discovery for custom namespaces.

Fix parsing of custom namespace routes. Transform class names, removing dashes and capitalizing each word/route part so a route path of widgets/recent-posts becomes a collection with the name WidgetsRecentPosts. Correct parent route part when routes are longer than expected, reversing parse direction.

Props westonruter, jazbek.
Fixes #39561.

#9 @adamsilverstein
8 years ago

  • Keywords fixed-major added; commit removed
  • Resolution fixed deleted
  • Status changed from closed to reopened

Reopening for 4.7.3 consideration.

#10 follow-up: @jnylen0
8 years ago

@adamsilverstein what about the unit tests for this change?

#11 in reply to: ↑ 10 @adamsilverstein
8 years ago

  • Keywords needs-unit-tests added

Replying to jnylen0:

@adamsilverstein what about the unit tests for this change?

Good point! I will work on adding a version of the test for this.

#12 @adamsilverstein
8 years ago

In 39561.4.diff :

  • check for each route instead of a strict equality comparison on the schema. address a potential failure if plugins or themes try running tests with additional routes present, as @rachelbaker pointed out in slack.
  • add a fixture for the custom endpoints created by the wp-js-widgets plugin - this is a good test case for the route discovery/class naming code.
  • add an additional test block, verifying the schema parsing correctly generates proper class names for each model and collection route.
  • ensure nav-menu test passes when code loaded without tests executing (tests for unset 'assert')

Note: the tests surfaced one issue with the parsing - underscores are being left untouched - hence the class name WidgetsTag_cloud, this should probably be auto-transformed to WidgetsTagCloud similar to handling of -. I will address that in a separate ticket.

Last edited 8 years ago by adamsilverstein (previous) (diff)

@jnylen0
8 years ago

Just the new tests (and the QUnit fix)

#13 @jnylen0
8 years ago

  • Keywords commit added

@adamsilverstein let's go with 39561.5.diff here. Only minor changes from your last patch: removed the PHPUnit test fix as that's a separate change addressed in [40104], and added a comment about the assert && assert.equal fix.

This ticket was mentioned in Slack in #core-restapi by jnylen. View the logs.


8 years ago

#15 @adamsilverstein
8 years ago

Looks good @jnylen0 thanks, I will get this committed.

#16 @adamsilverstein
8 years ago

  • Resolution set to fixed
  • Status changed from reopened to closed

In 40109:

REST API: JS client - QUnit tests for custom namespace route discovery.

Add QUnit tests for the parsing of custom namespace routes. Add a custom schema fixture based on the wp-js-widgets plugin. Test that the client can parse the widget namespace in the schema and correctly construct the expected group of models and collections. Also includes a small unrelated QUnit fix to ensure nav-menu test passes when it is loaded without its tests executing as well as a small jshint fix, adding a missing semicolon since [40107].

Props jnylen0.
Fixes #39561.

#17 @jnylen0
8 years ago

  • Keywords needs-unit-tests commit removed
  • Resolution fixed deleted
  • Status changed from closed to reopened

[40074] and [40109] need backport to the 4.7 branch for 4.7.3.

#18 @SergeyBiryukov
8 years ago

  • Resolution set to fixed
  • Status changed from reopened to closed

In 40117:

REST API: JavaScript client - improve route discovery for custom namespaces.

Fix parsing of custom namespace routes. Transform class names, removing dashes and capitalizing each word/route part so a route path of widgets/recent-posts becomes a collection with the name WidgetsRecentPosts. Correct parent route part when routes are longer than expected, reversing parse direction.

Props westonruter, jazbek, adamsilverstein, jnylen0.
Merges [40074] and [40109] to the 4.7 branch.
Fixes #39561.

This ticket was mentioned in Slack in #core-restapi by adamsilverstein. View the logs.


8 years ago

Note: See TracTickets for help on using tickets.