Fix swagger hub requests from wc-api (url vs. path).

This commit is contained in:
Jeff Stieler 2018-12-05 12:10:43 -07:00
parent d28eb0bcc9
commit 7aeb69916a
2 changed files with 16 additions and 18 deletions

View File

@ -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' ) );

View File

@ -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' ) );