From bc47b40466e7b8ed1f9d3cd8ecd83babecdb2411 Mon Sep 17 00:00:00 2001 From: Roman Hotsiy Date: Fri, 29 Jul 2016 18:20:38 +0300 Subject: [PATCH 1/7] Update README.md --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) 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 From 51965f94b527a1e42e9e8a1daf3bf219b85154de Mon Sep 17 00:00:00 2001 From: Mike Stead Date: Mon, 1 Aug 2016 09:46:34 +1000 Subject: [PATCH 2/7] Use api host if schema host is undefined --- lib/utils/SpecManager.ts | 6 ++++-- tests/unit/SpecManager.spec.ts | 7 +++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/utils/SpecManager.ts b/lib/utils/SpecManager.ts index 74f4d347..3b5776e6 100644 --- a/lib/utils/SpecManager.ts +++ b/lib/utils/SpecManager.ts @@ -43,15 +43,17 @@ export class SpecManager { /* calculate common used values */ init() { let protocol; + const urlParts = urlParse(this._url); if (!this._schema.schemes || !this._schema.schemes.length) { - protocol = this._url ? urlParse(this._url).protocol : 'http'; + protocol = this._url ? urlParts.protocol : 'http'; } else { protocol = this._schema.schemes[0]; if (protocol === 'http' && this._schema.schemes.indexOf('https') >= 0) { protocol = 'https'; } } - this.apiUrl = protocol + '://' + this._schema.host + this._schema.basePath; + let host = (!this._schema.host && urlParts.host) ? urlParts.host : this._schema.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/tests/unit/SpecManager.spec.ts b/tests/unit/SpecManager.spec.ts index 869392d1..1a32af5e 100644 --- a/tests/unit/SpecManager.spec.ts +++ b/tests/unit/SpecManager.spec.ts @@ -59,6 +59,13 @@ describe('Utils', () => { 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'); From 190b5e79f6be448b31883f512664d6985c211af4 Mon Sep 17 00:00:00 2001 From: Mike Stead Date: Mon, 1 Aug 2016 09:57:06 +1000 Subject: [PATCH 3/7] Replace const with let to conform to coding style --- lib/utils/SpecManager.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/utils/SpecManager.ts b/lib/utils/SpecManager.ts index 3b5776e6..02c5e92a 100644 --- a/lib/utils/SpecManager.ts +++ b/lib/utils/SpecManager.ts @@ -43,7 +43,7 @@ export class SpecManager { /* calculate common used values */ init() { let protocol; - const urlParts = urlParse(this._url); + let urlParts = urlParse(this._url); if (!this._schema.schemes || !this._schema.schemes.length) { protocol = this._url ? urlParts.protocol : 'http'; } else { From e8f090604ca794730ef211219b2df4b88e02a808 Mon Sep 17 00:00:00 2001 From: Mike Stead Date: Mon, 1 Aug 2016 10:26:10 +1000 Subject: [PATCH 4/7] Validate that api scheme is used correctly --- lib/utils/SpecManager.ts | 15 +++++++++------ tests/unit/SpecManager.spec.ts | 7 +++++++ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/lib/utils/SpecManager.ts b/lib/utils/SpecManager.ts index 02c5e92a..080e52e0 100644 --- a/lib/utils/SpecManager.ts +++ b/lib/utils/SpecManager.ts @@ -42,17 +42,20 @@ export class SpecManager { /* calculate common used values */ init() { + let urlParts = this._url ? urlParse(this._url) : {}; + let schemes = this._schema.schemes; let protocol; - let urlParts = urlParse(this._url); - if (!this._schema.schemes || !this._schema.schemes.length) { - protocol = this._url ? urlParts.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'; } } - let host = (!this._schema.host && urlParts.host) ? urlParts.host : this._schema.host; + + 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/tests/unit/SpecManager.spec.ts b/tests/unit/SpecManager.spec.ts index 1a32af5e..8bdfedd6 100644 --- a/tests/unit/SpecManager.spec.ts +++ b/tests/unit/SpecManager.spec.ts @@ -59,6 +59,13 @@ 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'; From 8300aa60556dd75c6f96bf3f28469bbeb73a287a Mon Sep 17 00:00:00 2001 From: Roman Hotsiy Date: Mon, 1 Aug 2016 07:04:35 +0300 Subject: [PATCH 5/7] Fix tests failure on PR --- build/run_tests.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) 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'); } From ce41ac13807437f782e8a68c733083d39699c634 Mon Sep 17 00:00:00 2001 From: Roman Hotsiy Date: Mon, 1 Aug 2016 07:23:01 +0300 Subject: [PATCH 6/7] move initial styles import to the top --- lib/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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'; From 5111abf1d4476edf204d0f7384b5b8247d5e661e Mon Sep 17 00:00:00 2001 From: Roman Hotsiy Date: Mon, 1 Aug 2016 07:23:09 +0300 Subject: [PATCH 7/7] v1.0.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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"