Skip to content

Commit

Permalink
feat: add hideDownloadButton option
Browse files Browse the repository at this point in the history
  • Loading branch information
RomanHotsiy committed Mar 7, 2018
1 parent 0658b8e commit 8dbe938
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
3 changes: 3 additions & 0 deletions src/services/RedocNormalizedOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 || {});
Expand All @@ -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);
}
}
2 changes: 1 addition & 1 deletion src/services/SpecStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export class SpecStore {

@computed
get info(): ApiInfoModel {
return new ApiInfoModel(this.parser);
return new ApiInfoModel(this.parser, this.options);
}

@computed
Expand Down
12 changes: 9 additions & 3 deletions src/services/models/ApiInfo.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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',
});
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const theme = {
backgroundColor: '#fafafa',
},
logo: {
maxHeight: '120px',
maxHeight: '150px',
},
rightPanel: {
backgroundColor: '#263238',
Expand Down

1 comment on commit 8dbe938

@CesarLanderos
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<3

Please sign in to comment.