From 624213b37880129bd1d0235408c2db0656179906 Mon Sep 17 00:00:00 2001 From: "K. Adam White" Date: Tue, 6 Dec 2016 01:53:09 -0500 Subject: [PATCH] Further slim down default routes JSON bootstrapping file The routes object is the only part of the default data file that gets consumed by the API client during bootstrapping, and not all properties within that dictionary are even used: for example the "required" status of arguments is not used anywhere in the library. In the spirit of YAGNI these extraneous values are being removed in preparation for v1.0. --- .jshintignore | 2 +- README.md | 2 +- lib/data/default-routes.json | 1 + lib/data/endpoint-response.json | 1 - lib/data/simplify-object.js | 4 +- ...-json.js => update-default-routes-json.js} | 26 +++---- package.json | 2 +- tests/unit/lib/data/simplify-object.js | 72 +++++++++---------- tests/unit/lib/route-tree.js | 4 +- tests/unit/wpapi.js | 6 +- wpapi.js | 2 +- 11 files changed, 60 insertions(+), 62 deletions(-) create mode 100644 lib/data/default-routes.json delete mode 100644 lib/data/endpoint-response.json rename lib/data/{generate-endpoint-response-json.js => update-default-routes-json.js} (85%) diff --git a/.jshintignore b/.jshintignore index f29ad364..4a362460 100644 --- a/.jshintignore +++ b/.jshintignore @@ -1 +1 @@ -./lib/data/generate-endpoint-response-json.js +./lib/data/update-default-routes-json.js diff --git a/README.md b/README.md index 8f7ded72..98e01dd8 100644 --- a/README.md +++ b/README.md @@ -174,7 +174,7 @@ var site = new WPAPI({ site.namespace( 'myplugin/v1' ).authors()... ``` -To create a slimmed JSON file dedicated to this particular purpose, see the Node script [lib/data/generate-endpoint-response-json.js](lib/data/generate-endpoint-response-json.js), which will let you download and save an endpoint response to your local project. +To create a slimmed JSON file dedicated to this particular purpose, see the Node script [lib/data/update-default-routes-json.js](https://github.com/wp-api/node-wpapi/tree/master/lib/data/update-default-routes-json.js), which will let you download and save an endpoint response to your local project. In addition to retrieving the specified resource with `.get()`, you can also `.create()`, `.update()` and `.delete()` resources: diff --git a/lib/data/default-routes.json b/lib/data/default-routes.json new file mode 100644 index 00000000..f7a3c0c3 --- /dev/null +++ b/lib/data/default-routes.json @@ -0,0 +1 @@ +{"/":{"namespace":"","methods":["GET"],"endpoints":[{"methods":["GET"],"args":{"context":{}}}]},"/oembed/1.0":{"namespace":"oembed/1.0","methods":["GET"],"endpoints":[{"methods":["GET"],"args":{"namespace":{},"context":{}}}]},"/oembed/1.0/embed":{"namespace":"oembed/1.0","methods":["GET"],"endpoints":[{"methods":["GET"],"args":{"url":{},"format":{},"maxwidth":{}}}]},"/wp/v2":{"namespace":"wp/v2","methods":["GET"],"endpoints":[{"methods":["GET"],"args":{"namespace":{},"context":{}}}]},"/wp/v2/posts":{"namespace":"wp/v2","methods":["GET","POST"],"endpoints":[{"methods":["GET"],"args":{"context":{},"page":{},"per_page":{},"search":{},"after":{},"author":{},"author_exclude":{},"before":{},"exclude":{},"include":{},"offset":{},"order":{},"orderby":{},"slug":{},"status":{},"categories":{},"categories_exclude":{},"tags":{},"tags_exclude":{},"sticky":{}}},{"methods":["POST"],"args":{"date":{},"date_gmt":{},"slug":{},"status":{},"password":{},"title":{},"content":{},"author":{},"excerpt":{},"featured_media":{},"comment_status":{},"ping_status":{},"format":{},"meta":{},"sticky":{},"template":{},"categories":{},"tags":{}}}]},"/wp/v2/posts/(?P[\\d]+)":{"namespace":"wp/v2","methods":["GET","POST","PUT","PATCH","DELETE"],"endpoints":[{"methods":["GET"],"args":{"context":{},"password":{}}},{"methods":["POST","PUT","PATCH"],"args":{"date":{},"date_gmt":{},"slug":{},"status":{},"password":{},"title":{},"content":{},"author":{},"excerpt":{},"featured_media":{},"comment_status":{},"ping_status":{},"format":{},"meta":{},"sticky":{},"template":{},"categories":{},"tags":{}}},{"methods":["DELETE"],"args":{"force":{}}}]},"/wp/v2/posts/(?P[\\d]+)/revisions":{"namespace":"wp/v2","methods":["GET"],"endpoints":[{"methods":["GET"],"args":{"context":{}}}]},"/wp/v2/posts/(?P[\\d]+)/revisions/(?P[\\d]+)":{"namespace":"wp/v2","methods":["GET","DELETE"],"endpoints":[{"methods":["GET"],"args":{"context":{}}},{"methods":["DELETE"],"args":{"force":{}}}]},"/wp/v2/pages":{"namespace":"wp/v2","methods":["GET","POST"],"endpoints":[{"methods":["GET"],"args":{"context":{},"page":{},"per_page":{},"search":{},"after":{},"author":{},"author_exclude":{},"before":{},"exclude":{},"include":{},"menu_order":{},"offset":{},"order":{},"orderby":{},"parent":{},"parent_exclude":{},"slug":{},"status":{}}},{"methods":["POST"],"args":{"date":{},"date_gmt":{},"slug":{},"status":{},"password":{},"parent":{},"title":{},"content":{},"author":{},"excerpt":{},"featured_media":{},"comment_status":{},"ping_status":{},"menu_order":{},"meta":{},"template":{}}}]},"/wp/v2/pages/(?P[\\d]+)":{"namespace":"wp/v2","methods":["GET","POST","PUT","PATCH","DELETE"],"endpoints":[{"methods":["GET"],"args":{"context":{},"password":{}}},{"methods":["POST","PUT","PATCH"],"args":{"date":{},"date_gmt":{},"slug":{},"status":{},"password":{},"parent":{},"title":{},"content":{},"author":{},"excerpt":{},"featured_media":{},"comment_status":{},"ping_status":{},"menu_order":{},"meta":{},"template":{}}},{"methods":["DELETE"],"args":{"force":{}}}]},"/wp/v2/pages/(?P[\\d]+)/revisions":{"namespace":"wp/v2","methods":["GET"],"endpoints":[{"methods":["GET"],"args":{"context":{}}}]},"/wp/v2/pages/(?P[\\d]+)/revisions/(?P[\\d]+)":{"namespace":"wp/v2","methods":["GET","DELETE"],"endpoints":[{"methods":["GET"],"args":{"context":{}}},{"methods":["DELETE"],"args":{"force":{}}}]},"/wp/v2/media":{"namespace":"wp/v2","methods":["GET","POST"],"endpoints":[{"methods":["GET"],"args":{"context":{},"page":{},"per_page":{},"search":{},"after":{},"author":{},"author_exclude":{},"before":{},"exclude":{},"include":{},"offset":{},"order":{},"orderby":{},"parent":{},"parent_exclude":{},"slug":{},"status":{},"media_type":{},"mime_type":{}}},{"methods":["POST"],"args":{"date":{},"date_gmt":{},"slug":{},"status":{},"title":{},"author":{},"comment_status":{},"ping_status":{},"meta":{},"template":{},"alt_text":{},"caption":{},"description":{},"post":{}}}]},"/wp/v2/media/(?P[\\d]+)":{"namespace":"wp/v2","methods":["GET","POST","PUT","PATCH","DELETE"],"endpoints":[{"methods":["GET"],"args":{"context":{},"password":{}}},{"methods":["POST","PUT","PATCH"],"args":{"date":{},"date_gmt":{},"slug":{},"status":{},"title":{},"author":{},"comment_status":{},"ping_status":{},"meta":{},"template":{},"alt_text":{},"caption":{},"description":{},"post":{}}},{"methods":["DELETE"],"args":{"force":{}}}]},"/wp/v2/types":{"namespace":"wp/v2","methods":["GET"],"endpoints":[{"methods":["GET"],"args":{"context":{}}}]},"/wp/v2/types/(?P[\\w-]+)":{"namespace":"wp/v2","methods":["GET"],"endpoints":[{"methods":["GET"],"args":{"context":{}}}]},"/wp/v2/statuses":{"namespace":"wp/v2","methods":["GET"],"endpoints":[{"methods":["GET"],"args":{"context":{}}}]},"/wp/v2/statuses/(?P[\\w-]+)":{"namespace":"wp/v2","methods":["GET"],"endpoints":[{"methods":["GET"],"args":{"context":{}}}]},"/wp/v2/taxonomies":{"namespace":"wp/v2","methods":["GET"],"endpoints":[{"methods":["GET"],"args":{"context":{},"type":{}}}]},"/wp/v2/taxonomies/(?P[\\w-]+)":{"namespace":"wp/v2","methods":["GET"],"endpoints":[{"methods":["GET"],"args":{"context":{}}}]},"/wp/v2/categories":{"namespace":"wp/v2","methods":["GET","POST"],"endpoints":[{"methods":["GET"],"args":{"context":{},"page":{},"per_page":{},"search":{},"exclude":{},"include":{},"order":{},"orderby":{},"hide_empty":{},"parent":{},"post":{},"slug":{}}},{"methods":["POST"],"args":{"description":{},"name":{},"slug":{},"parent":{},"meta":{}}}]},"/wp/v2/categories/(?P[\\d]+)":{"namespace":"wp/v2","methods":["GET","POST","PUT","PATCH","DELETE"],"endpoints":[{"methods":["GET"],"args":{"context":{}}},{"methods":["POST","PUT","PATCH"],"args":{"description":{},"name":{},"slug":{},"parent":{},"meta":{}}},{"methods":["DELETE"],"args":{"force":{}}}]},"/wp/v2/tags":{"namespace":"wp/v2","methods":["GET","POST"],"endpoints":[{"methods":["GET"],"args":{"context":{},"page":{},"per_page":{},"search":{},"exclude":{},"include":{},"offset":{},"order":{},"orderby":{},"hide_empty":{},"post":{},"slug":{}}},{"methods":["POST"],"args":{"description":{},"name":{},"slug":{},"meta":{}}}]},"/wp/v2/tags/(?P[\\d]+)":{"namespace":"wp/v2","methods":["GET","POST","PUT","PATCH","DELETE"],"endpoints":[{"methods":["GET"],"args":{"context":{}}},{"methods":["POST","PUT","PATCH"],"args":{"description":{},"name":{},"slug":{},"meta":{}}},{"methods":["DELETE"],"args":{"force":{}}}]},"/wp/v2/users":{"namespace":"wp/v2","methods":["GET","POST"],"endpoints":[{"methods":["GET"],"args":{"context":{},"page":{},"per_page":{},"search":{},"exclude":{},"include":{},"offset":{},"order":{},"orderby":{},"slug":{},"roles":{}}},{"methods":["POST"],"args":{"username":{},"name":{},"first_name":{},"last_name":{},"email":{},"url":{},"description":{},"locale":{},"nickname":{},"slug":{},"roles":{},"password":{},"meta":{}}}]},"/wp/v2/users/(?P[\\d]+)":{"namespace":"wp/v2","methods":["GET","POST","PUT","PATCH","DELETE"],"endpoints":[{"methods":["GET"],"args":{"context":{}}},{"methods":["POST","PUT","PATCH"],"args":{"username":{},"name":{},"first_name":{},"last_name":{},"email":{},"url":{},"description":{},"locale":{},"nickname":{},"slug":{},"roles":{},"password":{},"meta":{}}},{"methods":["DELETE"],"args":{"force":{},"reassign":{}}}]},"/wp/v2/users/me":{"namespace":"wp/v2","methods":["GET","POST","PUT","PATCH","DELETE"],"endpoints":[{"methods":["GET"],"args":{"context":{}}},{"methods":["POST","PUT","PATCH"],"args":{"username":{},"name":{},"first_name":{},"last_name":{},"email":{},"url":{},"description":{},"locale":{},"nickname":{},"slug":{},"roles":{},"password":{},"meta":{}}},{"methods":["DELETE"],"args":{"force":{},"reassign":{}}}]},"/wp/v2/comments":{"namespace":"wp/v2","methods":["GET","POST"],"endpoints":[{"methods":["GET"],"args":{"context":{},"page":{},"per_page":{},"search":{},"after":{},"author":{},"author_exclude":{},"author_email":{},"before":{},"exclude":{},"include":{},"offset":{},"order":{},"orderby":{},"parent":{},"parent_exclude":{},"post":{},"status":{},"type":{},"password":{}}},{"methods":["POST"],"args":{"author":{},"author_email":{},"author_ip":{},"author_name":{},"author_url":{},"author_user_agent":{},"content":{},"date":{},"date_gmt":{},"parent":{},"post":{},"status":{},"meta":{}}}]},"/wp/v2/comments/(?P[\\d]+)":{"namespace":"wp/v2","methods":["GET","POST","PUT","PATCH","DELETE"],"endpoints":[{"methods":["GET"],"args":{"context":{},"password":{}}},{"methods":["POST","PUT","PATCH"],"args":{"author":{},"author_email":{},"author_ip":{},"author_name":{},"author_url":{},"author_user_agent":{},"content":{},"date":{},"date_gmt":{},"parent":{},"post":{},"status":{},"meta":{}}},{"methods":["DELETE"],"args":{"force":{},"password":{}}}]},"/wp/v2/settings":{"namespace":"wp/v2","methods":["GET","POST","PUT","PATCH"],"endpoints":[{"methods":["GET"],"args":{}},{"methods":["POST","PUT","PATCH"],"args":{"title":{},"description":{},"url":{},"email":{},"timezone":{},"date_format":{},"time_format":{},"start_of_week":{},"language":{},"use_smilies":{},"default_category":{},"default_post_format":{},"posts_per_page":{},"default_ping_status":{},"default_comment_status":{}}}]}} \ No newline at end of file diff --git a/lib/data/endpoint-response.json b/lib/data/endpoint-response.json deleted file mode 100644 index b3b4ffd7..00000000 --- a/lib/data/endpoint-response.json +++ /dev/null @@ -1 +0,0 @@ -{"name":"WP-API Testbed","description":"Just another WordPress site","url":"http://wpapi.loc/wp","home":"http://wpapi.loc","namespaces":["oembed/1.0","wp/v2"],"authentication":{"oauth1":{"request":"http://wpapi.loc/oauth1/request","authorize":"http://wpapi.loc/oauth1/authorize","access":"http://wpapi.loc/oauth1/access","version":"0.1"}},"routes":{"/":{"namespace":"","methods":["GET"],"endpoints":[{"methods":["GET"],"args":{"context":{"required":false}}}]},"/oembed/1.0":{"namespace":"oembed/1.0","methods":["GET"],"endpoints":[{"methods":["GET"],"args":{"namespace":{"required":false},"context":{"required":false}}}]},"/oembed/1.0/embed":{"namespace":"oembed/1.0","methods":["GET"],"endpoints":[{"methods":["GET"],"args":{"url":{"required":true},"format":{"required":false},"maxwidth":{"required":false}}}]},"/wp/v2":{"namespace":"wp/v2","methods":["GET"],"endpoints":[{"methods":["GET"],"args":{"namespace":{"required":false},"context":{"required":false}}}]},"/wp/v2/posts":{"namespace":"wp/v2","methods":["GET","POST"],"endpoints":[{"methods":["GET"],"args":{"context":{"required":false},"page":{"required":false},"per_page":{"required":false},"search":{"required":false},"after":{"required":false},"author":{"required":false},"author_exclude":{"required":false},"before":{"required":false},"exclude":{"required":false},"include":{"required":false},"offset":{"required":false},"order":{"required":false},"orderby":{"required":false},"slug":{"required":false},"status":{"required":false},"categories":{"required":false},"categories_exclude":{"required":false},"tags":{"required":false},"tags_exclude":{"required":false},"sticky":{"required":false}}},{"methods":["POST"],"args":{"date":{"required":false},"date_gmt":{"required":false},"slug":{"required":false},"status":{"required":false},"password":{"required":false},"title":{"required":false},"content":{"required":false},"author":{"required":false},"excerpt":{"required":false},"featured_media":{"required":false},"comment_status":{"required":false},"ping_status":{"required":false},"format":{"required":false},"meta":{"required":false},"sticky":{"required":false},"template":{"required":false},"categories":{"required":false},"tags":{"required":false}}}]},"/wp/v2/posts/(?P[\\d]+)":{"namespace":"wp/v2","methods":["GET","POST","PUT","PATCH","DELETE"],"endpoints":[{"methods":["GET"],"args":{"context":{"required":false},"password":{"required":false}}},{"methods":["POST","PUT","PATCH"],"args":{"date":{"required":false},"date_gmt":{"required":false},"slug":{"required":false},"status":{"required":false},"password":{"required":false},"title":{"required":false},"content":{"required":false},"author":{"required":false},"excerpt":{"required":false},"featured_media":{"required":false},"comment_status":{"required":false},"ping_status":{"required":false},"format":{"required":false},"meta":{"required":false},"sticky":{"required":false},"template":{"required":false},"categories":{"required":false},"tags":{"required":false}}},{"methods":["DELETE"],"args":{"force":{"required":false}}}]},"/wp/v2/posts/(?P[\\d]+)/revisions":{"namespace":"wp/v2","methods":["GET"],"endpoints":[{"methods":["GET"],"args":{"context":{"required":false}}}]},"/wp/v2/posts/(?P[\\d]+)/revisions/(?P[\\d]+)":{"namespace":"wp/v2","methods":["GET","DELETE"],"endpoints":[{"methods":["GET"],"args":{"context":{"required":false}}},{"methods":["DELETE"],"args":{"force":{"required":false}}}]},"/wp/v2/pages":{"namespace":"wp/v2","methods":["GET","POST"],"endpoints":[{"methods":["GET"],"args":{"context":{"required":false},"page":{"required":false},"per_page":{"required":false},"search":{"required":false},"after":{"required":false},"author":{"required":false},"author_exclude":{"required":false},"before":{"required":false},"exclude":{"required":false},"include":{"required":false},"menu_order":{"required":false},"offset":{"required":false},"order":{"required":false},"orderby":{"required":false},"parent":{"required":false},"parent_exclude":{"required":false},"slug":{"required":false},"status":{"required":false}}},{"methods":["POST"],"args":{"date":{"required":false},"date_gmt":{"required":false},"slug":{"required":false},"status":{"required":false},"password":{"required":false},"parent":{"required":false},"title":{"required":false},"content":{"required":false},"author":{"required":false},"excerpt":{"required":false},"featured_media":{"required":false},"comment_status":{"required":false},"ping_status":{"required":false},"menu_order":{"required":false},"meta":{"required":false},"template":{"required":false}}}]},"/wp/v2/pages/(?P[\\d]+)":{"namespace":"wp/v2","methods":["GET","POST","PUT","PATCH","DELETE"],"endpoints":[{"methods":["GET"],"args":{"context":{"required":false},"password":{"required":false}}},{"methods":["POST","PUT","PATCH"],"args":{"date":{"required":false},"date_gmt":{"required":false},"slug":{"required":false},"status":{"required":false},"password":{"required":false},"parent":{"required":false},"title":{"required":false},"content":{"required":false},"author":{"required":false},"excerpt":{"required":false},"featured_media":{"required":false},"comment_status":{"required":false},"ping_status":{"required":false},"menu_order":{"required":false},"meta":{"required":false},"template":{"required":false}}},{"methods":["DELETE"],"args":{"force":{"required":false}}}]},"/wp/v2/pages/(?P[\\d]+)/revisions":{"namespace":"wp/v2","methods":["GET"],"endpoints":[{"methods":["GET"],"args":{"context":{"required":false}}}]},"/wp/v2/pages/(?P[\\d]+)/revisions/(?P[\\d]+)":{"namespace":"wp/v2","methods":["GET","DELETE"],"endpoints":[{"methods":["GET"],"args":{"context":{"required":false}}},{"methods":["DELETE"],"args":{"force":{"required":false}}}]},"/wp/v2/media":{"namespace":"wp/v2","methods":["GET","POST"],"endpoints":[{"methods":["GET"],"args":{"context":{"required":false},"page":{"required":false},"per_page":{"required":false},"search":{"required":false},"after":{"required":false},"author":{"required":false},"author_exclude":{"required":false},"before":{"required":false},"exclude":{"required":false},"include":{"required":false},"offset":{"required":false},"order":{"required":false},"orderby":{"required":false},"parent":{"required":false},"parent_exclude":{"required":false},"slug":{"required":false},"status":{"required":false},"media_type":{"required":false},"mime_type":{"required":false}}},{"methods":["POST"],"args":{"date":{"required":false},"date_gmt":{"required":false},"slug":{"required":false},"status":{"required":false},"title":{"required":false},"author":{"required":false},"comment_status":{"required":false},"ping_status":{"required":false},"meta":{"required":false},"template":{"required":false},"alt_text":{"required":false},"caption":{"required":false},"description":{"required":false},"post":{"required":false}}}]},"/wp/v2/media/(?P[\\d]+)":{"namespace":"wp/v2","methods":["GET","POST","PUT","PATCH","DELETE"],"endpoints":[{"methods":["GET"],"args":{"context":{"required":false},"password":{"required":false}}},{"methods":["POST","PUT","PATCH"],"args":{"date":{"required":false},"date_gmt":{"required":false},"slug":{"required":false},"status":{"required":false},"title":{"required":false},"author":{"required":false},"comment_status":{"required":false},"ping_status":{"required":false},"meta":{"required":false},"template":{"required":false},"alt_text":{"required":false},"caption":{"required":false},"description":{"required":false},"post":{"required":false}}},{"methods":["DELETE"],"args":{"force":{"required":false}}}]},"/wp/v2/types":{"namespace":"wp/v2","methods":["GET"],"endpoints":[{"methods":["GET"],"args":{"context":{"required":false}}}]},"/wp/v2/types/(?P[\\w-]+)":{"namespace":"wp/v2","methods":["GET"],"endpoints":[{"methods":["GET"],"args":{"context":{"required":false}}}]},"/wp/v2/statuses":{"namespace":"wp/v2","methods":["GET"],"endpoints":[{"methods":["GET"],"args":{"context":{"required":false}}}]},"/wp/v2/statuses/(?P[\\w-]+)":{"namespace":"wp/v2","methods":["GET"],"endpoints":[{"methods":["GET"],"args":{"context":{"required":false}}}]},"/wp/v2/taxonomies":{"namespace":"wp/v2","methods":["GET"],"endpoints":[{"methods":["GET"],"args":{"context":{"required":false},"type":{"required":false}}}]},"/wp/v2/taxonomies/(?P[\\w-]+)":{"namespace":"wp/v2","methods":["GET"],"endpoints":[{"methods":["GET"],"args":{"context":{"required":false}}}]},"/wp/v2/categories":{"namespace":"wp/v2","methods":["GET","POST"],"endpoints":[{"methods":["GET"],"args":{"context":{"required":false},"page":{"required":false},"per_page":{"required":false},"search":{"required":false},"exclude":{"required":false},"include":{"required":false},"order":{"required":false},"orderby":{"required":false},"hide_empty":{"required":false},"parent":{"required":false},"post":{"required":false},"slug":{"required":false}}},{"methods":["POST"],"args":{"description":{"required":false},"name":{"required":true},"slug":{"required":false},"parent":{"required":false},"meta":{"required":false}}}]},"/wp/v2/categories/(?P[\\d]+)":{"namespace":"wp/v2","methods":["GET","POST","PUT","PATCH","DELETE"],"endpoints":[{"methods":["GET"],"args":{"context":{"required":false}}},{"methods":["POST","PUT","PATCH"],"args":{"description":{"required":false},"name":{"required":false},"slug":{"required":false},"parent":{"required":false},"meta":{"required":false}}},{"methods":["DELETE"],"args":{"force":{"required":false}}}]},"/wp/v2/tags":{"namespace":"wp/v2","methods":["GET","POST"],"endpoints":[{"methods":["GET"],"args":{"context":{"required":false},"page":{"required":false},"per_page":{"required":false},"search":{"required":false},"exclude":{"required":false},"include":{"required":false},"offset":{"required":false},"order":{"required":false},"orderby":{"required":false},"hide_empty":{"required":false},"post":{"required":false},"slug":{"required":false}}},{"methods":["POST"],"args":{"description":{"required":false},"name":{"required":true},"slug":{"required":false},"meta":{"required":false}}}]},"/wp/v2/tags/(?P[\\d]+)":{"namespace":"wp/v2","methods":["GET","POST","PUT","PATCH","DELETE"],"endpoints":[{"methods":["GET"],"args":{"context":{"required":false}}},{"methods":["POST","PUT","PATCH"],"args":{"description":{"required":false},"name":{"required":false},"slug":{"required":false},"meta":{"required":false}}},{"methods":["DELETE"],"args":{"force":{"required":false}}}]},"/wp/v2/users":{"namespace":"wp/v2","methods":["GET","POST"],"endpoints":[{"methods":["GET"],"args":{"context":{"required":false},"page":{"required":false},"per_page":{"required":false},"search":{"required":false},"exclude":{"required":false},"include":{"required":false},"offset":{"required":false},"order":{"required":false},"orderby":{"required":false},"slug":{"required":false},"roles":{"required":false}}},{"methods":["POST"],"args":{"username":{"required":true},"name":{"required":false},"first_name":{"required":false},"last_name":{"required":false},"email":{"required":true},"url":{"required":false},"description":{"required":false},"locale":{"required":false},"nickname":{"required":false},"slug":{"required":false},"roles":{"required":false},"password":{"required":true},"meta":{"required":false}}}]},"/wp/v2/users/(?P[\\d]+)":{"namespace":"wp/v2","methods":["GET","POST","PUT","PATCH","DELETE"],"endpoints":[{"methods":["GET"],"args":{"context":{"required":false}}},{"methods":["POST","PUT","PATCH"],"args":{"username":{"required":false},"name":{"required":false},"first_name":{"required":false},"last_name":{"required":false},"email":{"required":false},"url":{"required":false},"description":{"required":false},"locale":{"required":false},"nickname":{"required":false},"slug":{"required":false},"roles":{"required":false},"password":{"required":false},"meta":{"required":false}}},{"methods":["DELETE"],"args":{"force":{"required":false},"reassign":{"required":false}}}]},"/wp/v2/users/me":{"namespace":"wp/v2","methods":["GET","POST","PUT","PATCH","DELETE"],"endpoints":[{"methods":["GET"],"args":{"context":{"required":false}}},{"methods":["POST","PUT","PATCH"],"args":{"username":{"required":false},"name":{"required":false},"first_name":{"required":false},"last_name":{"required":false},"email":{"required":false},"url":{"required":false},"description":{"required":false},"locale":{"required":false},"nickname":{"required":false},"slug":{"required":false},"roles":{"required":false},"password":{"required":false},"meta":{"required":false}}},{"methods":["DELETE"],"args":{"force":{"required":false},"reassign":{"required":false}}}]},"/wp/v2/comments":{"namespace":"wp/v2","methods":["GET","POST"],"endpoints":[{"methods":["GET"],"args":{"context":{"required":false},"page":{"required":false},"per_page":{"required":false},"search":{"required":false},"after":{"required":false},"author":{"required":false},"author_exclude":{"required":false},"author_email":{"required":false},"before":{"required":false},"exclude":{"required":false},"include":{"required":false},"offset":{"required":false},"order":{"required":false},"orderby":{"required":false},"parent":{"required":false},"parent_exclude":{"required":false},"post":{"required":false},"status":{"required":false},"type":{"required":false},"password":{"required":false}}},{"methods":["POST"],"args":{"author":{"required":false},"author_email":{"required":false},"author_ip":{"required":false},"author_name":{"required":false},"author_url":{"required":false},"author_user_agent":{"required":false},"content":{"required":false},"date":{"required":false},"date_gmt":{"required":false},"parent":{"required":false},"post":{"required":false},"status":{"required":false},"meta":{"required":false}}}]},"/wp/v2/comments/(?P[\\d]+)":{"namespace":"wp/v2","methods":["GET","POST","PUT","PATCH","DELETE"],"endpoints":[{"methods":["GET"],"args":{"context":{"required":false},"password":{"required":false}}},{"methods":["POST","PUT","PATCH"],"args":{"author":{"required":false},"author_email":{"required":false},"author_ip":{"required":false},"author_name":{"required":false},"author_url":{"required":false},"author_user_agent":{"required":false},"content":{"required":false},"date":{"required":false},"date_gmt":{"required":false},"parent":{"required":false},"post":{"required":false},"status":{"required":false},"meta":{"required":false}}},{"methods":["DELETE"],"args":{"force":{"required":false},"password":{"required":false}}}]},"/wp/v2/settings":{"namespace":"wp/v2","methods":["GET","POST","PUT","PATCH"],"endpoints":[{"methods":["GET"],"args":{}},{"methods":["POST","PUT","PATCH"],"args":{"title":{"required":false},"description":{"required":false},"url":{"required":false},"email":{"required":false},"timezone":{"required":false},"date_format":{"required":false},"time_format":{"required":false},"start_of_week":{"required":false},"language":{"required":false},"use_smilies":{"required":false},"default_category":{"required":false},"default_post_format":{"required":false},"posts_per_page":{"required":false},"default_ping_status":{"required":false},"default_comment_status":{"required":false}}}]}}} \ No newline at end of file diff --git a/lib/data/simplify-object.js b/lib/data/simplify-object.js index bd088f5c..d82eafe4 100644 --- a/lib/data/simplify-object.js +++ b/lib/data/simplify-object.js @@ -37,9 +37,7 @@ function simplifyObject( obj ) { // other than "required" if ( key === 'args' ) { newObj.args = objectReduce( val, function( slimArgs, argVal, argKey ) { - slimArgs[ argKey ] = { - required: argVal.required - }; + slimArgs[ argKey ] = {}; return slimArgs; }, {}); } else { diff --git a/lib/data/generate-endpoint-response-json.js b/lib/data/update-default-routes-json.js similarity index 85% rename from lib/data/generate-endpoint-response-json.js rename to lib/data/update-default-routes-json.js index ccd72c2c..9228adc5 100755 --- a/lib/data/generate-endpoint-response-json.js +++ b/lib/data/update-default-routes-json.js @@ -9,11 +9,11 @@ * vanilla WordPress REST API installation. That file may be updated by * installing the API plugin on a clean WP development instance, with no other * plugins running, and downloading the JSON output from `yourwpsite.com/wp-json/` - * into the "endpoint-response.json" file in this directory. + * into the "default-routes.json" file in this directory. * * That file can also be generated by running this script against the same live * WP REST API instance to download that same file, the difference being that, - * if the `endpoint-response.json` file is downloaded through this script, it + * if the `default-routes.json` file is downloaded through this script, it * will be run through the `simplifyObject` utility to cut out about 1/3 of the * bytes of the response by removing properties that do not effect route generation. * @@ -24,10 +24,10 @@ * @example * * # Invoke directly, run against default endpoint (details below) - * ./generate-endpoint-response-json.js + * ./update-default-routes-json.js * * # Invoke with `node` CLI, run against default endpoint - * node ./generate-endpoint-response-json --endpoint=http://my-site.com/wp-json + * node ./update-default-routes-json --endpoint=http://my-site.com/wp-json * * This script runs against http://wpapi.loc/wp-json by default, but it can be * run against an arbitrary WordPress REST API endpoint by passing the --endpoint @@ -36,12 +36,12 @@ * @example * * # Invoke directly, run against an arbitrary WordPress API root - * ./generate-endpoint-response-json.js --endpoint=http://my-site.com/wp-json + * ./update-default-routes-json.js --endpoint=http://my-site.com/wp-json * * # Invoke with `node` CLI, run against an arbitrary WordPress API root - * node ./generate-endpoint-response-json --endpoint=http://my-site.com/wp-json + * node ./update-default-routes-json --endpoint=http://my-site.com/wp-json * - * Either form will update the `endpoint-response.json` file in this directory, + * Either form will update the `default-routes.json` file in this directory, * providing that the endpoint data is downloaded successfully. * * This script also has some utility for downloading a custom JSON file for your @@ -52,10 +52,10 @@ * @example * * # Output to your current working directory - * ./path/to/this/dir/generate-endpoint-response-json.js --output=. + * ./path/to/this/dir/update-default-routes-json.js --output=. * * # Output to an arbitrary absolute path - * ./path/to/this/dir/generate-endpoint-response-json.js --output=/home/mordor/output.json + * ./path/to/this/dir/update-default-routes-json.js --output=/home/mordor/output.json * * These command-line flags may be combined, and you will usually want to use * --endpoint alongside --output to download your own JSON into your own directory. @@ -102,7 +102,7 @@ function getJSON( cbFn ) { if ( res.type !== 'application/json' ) { console.error( '\nError: expected response type "application/json", got ' + res.type ); - console.error( 'Could not save endpoint-response.json' ); + console.error( 'Could not save default-routes.json' ); return process.exit( 1 ); } @@ -132,9 +132,11 @@ fs.stat( outputPath, function( err, stats ) { getJSON(function( response ) { // Extract the JSON var endpointJSON = JSON.parse( JSON.stringify( response.body ) ); - var slimJSON = simplifyObject( endpointJSON ); + // Simplify the JSON structure and pick out the routes dictionary + var slimJSON = simplifyObject( endpointJSON ).routes; - var outputFilePath = path.join( outputPath, 'endpoint-response.json' ); + // Save the file + var outputFilePath = path.join( outputPath, 'default-routes.json' ); fs.writeFile( outputFilePath, JSON.stringify( slimJSON ), function( err ) { if ( err ) { console.error( '\nSomething went wrong! Could not save ' + outputFilePath ); diff --git a/package.json b/package.json index a4ab8eff..4610016b 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,7 @@ "scripts": { "build": "webpack && webpack --config webpack.config.minified.js", "zip": "npm run build && grunt zip", - "download-endpoint-json": "node ./lib/data/generate-endpoint-response-json", + "update-default-routes-json": "node ./lib/data/update-default-routes-json", "docs": "grunt docs", "jekyll": "node bin/jekyll", "release-docs": "node build/scripts/release-docs", diff --git a/tests/unit/lib/data/simplify-object.js b/tests/unit/lib/data/simplify-object.js index 1015d614..8f5aa38c 100644 --- a/tests/unit/lib/data/simplify-object.js +++ b/tests/unit/lib/data/simplify-object.js @@ -77,9 +77,7 @@ describe( 'simplifyObject', function() { } }) ).to.deep.equal({ args: { - context: { - required: false - } + 'context': {} } }); }); @@ -91,44 +89,44 @@ describe( 'simplifyObject', function() { endpoints: [ { methods: [ 'GET' ], args: { - context: { required: false }, - page: { required: false }, - per_page: { required: false }, - search: { required: false }, - after: { required: false }, - author: { required: false }, - author_exclude: { required: false }, - before: { required: false }, - exclude: { required: false }, - include: { required: false }, - offset: { required: false }, - order: { required: false }, - orderby: { required: false }, - slug: { required: false }, - status: { required: false }, - filter: { required: false }, - categories: { required: false }, - tags: { required: false } + context: {}, + page: {}, + per_page: {}, + search: {}, + after: {}, + author: {}, + author_exclude: {}, + before: {}, + exclude: {}, + include: {}, + offset: {}, + order: {}, + orderby: {}, + slug: {}, + status: {}, + filter: {}, + categories: {}, + tags: {} } }, { methods: [ 'POST' ], args: { - date: { required: false }, - date_gmt: { required: false }, - password: { required: false }, - slug: { required: false }, - status: { required: false }, - title: { required: false }, - content: { required: false }, - author: { required: false }, - excerpt: { required: false }, - featured_media: { required: false }, - comment_status: { required: false }, - ping_status: { required: false }, - format: { required: false }, - sticky: { required: false }, - categories: { required: false }, - tags: { required: false } + date: {}, + date_gmt: {}, + password: {}, + slug: {}, + status: {}, + title: {}, + content: {}, + author: {}, + excerpt: {}, + featured_media: {}, + comment_status: {}, + ping_status: {}, + format: {}, + sticky: {}, + categories: {}, + tags: {} } } ] }); diff --git a/tests/unit/lib/route-tree.js b/tests/unit/lib/route-tree.js index 9f53141f..3395e50c 100644 --- a/tests/unit/lib/route-tree.js +++ b/tests/unit/lib/route-tree.js @@ -2,7 +2,7 @@ var expect = require( 'chai' ).expect; var routeTree = require( '../../../lib/route-tree' ); -var endpointResponse = require( '../../../lib/data/endpoint-response.json' ); +var defaultRoutes = require( '../../../lib/data/default-routes.json' ); describe( 'route-tree utility', function() { @@ -10,7 +10,7 @@ describe( 'route-tree utility', function() { var tree; beforeEach(function() { - tree = routeTree.build( endpointResponse.routes ); + tree = routeTree.build( defaultRoutes ); }); it( 'returns an object keyed by API namespace', function() { diff --git a/tests/unit/wpapi.js b/tests/unit/wpapi.js index f63f89f2..fb4df45a 100644 --- a/tests/unit/wpapi.js +++ b/tests/unit/wpapi.js @@ -277,7 +277,7 @@ describe( 'WPAPI', function() { endpoints: [ { methods: [ 'GET' ], args: { - filter: { required: false } + filter: {} } } ] } @@ -511,7 +511,7 @@ describe( 'WPAPI', function() { endpoints: [ { methods: [ 'GET' ], args: { - name: { required: false } + name: {} } } ] }, @@ -521,7 +521,7 @@ describe( 'WPAPI', function() { endpoints: [ { methods: [ 'GET' ], args: { - parent: { required: false } + parent: {} } } ] } diff --git a/wpapi.js b/wpapi.js index 63291f48..38ca5e40 100644 --- a/wpapi.js +++ b/wpapi.js @@ -20,7 +20,7 @@ var extend = require( 'node.extend' ); var objectReduce = require( './lib/util/object-reduce' ); // All valid routes in API v2 beta 11 -var defaultRoutes = require( './lib/data/endpoint-response.json' ).routes; +var defaultRoutes = require( './lib/data/default-routes.json' ); var buildRouteTree = require( './lib/route-tree' ).build; var generateEndpointFactories = require( './lib/endpoint-factories' ).generate;