Skip to content

Commit f30d07d

Browse files
committed
Support different content type variations for json & xml
1 parent e5f90fd commit f30d07d

5 files changed

Lines changed: 1437 additions & 1238 deletions

File tree

src/components/ApiItem.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
import { makeRequest } from '../utils/make-request';
5757
import { getErrorMessage } from '../utils/errors';
5858
import Raven from 'raven-js';
59+
import { supportedContentTypes } from '@/config';
5960
6061
export default {
6162
name : 'ApiItem',
@@ -77,7 +78,7 @@
7778
7879
const contentType = response.headers.get('content-type').split(';')[0].toLowerCase();
7980
80-
if (!['application/json', 'application/xml'].includes(contentType)) {
81+
if (!supportedContentTypes.includes(contentType)) {
8182
return this.$notify({
8283
type : 'error',
8384
title : 'Unsupported response type ' + contentType,

src/components/rest/DataView.vue

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,10 @@
118118
},
119119
parsedData() {
120120
switch (this.result.contentType) {
121+
case 'text/json':
121122
case 'application/json':
122123
return this.result.data;
124+
case 'text/xml':
123125
case 'application/xml': {
124126
let object = xml2js(this.result.data, {
125127
compact : true,
@@ -131,6 +133,7 @@
131133
nativeType : true,
132134
trim : true,
133135
});
136+
console.log(object);
134137
if (this.parsingOptions.includes('collapseText')) {
135138
object = collapseKey(object, '_text');
136139
}

src/components/rest/RestExplorer.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import { makeRequest } from '../../utils/make-request';
2222
import { modifyRequest } from '../../utils/interceptor';
2323
import { getErrorMessage } from '../../utils/errors';
24+
import { supportedContentTypes } from '@/config';
2425
2526
export default {
2627
components: {
@@ -80,7 +81,7 @@
8081
8182
const contentType = response.headers.get('content-type').split(';')[0].toLowerCase();
8283
83-
if (!['application/json', 'application/xml'].includes(contentType)) {
84+
if (!supportedContentTypes.includes(contentType)) {
8485
return this.$notify({
8586
type : 'error',
8687
title : 'Unsupported response type ' + contentType,

src/config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const supportedContentTypes = ['application/json', 'application/xml', 'text/json', 'text/xml'];

0 commit comments

Comments
 (0)