2017-10-12 00:01:37 +03:00
|
|
|
import { OpenAPIContact, OpenAPIInfo, OpenAPILicense } from '../../types';
|
2018-03-26 18:14:38 +03:00
|
|
|
import { IS_BROWSER } 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;
|
|
|
|
|
2018-07-30 13:04:27 +03:00
|
|
|
description: string;
|
2017-10-12 00:01:37 +03:00
|
|
|
termsOfService?: string;
|
|
|
|
contact?: OpenAPIContact;
|
|
|
|
license?: OpenAPILicense;
|
|
|
|
|
2018-07-17 12:17:06 +03:00
|
|
|
constructor(private parser: OpenAPIParser) {
|
2017-11-14 18:46:50 +03:00
|
|
|
Object.assign(this, parser.spec.info);
|
2018-07-30 13:04:27 +03:00
|
|
|
this.description = parser.spec.info.description || '';
|
|
|
|
this.description = this.description.substring(0, this.description.search(/^##?\s+/m));
|
2017-10-12 00:01:37 +03:00
|
|
|
}
|
|
|
|
|
2018-07-17 12:17:06 +03:00
|
|
|
get downloadLink(): string | undefined {
|
2018-03-07 18:21:17 +03:00
|
|
|
if (this.parser.specUrl) {
|
|
|
|
return this.parser.specUrl;
|
|
|
|
}
|
|
|
|
|
2018-07-17 12:17:06 +03:00
|
|
|
if (IS_BROWSER && window.Blob && window.URL && window.URL.createObjectURL) {
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|