redoc/src/services/models/ApiInfo.ts

35 lines
948 B
TypeScript
Raw Normal View History

2017-10-12 00:01:37 +03:00
import { OpenAPIContact, OpenAPIInfo, OpenAPILicense } from '../../types';
import { OpenAPIParser } from '../OpenAPIParser';
import { isBrowser } from '../../utils/';
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) {
Object.assign(this, parser.spec.info);
2017-10-12 00:01:37 +03:00
}
get downloadLink() {
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);
}
return this.parser.specUrl;
}
get downloadFileName(): string | undefined {
if (!this.parser.specUrl && isBrowser && window.Blob && window.URL) {
2017-10-12 00:01:37 +03:00
return 'swagger.json';
}
return undefined;
}
}