fix: don't show download button if initialized with an object

This commit is contained in:
Roman Hotsiy 2017-04-23 15:22:04 +03:00
parent 0f6f0359d9
commit 476d6c44fe
No known key found for this signature in database
GPG Key ID: 5CB7B3ACABA57CB0
4 changed files with 8 additions and 8 deletions

View File

@ -1,6 +1,6 @@
<div class="api-info-wrapper"> <div class="api-info-wrapper">
<h1>{{info.title}} <span class="api-info-version">({{info.version}})</span></h1> <h1>{{info.title}} <span class="api-info-version">({{info.version}})</span></h1>
<p> <p class="donwload-openapi" *ngIf="specUrl">
Download OpenAPI (fka Swagger) specification: Download OpenAPI (fka Swagger) specification:
<a class="openapi-button" target="_blank" attr.href='{{specUrl}}'> Download </a> <a class="openapi-button" target="_blank" attr.href='{{specUrl}}'> Download </a>
</p> </p>

View File

@ -23,7 +23,7 @@ export class ApiInfo extends BaseComponent implements OnInit {
init() { init() {
this.info = this.componentSchema.info; this.info = this.componentSchema.info;
this.specUrl = this.optionsService.options.specUrl; this.specUrl = this.specMgr.specUrl;
if (!isNaN(parseInt(this.info.version.toString().substring(0, 1)))) { if (!isNaN(parseInt(this.info.version.toString().substring(0, 1)))) {
this.info.version = 'v' + this.info.version; this.info.version = 'v' + this.info.version;
} }

View File

@ -32,7 +32,7 @@ export class SpecManager {
public basePath: string; public basePath: string;
public spec = new BehaviorSubject<any|null>(null); public spec = new BehaviorSubject<any|null>(null);
public _specUrl: string; public specUrl: string;
private parser: any; private parser: any;
private options: Options; private options: Options;
@ -46,7 +46,7 @@ export class SpecManager {
this.parser.bundle(urlOrObject, {http: {withCredentials: false}}) this.parser.bundle(urlOrObject, {http: {withCredentials: false}})
.then(schema => { .then(schema => {
if (typeof urlOrObject === 'string') { if (typeof urlOrObject === 'string') {
this._specUrl = urlOrObject; this.specUrl = urlOrObject;
} }
this._schema = snapshot(schema); this._schema = snapshot(schema);
try { try {
@ -64,7 +64,7 @@ export class SpecManager {
/* calculate common used values */ /* calculate common used values */
init() { init() {
let urlParts = this._specUrl ? urlParse(urlResolve(window.location.href, this._specUrl)) : {}; let urlParts = this.specUrl ? urlParse(urlResolve(window.location.href, this.specUrl)) : {};
let schemes = this._schema.schemes; let schemes = this._schema.schemes;
let protocol; let protocol;
if (!schemes || !schemes.length) { if (!schemes || !schemes.length) {

View File

@ -46,21 +46,21 @@ describe('Utils', () => {
it('should substitute api scheme when spec schemes are undefined', () => { it('should substitute api scheme when spec schemes are undefined', () => {
specMgr._schema.schemes = undefined; specMgr._schema.schemes = undefined;
specMgr._specUrl = 'https://petstore.swagger.io/v2'; specMgr.specUrl = 'https://petstore.swagger.io/v2';
specMgr.init(); specMgr.init();
specMgr.apiUrl.should.be.equal('https://petstore.swagger.io/v2'); specMgr.apiUrl.should.be.equal('https://petstore.swagger.io/v2');
}); });
it('should substitute api host when spec host is undefined', () => { it('should substitute api host when spec host is undefined', () => {
specMgr._schema.host = undefined; specMgr._schema.host = undefined;
specMgr._specUrl = 'http://petstore.swagger.io/v2'; specMgr.specUrl = 'http://petstore.swagger.io/v2';
specMgr.init(); specMgr.init();
specMgr.apiUrl.should.be.equal('http://petstore.swagger.io/v2'); specMgr.apiUrl.should.be.equal('http://petstore.swagger.io/v2');
}); });
it('should use empty basePath when basePath is not present', () => { it('should use empty basePath when basePath is not present', () => {
specMgr._schema.basePath = undefined; specMgr._schema.basePath = undefined;
specMgr._specUrl = 'https://petstore.swagger.io'; specMgr.specUrl = 'https://petstore.swagger.io';
specMgr.init(); specMgr.init();
specMgr.basePath.should.be.equal(''); specMgr.basePath.should.be.equal('');
}); });