diff --git a/README.md b/README.md index 41b83e7c..e9e357a0 100644 --- a/README.md +++ b/README.md @@ -97,7 +97,7 @@ ReDoc makes use of the following [vendor extensions](http://swagger.io/specifica * **number**: A fixed number of pixels to be used as offset; * **selector**: selector of the element to be used for specifying the offset. The distance from the top of the page to the element's bottom will be used as offset; * **function**: A getter function. Must return a number representing the offset (in pixels); -* `suppress-warnings` - if set, warnings are not rendered at the top of page (they still are logged to the console). +* `suppress-warnings` - if set, warnings are not rendered at the top of documentation (they still are logged to the console). ## Advanced usage Instead of adding `spec-url` attribute to the `` element you can initialize ReDoc via globally exposed `Redoc` object: @@ -105,12 +105,13 @@ Instead of adding `spec-url` attribute to the `` element you can initiali Redoc.init(specUrl, options) ``` -`options` is javascript object with camel-cased version of options names as the keys. For example: +`options` is javascript object with camel-cased version of options names as the keys, e.g.: ```js Redoc.init('http://petstore.swagger.io/v2/swagger.json', { scrollYOffset: 50 }) ``` + ----------- ## Running locally 1. Clone repository diff --git a/build/run_tests.js b/build/run_tests.js index 40b488fa..dc8b232c 100755 --- a/build/run_tests.js +++ b/build/run_tests.js @@ -4,10 +4,22 @@ require('shelljs/global'); set('-e'); +function isPR() { + return process.env.TRAVIS_PULL_REQUEST && process.env.TRAVIS_PULL_REQUEST !== 'false'; +} + if (process.env.JOB === 'e2e-guru') { + if (isPR()) { + console.log('Skiping E2E tests on PR'); + return; + } exec('npm run e2e'); } else { exec('npm run unit'); + if (isPR()) { + console.log('Skiping E2E tests on PR'); + return; + } console.log('Starting Basic E2E'); exec('npm run e2e'); } diff --git a/lib/index.js b/lib/index.js index 8e0aa90f..620fc1af 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1,8 +1,8 @@ 'use strict'; +import './components/Redoc/redoc-initial-styles.css!css'; import 'dropkickjs/build/css/dropkick.css!css'; import 'prismjs/themes/prism-dark.css!css'; import 'hint.css/hint.base.css!css'; -import './components/Redoc/redoc-initial-styles.css!css'; import { redocVersion } from './version.js'; import { Redoc } from './components/index'; diff --git a/lib/utils/SpecManager.ts b/lib/utils/SpecManager.ts index 74f4d347..080e52e0 100644 --- a/lib/utils/SpecManager.ts +++ b/lib/utils/SpecManager.ts @@ -42,16 +42,21 @@ export class SpecManager { /* calculate common used values */ init() { + let urlParts = this._url ? urlParse(this._url) : {}; + let schemes = this._schema.schemes; let protocol; - if (!this._schema.schemes || !this._schema.schemes.length) { - protocol = this._url ? urlParse(this._url).protocol : 'http'; + if (!schemes || !schemes.length) { + // url parser incudles ':' in protocol so remove it + protocol = urlParts.protocol ? urlParts.protocol.slice(0, -1) : 'http'; } else { - protocol = this._schema.schemes[0]; - if (protocol === 'http' && this._schema.schemes.indexOf('https') >= 0) { + protocol = schemes[0]; + if (protocol === 'http' && schemes.indexOf('https') >= 0) { protocol = 'https'; } } - this.apiUrl = protocol + '://' + this._schema.host + this._schema.basePath; + + let host = this._schema.host || urlParts.host; + this.apiUrl = protocol + '://' + host + this._schema.basePath; if (this.apiUrl.endsWith('/')) { this.apiUrl = this.apiUrl.substr(0, this.apiUrl.length - 1); } diff --git a/package.json b/package.json index 3c7d2f69..e123f48f 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "redoc", "description": "Swagger-generated API Reference Documentation", - "version": "1.0.0", + "version": "1.0.1", "repository": { "type": "git", "url": "git://github.com/Rebilly/ReDoc" diff --git a/tests/unit/SpecManager.spec.ts b/tests/unit/SpecManager.spec.ts index 869392d1..8bdfedd6 100644 --- a/tests/unit/SpecManager.spec.ts +++ b/tests/unit/SpecManager.spec.ts @@ -59,6 +59,20 @@ describe('Utils', () => { specMgr.apiUrl.should.be.equal('https://petstore.swagger.io/v2'); }); + it('should substitute api scheme when spec schemes are undefined', () => { + specMgr._schema.schemes = undefined; + specMgr._url = 'https://petstore.swagger.io/v2'; + specMgr.init(); + specMgr.apiUrl.should.be.equal('https://petstore.swagger.io/v2'); + }); + + it('should substitute api host when spec host is undefined', () => { + specMgr._schema.host = undefined; + specMgr._url = 'https://petstore.swagger.io/v2'; + specMgr.init(); + specMgr.apiUrl.should.be.equal('https://petstore.swagger.io/v2'); + }); + describe('byPointer method', () => { it('should return correct schema part', ()=> { let part = specMgr.byPointer('/tags/3');