fix: downloadDefinitionUrl instead of downloadFileName

This commit is contained in:
anastasiia-developer 2022-05-10 11:26:15 +03:00
parent f9f7ced497
commit cecb737c00
4 changed files with 13 additions and 8 deletions

View File

@ -212,7 +212,6 @@ You can use all of the following options with the standalone version of the <red
* `generatedPayloadSamplesMaxDepth` - set the maximum render depth for JSON payload samples (responses and request body). The default value is `10`.
* `maxDisplayedEnumValues` - display only specified number of enum values. hide rest values under spoiler.
* `hideDownloadButton` - do not show "Download" spec button. **THIS DOESN'T MAKE YOUR SPEC PRIVATE**, it just hides the button.
* `downloadFileName` - set a custom file name for the downloaded API definition file. The file is always in JSON format regardless of the file extension you set with this option. The default file name is `openapi.json`. **This option is supported only in redoc-cli**.
* `hideHostname` - if set, the protocol and hostname is not shown in the operation definition.
* `hideLoading` - do not show loading animation. Useful for small docs.
* `hideFab` - do not show FAB in mobile view. Useful for implementing a custom floating action button.

View File

@ -27,7 +27,7 @@ export interface RedocRawOptions {
untrustedSpec?: boolean | string;
hideLoading?: boolean | string;
hideDownloadButton?: boolean | string;
downloadFileName?: string;
downloadDefinitionUrl?: string;
disableSearch?: boolean | string;
onlyRequiredInSamples?: boolean | string;
showExtensions?: boolean | string | string[];
@ -226,7 +226,7 @@ export class RedocNormalizedOptions {
pathInMiddlePanel: boolean;
untrustedSpec: boolean;
hideDownloadButton: boolean;
downloadFileName: string;
downloadDefinitionUrl?: string;
disableSearch: boolean;
onlyRequiredInSamples: boolean;
showExtensions: boolean | string[];
@ -293,7 +293,7 @@ export class RedocNormalizedOptions {
this.pathInMiddlePanel = argValueToBoolean(raw.pathInMiddlePanel);
this.untrustedSpec = argValueToBoolean(raw.untrustedSpec);
this.hideDownloadButton = argValueToBoolean(raw.hideDownloadButton);
this.downloadFileName = raw.downloadFileName || 'openapi.json';
this.downloadDefinitionUrl = raw.downloadDefinitionUrl;
this.disableSearch = argValueToBoolean(raw.disableSearch);
this.onlyRequiredInSamples = argValueToBoolean(raw.onlyRequiredInSamples);
this.showExtensions = RedocNormalizedOptions.normalizeShowExtensions(raw.showExtensions);

View File

@ -83,9 +83,11 @@ describe('Models', () => {
},
} as any;
const opts = new RedocNormalizedOptions({ downloadFileName: 'filename.json' });
const opts = new RedocNormalizedOptions({
downloadDefinitionUrl: 'https:test.com/filename.yaml',
});
const info = new ApiInfoModel(parser, opts);
expect(info.downloadFileName).toEqual('filename.json');
expect(info.downloadFileName).toEqual(undefined);
});
});
});

View File

@ -34,6 +34,10 @@ export class ApiInfoModel implements OpenAPIInfo {
}
private getDownloadLink(): string | undefined {
if (this.options.downloadDefinitionUrl) {
return this.options.downloadDefinitionUrl;
}
if (this.parser.specUrl) {
return this.parser.specUrl;
}
@ -47,8 +51,8 @@ export class ApiInfoModel implements OpenAPIInfo {
}
private getDownloadFileName(): string | undefined {
if (!this.parser.specUrl) {
return this.options.downloadFileName;
if (!this.parser.specUrl && !this.options.downloadDefinitionUrl) {
return 'openapi.json';
}
return undefined;
}