Skip to content

Commit c5770b3

Browse files
authored
improvement: factor out Accept value for document fetches (#1478)
* improve: factor out Accept value for document fetches * fix import path
1 parent a65fecb commit c5770b3

File tree

3 files changed

+5
-2
lines changed

3 files changed

+5
-2
lines changed

src/constants.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const ACCEPT_HEADER_VALUE_FOR_DOCUMENTS = 'application/json, application/yaml'

src/resolver.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import Http from './http'
22
import mapSpec, {plugins} from './specmap'
33
import {normalizeSwagger} from './helpers'
4+
import {ACCEPT_HEADER_VALUE_FOR_DOCUMENTS} from './constants'
45

56
export function makeFetchJSON(http, opts = {}) {
67
const {requestInterceptor, responseInterceptor} = opts
@@ -13,7 +14,7 @@ export function makeFetchJSON(http, opts = {}) {
1314
requestInterceptor,
1415
responseInterceptor,
1516
headers: {
16-
Accept: 'application/json'
17+
Accept: ACCEPT_HEADER_VALUE_FOR_DOCUMENTS
1718
},
1819
credentials
1920
})

src/specmap/lib/refs.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import url from 'url'
55
import lib from '../lib'
66
import createError from '../lib/create-error'
77
import {isFreelyNamed, absolutifyPointer} from '../helpers'
8+
import {ACCEPT_HEADER_VALUE_FOR_DOCUMENTS} from '../../constants'
89

910
const ABSOLUTE_URL_REGEXP = new RegExp('^([a-z]+://|//)', 'i')
1011

@@ -315,7 +316,7 @@ function getDoc(docPath) {
315316
* @api public
316317
*/
317318
function fetchJSON(docPath) {
318-
return fetch(docPath, {headers: {Accept: 'application/json, application/yaml'}, loadSpec: true})
319+
return fetch(docPath, {headers: {Accept: ACCEPT_HEADER_VALUE_FOR_DOCUMENTS}, loadSpec: true})
319320
.then(res => res.text())
320321
.then(text => jsYaml.safeLoad(text))
321322
}

0 commit comments

Comments
 (0)