Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Swagger Client <img src="https://raw.githubusercontent.com/swagger-api/swagger.io/wordpress/images/assets/SW-logo-clr.png" height="50" align="right">

[![Build Status](https://travis-ci.org/swagger-api/swagger-js.svg?branch=master)](https://travis-ci.org/swagger-api/swagger-js)
[![Build Status](https://jenkins.swagger.io/view/OSS%20-%20JavaScript/job/oss-swagger-js-master/badge/icon?subject=jenkins%20build)](https://jenkins.swagger.io/view/OSS%20-%20JavaScript/job/oss-swagger-js-master/)

**Swagger Client** is a JavaScript module that allows you to fetch, resolve, and interact with Swagger/OpenAPI documents.

Expand Down
17 changes: 5 additions & 12 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "swagger-client",
"version": "3.8.26",
"version": "3.9.0",
"description": "SwaggerJS - a collection of interfaces for OAI specs",
"main": "dist/index.js",
"unpkg": "browser/index.js",
Expand Down Expand Up @@ -91,7 +91,6 @@
"@kyleshockey/object-assign-deep": "^0.4.0",
"babel-runtime": "^6.26.0",
"btoa": "1.1.2",
"buffer": "^5.1.0",
"cookie": "^0.3.1",
"cross-fetch": "0.0.8",
"deep-extend": "^0.5.1",
Expand Down
18 changes: 2 additions & 16 deletions src/execute/oas3/build-request.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import assign from 'lodash/assign'
import get from 'lodash/get'
import btoa from 'btoa'
import {Buffer} from 'buffer/'
import {isFile} from '../../http'

export default function (options, req) {
const {
Expand Down Expand Up @@ -57,21 +57,7 @@ export default function (options, req) {
const val = requestBody[k]
let newVal

let isFile

if (typeof File !== 'undefined') {
isFile = val instanceof File // eslint-disable-line no-undef
}

if (typeof Blob !== 'undefined') {
isFile = isFile || val instanceof Blob // eslint-disable-line no-undef
}

if (typeof Buffer !== 'undefined') {
isFile = isFile || Buffer.isBuffer(val)
}

if (typeof val === 'object' && !isFile) {
if (typeof val === 'object' && !isFile(val)) {
if (Array.isArray(val)) {
newVal = val.toString()
}
Expand Down
8 changes: 5 additions & 3 deletions src/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,15 +139,17 @@ export function isFile(obj, navigatorObj) {
// eslint-disable-next-line no-undef
navigatorObj = navigator
}
if (typeof Blob !== 'undefined' && obj instanceof Blob) { // eslint-disable-line no-undef
return true
}
if (navigatorObj && navigatorObj.product === 'ReactNative') {
if (obj && typeof obj === 'object' && typeof obj.uri === 'string') {
return true
}
return false
}
if (typeof File !== 'undefined') {
// eslint-disable-next-line no-undef
return obj instanceof File
if (typeof File !== 'undefined' && obj instanceof File) { // eslint-disable-line no-undef
return true
}
return obj !== null && typeof obj === 'object' && typeof obj.pipe === 'function'
}
Expand Down
20 changes: 20 additions & 0 deletions test/http.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import xmock from 'xmock'
import fetchMock from 'fetch-mock'
import {Readable} from 'stream'
import http, {
serializeHeaders, mergeInQueryOrForm, encodeFormOrQuery, serializeRes,
shouldDownloadAsText, isFile
Expand Down Expand Up @@ -429,6 +430,7 @@ describe('http', () => {
describe('isFile', () => {
// mock browser File class
global.File = class MockBrowserFile {}
global.Blob = class MockBlob {}

const mockBrowserNavigator = {
product: 'Gecko'
Expand All @@ -438,9 +440,11 @@ describe('http', () => {
}

const browserFile = new global.File()
const browserBlobFile = new global.Blob()
const reactNativeFileObject = {
uri: '/mock/path'
}
const nodeStream = new Readable()

test('should return true for browser File type', () => {
expect(isFile(browserFile)).toEqual(true)
Expand All @@ -462,6 +466,14 @@ describe('http', () => {
expect(isFile(reactNativeFileObject, mockReactNativeNavigator)).toEqual(true)
})

test('should return true for browser Blob type and browser user agent', () => {
expect(isFile(browserBlobFile, mockBrowserNavigator)).toEqual(true)
})

test('should return true for readable node streams', () => {
expect(isFile(nodeStream)).toEqual(true)
})

test('should return false for non-File type and browser user agent', () => {
expect(isFile(undefined, mockBrowserNavigator)).toEqual(false)
expect(isFile('', mockBrowserNavigator)).toEqual(false)
Expand All @@ -477,5 +489,13 @@ describe('http', () => {
expect(isFile([], mockReactNativeNavigator)).toEqual(false)
expect(isFile({}, mockReactNativeNavigator)).toEqual(false)
})

test('should return false for non-object type and no user agent', () => {
expect(isFile(undefined)).toEqual(false)
expect(isFile('')).toEqual(false)
expect(isFile(123)).toEqual(false)
expect(isFile([])).toEqual(false)
expect(isFile({})).toEqual(false)
})
})
})