Skip to content

Commit 6ea9e34

Browse files
committedDec 20, 2018
Exclude args objects for non-GET endpoints from simplified route tree
1 parent eedfdba commit 6ea9e34

File tree

2 files changed

+9
-18
lines changed

2 files changed

+9
-18
lines changed
 

‎build/scripts/simplify-object.js

+8
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,14 @@ const simplifyObject = ( obj ) => {
2323
return obj;
2424
}
2525

26+
if ( obj.methods && obj.args ) {
27+
// If the key is an object with "methods" and "args" properties, only
28+
// include the full "args" object if "methods" contains GET.
29+
if ( ! obj.methods.map( str => str.toLowerCase() ).includes( 'get' ) ) {
30+
obj.args = {};
31+
}
32+
}
33+
2634
// Map arrays through simplifyObject
2735
if ( Array.isArray( obj ) ) {
2836
return obj.map( simplifyObject );

‎tests/unit/build/scripts/simplify-object.js

+1-18
Original file line numberDiff line numberDiff line change
@@ -109,24 +109,7 @@ describe( 'simplifyObject', () => {
109109
},
110110
}, {
111111
methods: [ 'POST' ],
112-
args: {
113-
date: {},
114-
date_gmt: {},
115-
password: {},
116-
slug: {},
117-
status: {},
118-
title: {},
119-
content: {},
120-
author: {},
121-
excerpt: {},
122-
featured_media: {},
123-
comment_status: {},
124-
ping_status: {},
125-
format: {},
126-
sticky: {},
127-
categories: {},
128-
tags: {},
129-
},
112+
args: {},
130113
} ],
131114
} );
132115
} );

0 commit comments

Comments
 (0)
Please sign in to comment.