mirror of
https://github.com/Redocly/redoc.git
synced 2025-01-30 17:44:07 +03:00
If API supports both HTTP and HTTPS use HTTPS (fixes #72)
This commit is contained in:
parent
ae0b0f5f14
commit
2872ffbcf9
|
@ -1,6 +1,7 @@
|
|||
swagger: '2.0'
|
||||
schemes:
|
||||
- http
|
||||
- https
|
||||
host: petstore.swagger.io
|
||||
basePath: /v2
|
||||
info:
|
||||
|
|
|
@ -4,11 +4,13 @@ import JsonSchemaRefParser from 'json-schema-ref-parser';
|
|||
import JsonPointer from './JsonPointer';
|
||||
import { renderMd, safePush } from './helpers';
|
||||
import slugify from 'slugify';
|
||||
import { parse as urlParse } from 'url';
|
||||
|
||||
export class SpecManager {
|
||||
public _schema:any = {};
|
||||
public _schema: any = {};
|
||||
public apiUrl: string;
|
||||
private _instance:any;
|
||||
private _instance: any;
|
||||
private _url: string;
|
||||
|
||||
static instance() {
|
||||
return new SpecManager();
|
||||
|
@ -28,6 +30,7 @@ export class SpecManager {
|
|||
|
||||
JsonSchemaRefParser.bundle(url, {http: {withCredentials: false}})
|
||||
.then(schema => {
|
||||
this._url = url;
|
||||
this._schema = schema;
|
||||
resolve(this._schema);
|
||||
this.init();
|
||||
|
@ -39,8 +42,16 @@ export class SpecManager {
|
|||
|
||||
/* calculate common used values */
|
||||
init() {
|
||||
if (!this._schema || !this._schema.schemes) return;
|
||||
this.apiUrl = this._schema.schemes[0] + '://' + this._schema.host + this._schema.basePath;
|
||||
let protocol;
|
||||
if (!this._schema.schemes || !this._schema.schemes.length) {
|
||||
protocol = this._url ? urlParse(this._url).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;
|
||||
if (this.apiUrl.endsWith('/')) {
|
||||
this.apiUrl = this.apiUrl.substr(0, this.apiUrl.length - 1);
|
||||
}
|
||||
|
|
|
@ -50,6 +50,7 @@
|
|||
"scrollparent": "npm:scrollparent@^0.1.0",
|
||||
"slugify": "npm:slugify@^0.1.1",
|
||||
"stream-http": "npm:stream-http@^2.3.0",
|
||||
"url": "github:jspm/nodelibs-url@^0.1.0",
|
||||
"zone.js": "npm:zone.js@0.6.12"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
|
|
@ -41,6 +41,7 @@ System.config({
|
|||
"slugify": "npm:slugify@0.1.1",
|
||||
"stream-http": "npm:stream-http@2.3.0",
|
||||
"systemjs/plugin-json": "github:systemjs/plugin-json@0.1.2",
|
||||
"url": "github:jspm/nodelibs-url@0.1.0",
|
||||
"zone.js": "npm:zone.js@0.6.12",
|
||||
"github:jspm/nodelibs-assert@0.1.0": {
|
||||
"assert": "npm:assert@1.4.1"
|
||||
|
|
|
@ -53,6 +53,12 @@ describe('Utils', () => {
|
|||
specMgr.apiUrl.should.be.equal('http://petstore.swagger.io/v2');
|
||||
});
|
||||
|
||||
it('should correctly init api url if both http and https', ()=> {
|
||||
specMgr._schema.schemes.push('https');
|
||||
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');
|
||||
|
|
2590
typings/globals/node/index.d.ts
vendored
Normal file
2590
typings/globals/node/index.d.ts
vendored
Normal file
File diff suppressed because it is too large
Load Diff
8
typings/globals/node/typings.json
Normal file
8
typings/globals/node/typings.json
Normal file
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
"resolution": "main",
|
||||
"tree": {
|
||||
"src": "https://raw.githubusercontent.com/DefinitelyTyped/DefinitelyTyped/91d45c49a3b5cd6a0abbf5f319c1406fd4f2b1e7/node/node.d.ts",
|
||||
"raw": "registry:dt/node#6.0.0+20160720070758",
|
||||
"typings": "https://raw.githubusercontent.com/DefinitelyTyped/DefinitelyTyped/91d45c49a3b5cd6a0abbf5f319c1406fd4f2b1e7/node/node.d.ts"
|
||||
}
|
||||
}
|
1
typings/index.d.ts
vendored
1
typings/index.d.ts
vendored
|
@ -1,3 +1,4 @@
|
|||
/// <reference path="globals/jasmine/index.d.ts" />
|
||||
/// <reference path="globals/json-pointer/index.d.ts" />
|
||||
/// <reference path="globals/node/index.d.ts" />
|
||||
/// <reference path="globals/should/index.d.ts" />
|
||||
|
|
Loading…
Reference in New Issue
Block a user