Skip to content

Commit 0402f89

Browse files
authored
Merge branch 'master' into bug/opid-safe-access
2 parents ada894f + 99fd9bc commit 0402f89

File tree

10 files changed

+845
-22
lines changed

10 files changed

+845
-22
lines changed

.github/pull_request_template.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<!--- Provide a general summary of your changes in the Title above -->
2+
3+
### Description
4+
<!--- Describe your changes in detail -->
5+
6+
7+
8+
### Motivation and Context
9+
<!--- Why is this change required? What problem does it solve? -->
10+
<!--- If it fixes an open issue, please link to the issue here. -->
11+
<!--- Use the magic "Fixes #1234" format, so the issues are -->
12+
<!--- automatically closed when this PR is merged. -->
13+
14+
15+
16+
### How Has This Been Tested?
17+
<!--- Please describe in detail how you manually tested your changes. -->
18+
<!--- Include details of your testing environment, and the tests you ran to -->
19+
<!--- see how your change affects other areas of the code, etc. -->
20+
21+
22+
23+
### Screenshots (if appropriate):
24+
25+
26+
27+
### Types of changes
28+
<!--- What types of changes does your code introduce? Put an `x` in all the boxes that apply: -->
29+
- [ ] No code changes (changes to documentation, CI, metadata, etc)
30+
- [ ] Dependency changes (any modification to dependencies in `package.json`)
31+
- [ ] Bug fix (non-breaking change which fixes an issue)
32+
- [ ] New feature (non-breaking change which adds functionality)
33+
- [ ] Breaking change (fix or feature that would cause existing functionality to change)
34+
35+
### Checklist:
36+
<!--- Go over all the following points, and put an `x` in all the boxes that apply. -->
37+
<!--- If you're unsure about any of these, don't hesitate to ask. We're here to help! -->
38+
- [ ] My code follows the code style of this project.
39+
- [ ] My change requires a change to the documentation.
40+
- [ ] I have updated the documentation accordingly.
41+
- [ ] I have added tests to cover my changes.
42+
- [ ] All new and existing tests passed.

.travis.yml

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
1+
sudo: false
12
language: node_js
23
node_js:
34
- '4.7'
45
- '6.9'
5-
env:
6-
- CXX=g++-4.8
7-
addons:
8-
apt:
9-
sources:
10-
- ubuntu-toolchain-r-test
11-
packages:
12-
- g++-4.8
6+
cache:
7+
directories:
8+
- node_modules
139
branches:
1410
only:
1511
- master
1612
- /^v\d+\.\d+(\.\d+)?(-\S*)?$/
13+
before_script: "npm update"
1714
before_deploy: "npm run build"
1815
deploy:
1916
provider: npm

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ This lib exposes these functionalities:
6464
HTTP Client
6565
-----------
6666

67-
`Swagger.http(req)` exposes a [Fetch-like interface](https://github.com/matthew-andrews/isomorphic-fetch) with a twist: allowing `url` in the request object so that it can be passed around and mutated. It extends Fetch to support request and response interceptors and performs response & header serialization. This method could be overridden to change how SwaggerJS performs HTTP requests.
67+
`Swagger.http(req)` exposes a [Fetch-like interface](https://github.com/lquixada/cross-fetch) with a twist: allowing `url` in the request object so that it can be passed around and mutated. It extends Fetch to support request and response interceptors and performs response & header serialization. This method could be overridden to change how SwaggerJS performs HTTP requests.
6868

6969
```js
7070
// Fetch-like, but support `url`, `query` and `xxxInterceptor`
@@ -279,6 +279,7 @@ npm run test # run test
279279
npm run test:watch # run test with change watching
280280
npm run lint # run lint
281281
npm run build # package to release
282+
npm run build-dev # package with non-minified dist/index.js (for debugging)
282283
npm run build-bundle # build browser version available at .../browser
283284
```
284285

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "swagger-client",
3-
"version": "3.3.0",
3+
"version": "3.3.1",
44
"description": "SwaggerJS - a collection of interfaces for OAI specs",
55
"main": "dist/index.js",
66
"repository": "[email protected]:swagger-api/swagger-js.git",
@@ -17,6 +17,7 @@
1717
},
1818
"scripts": {
1919
"build": "cross-env NODE_ENV=production webpack -p --config ./webpack.config.js",
20+
"build-dev": "cross-env NODE_ENV=development webpack --config ./webpack.config.js",
2021
"build-bundle": "cross-env NODE_ENV=production webpack -p --config ./webpack.bundle.config.js",
2122
"watch": "webpack --config webpack.config.js --watch --progress",
2223
"test": "npm run just-test && npm run lint",
@@ -64,12 +65,12 @@
6465
"babel-runtime": "^6.23.0",
6566
"btoa": "1.1.2",
6667
"cookie": "^0.3.1",
68+
"cross-fetch": "0.0.8",
6769
"deep-extend": "^0.4.1",
6870
"fast-json-patch": "1.1.8",
69-
"isomorphic-fetch": "2.2.1",
7071
"isomorphic-form-data": "0.0.1",
7172
"js-yaml": "^3.8.1",
72-
"lodash": "4.16.2",
73+
"lodash": "^4.16.2",
7374
"qs": "^6.3.0",
7475
"url": "^0.11.0"
7576
}

src/http.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import 'isomorphic-fetch'
1+
import 'cross-fetch/polyfill'
22
import qs from 'qs'
33
import jsYaml from 'js-yaml'
44
import isString from 'lodash/isString'

src/specmap/lib/refs.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import fetch from 'isomorphic-fetch'
1+
import {fetch} from 'cross-fetch'
22
import url from 'url'
33
import lib from '../lib'
44
import createError from '../lib/create-error'

test/client.js

Lines changed: 78 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,17 @@ describe('http', () => {
3838
}
3939
}
4040

41+
if (req.headers['x-setcontenttype']) {
42+
console.log('here come dat header', req.headers)
43+
// Allow the test to explicitly set (or unset) a content type
44+
if (req.headers['x-setcontenttype'] === 'none') {
45+
res.removeHeader('Content-Type')
46+
}
47+
else {
48+
res.setHeader('Content-Type', req.headers['x-setcontenttype'])
49+
}
50+
}
51+
4152
fs.exists(filename, function (exists) {
4253
if (exists) {
4354
const fileStream = fs.createReadStream(filename)
@@ -61,7 +72,25 @@ describe('http', () => {
6172
afterEach(function () {
6273
})
6374

64-
it.skip('should get the petstore api and build it', (done) => {
75+
it('should get the JSON petstore api and build it', (done) => {
76+
Swagger('http://localhost:8000/petstore.json')
77+
.then((client) => {
78+
expect(client).toExist()
79+
80+
// we have 3 tags
81+
expect(Object.keys(client.apis).length).toBe(3)
82+
83+
// the pet tag exists
84+
expect(client.apis.pet).toExist()
85+
86+
// the get pet operation
87+
expect(client.apis.pet.getPetById).toExist()
88+
89+
done()
90+
})
91+
})
92+
93+
it('should get the YAML petstore api and build it', (done) => {
6594
Swagger('http://localhost:8000/petstore.json')
6695
.then((client) => {
6796
expect(client).toExist()
@@ -79,6 +108,54 @@ describe('http', () => {
79108
})
80109
})
81110

111+
it('should get the JSON petstore api and build it when response lacks a `Content-Type`', (done) => {
112+
Swagger('http://localhost:8000/petstore.json', {
113+
requestInterceptor: (req) => {
114+
req.headers['X-SetContentType'] = 'none'
115+
return req
116+
}
117+
})
118+
.then((client) => {
119+
expect(client).toExist()
120+
121+
// we have 3 tags
122+
expect(Object.keys(client.apis).length).toBe(3)
123+
124+
// the pet tag exists
125+
expect(client.apis.pet).toExist()
126+
127+
// the get pet operation
128+
expect(client.apis.pet.getPetById).toExist()
129+
130+
done()
131+
})
132+
.catch(err => done(err))
133+
})
134+
135+
it('should get the YAML petstore api and build it when response lacks a `Content-Type`', (done) => {
136+
Swagger('http://localhost:8000/petstore.yaml', {
137+
requestInterceptor: (req) => {
138+
req.headers['X-SetContentType'] = 'none'
139+
return req
140+
}
141+
})
142+
.then((client) => {
143+
expect(client).toExist()
144+
145+
// we have 3 tags
146+
expect(Object.keys(client.apis).length).toBe(3)
147+
148+
// the pet tag exists
149+
expect(client.apis.pet).toExist()
150+
151+
// the get pet operation
152+
expect(client.apis.pet.getPetById).toExist()
153+
154+
done()
155+
})
156+
.catch(err => done(err))
157+
})
158+
82159
/**
83160
* See https://github.com/swagger-api/swagger-js/issues/1005
84161
*/

0 commit comments

Comments
 (0)