Skip to content

Commit a9c61c0

Browse files
authored
Merge branch 'master' into master
2 parents 2c4409c + 581f181 commit a9c61c0

File tree

7 files changed

+94
-18
lines changed

7 files changed

+94
-18
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: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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: 3 additions & 2 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",
@@ -69,7 +70,7 @@
6970
"fast-json-patch": "1.1.8",
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/execute/index.js

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -286,15 +286,18 @@ function buildOas3UrlWithContext(ourUrl = '', contextUrl = '') {
286286
const computedScheme = stripNonAlpha(parsedUrl.protocol) || stripNonAlpha(parsedContextUrl.protocol) || ''
287287
const computedHost = parsedUrl.host || parsedContextUrl.host
288288
const computedPath = parsedUrl.pathname || ''
289+
let res
289290

290291
if (computedScheme && computedHost) {
291-
const res = `${computedScheme}://${computedHost + computedPath}`
292+
res = `${computedScheme}://${computedHost + computedPath}`
292293

293294
// If last character is '/', trim it off
294-
return res[res.length - 1] === '/' ? res.slice(0, -1) : res
295+
}
296+
else {
297+
res = computedPath
295298
}
296299

297-
return ''
300+
return res[res.length - 1] === '/' ? res.slice(0, -1) : res
298301
}
299302

300303
function getVariableTemplateNames(str) {
@@ -317,13 +320,17 @@ function swagger2BaseUrl({spec, scheme, contextUrl = ''}) {
317320
const computedScheme = scheme || firstSchemeInSpec || stripNonAlpha(parsedContextUrl.protocol) || 'http'
318321
const computedHost = spec.host || parsedContextUrl.host || ''
319322
const computedPath = spec.basePath || ''
323+
let res
320324

321325
if (computedScheme && computedHost) {
322-
const res = `${computedScheme}://${computedHost + computedPath}`
323-
324-
// If last character is '/', trim it off
325-
return res[res.length - 1] === '/' ? res.slice(0, -1) : res
326+
// we have what we need for an absolute URL
327+
res = `${computedScheme}://${computedHost + computedPath}`
328+
}
329+
else {
330+
// if not, a relative URL will have to do
331+
res = computedPath
326332
}
327333

328-
return ''
334+
// If last character is '/', trim it off
335+
return res[res.length - 1] === '/' ? res.slice(0, -1) : res
329336
}

test/execute/baseurl.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,4 +129,15 @@ describe('baseUrl', () => {
129129

130130
expect(res).toEqual('https://example.com:9090')
131131
})
132+
133+
it('should include a basePath when no contextUrl is available', () => {
134+
const res = baseUrl({
135+
spec: {
136+
title: 'a spec',
137+
basePath: '/mybase'
138+
}
139+
})
140+
141+
expect(res).toEqual('/mybase')
142+
})
132143
})

test/oas3/execute/main.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,23 @@ describe('buildRequest - OpenAPI Specification 3.0', function () {
497497

498498
expect(res).toEqual('http://google.com')
499499
})
500+
it('should create a relative url based on a relative server if no contextUrl is available', function () {
501+
const spec = {
502+
openapi: '3.0.0',
503+
servers: [
504+
{
505+
url: '/mypath'
506+
}
507+
]
508+
}
509+
510+
const res = baseUrl({
511+
spec,
512+
server: '/mypath'
513+
})
514+
515+
expect(res).toEqual('/mypath')
516+
})
500517
it('should return an empty string if no servers or contextUrl are provided', function () {
501518
const spec = {
502519
openapi: '3.0.0'

0 commit comments

Comments
 (0)