2017-10-12 00:01:37 +03:00
|
|
|
import { OpenAPIContact, OpenAPIInfo, OpenAPILicense } from '../../types';
|
2018-01-09 20:00:17 +03:00
|
|
|
import { isBrowser } from '../../utils/';
|
2018-01-22 21:30:53 +03:00
|
|
|
import { OpenAPIParser } from '../OpenAPIParser';
|
2017-10-12 00:01:37 +03:00
|
|
|
|
|
|
|
export class ApiInfoModel implements OpenAPIInfo {
|
|
|
|
title: string;
|
|
|
|
version: string;
|
|
|
|
|
|
|
|
description?: string;
|
|
|
|
termsOfService?: string;
|
|
|
|
contact?: OpenAPIContact;
|
|
|
|
license?: OpenAPILicense;
|
|
|
|
|
|
|
|
constructor(public parser: OpenAPIParser) {
|
2017-11-14 18:46:50 +03:00
|
|
|
Object.assign(this, parser.spec.info);
|
2017-10-12 00:01:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
get downloadLink() {
|
2018-01-09 20:00:17 +03:00
|
|
|
if (!this.parser.specUrl && isBrowser && window.Blob && window.URL) {
|
2017-10-12 00:01:37 +03:00
|
|
|
const blob = new Blob([JSON.stringify(this.parser.spec, null, 2)], {
|
|
|
|
type: 'application/json',
|
|
|
|
});
|
|
|
|
return window.URL.createObjectURL(blob);
|
2018-01-10 19:24:55 +03:00
|
|
|
} else if (!isBrowser) {
|
|
|
|
return (
|
|
|
|
'data:application/octet-stream;base64,' +
|
|
|
|
new Buffer(JSON.stringify(this.parser.spec, null, 2)).toString('base64')
|
|
|
|
);
|
2017-10-12 00:01:37 +03:00
|
|
|
}
|
|
|
|
return this.parser.specUrl;
|
|
|
|
}
|
|
|
|
|
|
|
|
get downloadFileName(): string | undefined {
|
2018-01-10 19:24:55 +03:00
|
|
|
if (!this.parser.specUrl) {
|
2017-10-12 00:01:37 +03:00
|
|
|
return 'swagger.json';
|
|
|
|
}
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
}
|