From 7aeb69916a7f436907d7516dfb2643e44d083957 Mon Sep 17 00:00:00 2001 From: Jeff Stieler Date: Wed, 5 Dec 2018 12:10:43 -0700 Subject: [PATCH] Fix swagger hub requests from wc-api (url vs. path). --- .../client/wc-api/reports/items/operations.js | 14 ++++++------- .../client/wc-api/reports/stats/operations.js | 20 +++++++++---------- 2 files changed, 16 insertions(+), 18 deletions(-) diff --git a/plugins/woocommerce-admin/client/wc-api/reports/items/operations.js b/plugins/woocommerce-admin/client/wc-api/reports/items/operations.js index b27ffb37625..61cd06478c3 100644 --- a/plugins/woocommerce-admin/client/wc-api/reports/items/operations.js +++ b/plugins/woocommerce-admin/client/wc-api/reports/items/operations.js @@ -39,18 +39,18 @@ function read( resourceNames, fetch = apiFetch ) { const endpoint = typeEndpointMap[ prefix ]; const query = getResourceIdentifier( resourceName ); - let apiPath = NAMESPACE + '/reports/' + endpoint + stringifyQuery( query ); + const fetchArgs = { + parse: false, + }; if ( swaggerEndpoints.indexOf( endpoint ) >= 0 ) { - apiPath = SWAGGERNAMESPACE + 'reports/' + endpoint + stringifyQuery( query ); + fetchArgs.url = SWAGGERNAMESPACE + 'reports/' + endpoint + stringifyQuery( query ); + } else { + fetchArgs.path = NAMESPACE + '/reports/' + endpoint + stringifyQuery( query ); } try { - const response = await fetch( { - parse: false, - path: apiPath, - } ); - + const response = await fetch( fetchArgs ); const report = await response.json(); // TODO: exclude these if using swagger? const totalResults = parseInt( response.headers.get( 'x-wp-total' ) ); diff --git a/plugins/woocommerce-admin/client/wc-api/reports/stats/operations.js b/plugins/woocommerce-admin/client/wc-api/reports/stats/operations.js index 19d54b14cf5..7529a103a64 100644 --- a/plugins/woocommerce-admin/client/wc-api/reports/stats/operations.js +++ b/plugins/woocommerce-admin/client/wc-api/reports/stats/operations.js @@ -40,22 +40,20 @@ function read( resourceNames, fetch = apiFetch ) { const endpoint = typeEndpointMap[ prefix ]; const query = getResourceIdentifier( resourceName ); - let apiPath = endpoint + stringifyQuery( query ); + const fetchArgs = { + parse: false, + }; if ( swaggerEndpoints.indexOf( endpoint ) >= 0 ) { - apiPath = SWAGGERNAMESPACE + 'reports/' + endpoint + '/stats' + stringifyQuery( query ); - } - - if ( statEndpoints.indexOf( endpoint ) >= 0 ) { - apiPath = NAMESPACE + '/reports/' + endpoint + '/stats' + stringifyQuery( query ); + fetchArgs.url = SWAGGERNAMESPACE + 'reports/' + endpoint + '/stats' + stringifyQuery( query ); + } else if ( statEndpoints.indexOf( endpoint ) >= 0 ) { + fetchArgs.path = NAMESPACE + '/reports/' + endpoint + '/stats' + stringifyQuery( query ); + } else { + fetchArgs.path = endpoint + stringifyQuery( query ); } try { - const response = await fetch( { - parse: false, - path: apiPath, - } ); - + const response = await fetch( fetchArgs ); const report = await response.json(); // TODO: exclude these if using swagger? const totalResults = parseInt( response.headers.get( 'x-wp-total' ) );