Merge commit '5111abf1d4476edf204d0f7384b5b8247d5e661e' into releases

This commit is contained in:
RedocBot 2016-08-01 04:32:23 +00:00 committed by travis@localhost
commit 41add7fbf8
6 changed files with 41 additions and 9 deletions

View File

@ -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; * **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; * **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); * **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 ## Advanced usage
Instead of adding `spec-url` attribute to the `<redoc>` element you can initialize ReDoc via globally exposed `Redoc` object: Instead of adding `spec-url` attribute to the `<redoc>` element you can initialize ReDoc via globally exposed `Redoc` object:
@ -105,12 +105,13 @@ Instead of adding `spec-url` attribute to the `<redoc>` element you can initiali
Redoc.init(specUrl, options) 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 ```js
Redoc.init('http://petstore.swagger.io/v2/swagger.json', { Redoc.init('http://petstore.swagger.io/v2/swagger.json', {
scrollYOffset: 50 scrollYOffset: 50
}) })
``` ```
----------- -----------
## Running locally ## Running locally
1. Clone repository 1. Clone repository

View File

@ -4,10 +4,22 @@
require('shelljs/global'); require('shelljs/global');
set('-e'); set('-e');
function isPR() {
return process.env.TRAVIS_PULL_REQUEST && process.env.TRAVIS_PULL_REQUEST !== 'false';
}
if (process.env.JOB === 'e2e-guru') { if (process.env.JOB === 'e2e-guru') {
if (isPR()) {
console.log('Skiping E2E tests on PR');
return;
}
exec('npm run e2e'); exec('npm run e2e');
} else { } else {
exec('npm run unit'); exec('npm run unit');
if (isPR()) {
console.log('Skiping E2E tests on PR');
return;
}
console.log('Starting Basic E2E'); console.log('Starting Basic E2E');
exec('npm run e2e'); exec('npm run e2e');
} }

View File

@ -1,8 +1,8 @@
'use strict'; 'use strict';
import './components/Redoc/redoc-initial-styles.css!css';
import 'dropkickjs/build/css/dropkick.css!css'; import 'dropkickjs/build/css/dropkick.css!css';
import 'prismjs/themes/prism-dark.css!css'; import 'prismjs/themes/prism-dark.css!css';
import 'hint.css/hint.base.css!css'; import 'hint.css/hint.base.css!css';
import './components/Redoc/redoc-initial-styles.css!css';
import { redocVersion } from './version.js'; import { redocVersion } from './version.js';
import { Redoc } from './components/index'; import { Redoc } from './components/index';

View File

@ -42,16 +42,21 @@ export class SpecManager {
/* calculate common used values */ /* calculate common used values */
init() { init() {
let urlParts = this._url ? urlParse(this._url) : {};
let schemes = this._schema.schemes;
let protocol; let protocol;
if (!this._schema.schemes || !this._schema.schemes.length) { if (!schemes || !schemes.length) {
protocol = this._url ? urlParse(this._url).protocol : 'http'; // url parser incudles ':' in protocol so remove it
protocol = urlParts.protocol ? urlParts.protocol.slice(0, -1) : 'http';
} else { } else {
protocol = this._schema.schemes[0]; protocol = schemes[0];
if (protocol === 'http' && this._schema.schemes.indexOf('https') >= 0) { if (protocol === 'http' && schemes.indexOf('https') >= 0) {
protocol = 'https'; 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('/')) { if (this.apiUrl.endsWith('/')) {
this.apiUrl = this.apiUrl.substr(0, this.apiUrl.length - 1); this.apiUrl = this.apiUrl.substr(0, this.apiUrl.length - 1);
} }

View File

@ -1,7 +1,7 @@
{ {
"name": "redoc", "name": "redoc",
"description": "Swagger-generated API Reference Documentation", "description": "Swagger-generated API Reference Documentation",
"version": "1.0.0", "version": "1.0.1",
"repository": { "repository": {
"type": "git", "type": "git",
"url": "git://github.com/Rebilly/ReDoc" "url": "git://github.com/Rebilly/ReDoc"

View File

@ -59,6 +59,20 @@ describe('Utils', () => {
specMgr.apiUrl.should.be.equal('https://petstore.swagger.io/v2'); 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', () => { describe('byPointer method', () => {
it('should return correct schema part', ()=> { it('should return correct schema part', ()=> {
let part = specMgr.byPointer('/tags/3'); let part = specMgr.byPointer('/tags/3');