From 8dbe938195770073a74d1b5be7cb106ee0b4769b Mon Sep 17 00:00:00 2001 From: Roman Hotsiy Date: Wed, 7 Mar 2018 17:21:17 +0200 Subject: [PATCH] feat: add hideDownloadButton option --- src/services/RedocNormalizedOptions.ts | 3 +++ src/services/SpecStore.ts | 2 +- src/services/models/ApiInfo.ts | 12 +++++++++--- src/theme.ts | 2 +- 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/services/RedocNormalizedOptions.ts b/src/services/RedocNormalizedOptions.ts index eceb1057..ccca10a9 100644 --- a/src/services/RedocNormalizedOptions.ts +++ b/src/services/RedocNormalizedOptions.ts @@ -13,6 +13,7 @@ export interface RedocRawOptions { pathInMiddlePanel?: boolean | string; untrustedSpec?: boolean | string; hideLoading?: boolean | string; + hideDownloadButton?: boolean | string; } function argValueToBoolean(val?: string | boolean): boolean { @@ -89,6 +90,7 @@ export class RedocNormalizedOptions { nativeScrollbars: boolean; pathInMiddlePanel: boolean; untrustedSpec: boolean; + hideDownloadButton: boolean; constructor(raw: RedocRawOptions) { this.theme = mergeObjects({} as any, defaultTheme, raw.theme || {}); @@ -100,5 +102,6 @@ export class RedocNormalizedOptions { this.nativeScrollbars = argValueToBoolean(raw.nativeScrollbars); this.pathInMiddlePanel = argValueToBoolean(raw.pathInMiddlePanel); this.untrustedSpec = argValueToBoolean(raw.untrustedSpec); + this.hideDownloadButton = argValueToBoolean(raw.hideDownloadButton); } } diff --git a/src/services/SpecStore.ts b/src/services/SpecStore.ts index cde6e274..0f6544fd 100644 --- a/src/services/SpecStore.ts +++ b/src/services/SpecStore.ts @@ -24,7 +24,7 @@ export class SpecStore { @computed get info(): ApiInfoModel { - return new ApiInfoModel(this.parser); + return new ApiInfoModel(this.parser, this.options); } @computed diff --git a/src/services/models/ApiInfo.ts b/src/services/models/ApiInfo.ts index 12f1e87c..3dfa102f 100644 --- a/src/services/models/ApiInfo.ts +++ b/src/services/models/ApiInfo.ts @@ -1,6 +1,7 @@ import { OpenAPIContact, OpenAPIInfo, OpenAPILicense } from '../../types'; import { isBrowser } from '../../utils/'; import { OpenAPIParser } from '../OpenAPIParser'; +import { RedocNormalizedOptions } from '../RedocNormalizedOptions'; export class ApiInfoModel implements OpenAPIInfo { title: string; @@ -11,12 +12,18 @@ export class ApiInfoModel implements OpenAPIInfo { contact?: OpenAPIContact; license?: OpenAPILicense; - constructor(public parser: OpenAPIParser) { + constructor(private parser: OpenAPIParser, private options: RedocNormalizedOptions) { Object.assign(this, parser.spec.info); } get downloadLink() { - if (!this.parser.specUrl && isBrowser && window.Blob && window.URL) { + if (this.options.hideDownloadButton) return undefined; + + if (this.parser.specUrl) { + return this.parser.specUrl; + } + + if (isBrowser && window.Blob && window.URL) { const blob = new Blob([JSON.stringify(this.parser.spec, null, 2)], { type: 'application/json', }); @@ -27,7 +34,6 @@ export class ApiInfoModel implements OpenAPIInfo { new Buffer(JSON.stringify(this.parser.spec, null, 2)).toString('base64') ); } - return this.parser.specUrl; } get downloadFileName(): string | undefined { diff --git a/src/theme.ts b/src/theme.ts index 72430c96..be449331 100644 --- a/src/theme.ts +++ b/src/theme.ts @@ -53,7 +53,7 @@ const theme = { backgroundColor: '#fafafa', }, logo: { - maxHeight: '120px', + maxHeight: '150px', }, rightPanel: { backgroundColor: '#263238',