mirror of
https://github.com/Redocly/redoc.git
synced 2025-08-05 12:50:18 +03:00
feat: downloadFileName
This commit is contained in:
parent
6995a8e4b7
commit
d0b1309aee
|
@ -212,6 +212,7 @@ 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.
|
||||
* `downloadDefinitionUrl` - If the 'Download' button is visible in the API reference documentation (hideDownloadButton=false), the URL configured here will open when that button is selected. Provide it as an absolute URL with the full URI scheme.
|
||||
* `hideHostname` - if set, the protocol and hostname is not shown in the operation definition.
|
||||
* `hideLoading` - do not show loading animation. Useful for small docs.
|
||||
|
|
|
@ -75,6 +75,7 @@ exports[`Components SchemaView discriminator should correctly render SchemaView
|
|||
"allowedMdComponents": Object {},
|
||||
"disableSearch": false,
|
||||
"downloadDefinitionUrl": undefined,
|
||||
"downloadFileName": undefined,
|
||||
"enumSkipQuotes": false,
|
||||
"expandDefaultServerVariables": false,
|
||||
"expandResponses": Object {},
|
||||
|
@ -326,6 +327,7 @@ exports[`Components SchemaView discriminator should correctly render SchemaView
|
|||
"allowedMdComponents": Object {},
|
||||
"disableSearch": false,
|
||||
"downloadDefinitionUrl": undefined,
|
||||
"downloadFileName": undefined,
|
||||
"enumSkipQuotes": false,
|
||||
"expandDefaultServerVariables": false,
|
||||
"expandResponses": Object {},
|
||||
|
@ -553,6 +555,7 @@ exports[`Components SchemaView discriminator should correctly render SchemaView
|
|||
"allowedMdComponents": Object {},
|
||||
"disableSearch": false,
|
||||
"downloadDefinitionUrl": undefined,
|
||||
"downloadFileName": undefined,
|
||||
"enumSkipQuotes": false,
|
||||
"expandDefaultServerVariables": false,
|
||||
"expandResponses": Object {},
|
||||
|
@ -845,6 +848,7 @@ exports[`Components SchemaView discriminator should correctly render SchemaView
|
|||
"allowedMdComponents": Object {},
|
||||
"disableSearch": false,
|
||||
"downloadDefinitionUrl": undefined,
|
||||
"downloadFileName": undefined,
|
||||
"enumSkipQuotes": false,
|
||||
"expandDefaultServerVariables": false,
|
||||
"expandResponses": Object {},
|
||||
|
@ -1096,6 +1100,7 @@ exports[`Components SchemaView discriminator should correctly render SchemaView
|
|||
"allowedMdComponents": Object {},
|
||||
"disableSearch": false,
|
||||
"downloadDefinitionUrl": undefined,
|
||||
"downloadFileName": undefined,
|
||||
"enumSkipQuotes": false,
|
||||
"expandDefaultServerVariables": false,
|
||||
"expandResponses": Object {},
|
||||
|
@ -1323,6 +1328,7 @@ exports[`Components SchemaView discriminator should correctly render SchemaView
|
|||
"allowedMdComponents": Object {},
|
||||
"disableSearch": false,
|
||||
"downloadDefinitionUrl": undefined,
|
||||
"downloadFileName": undefined,
|
||||
"enumSkipQuotes": false,
|
||||
"expandDefaultServerVariables": false,
|
||||
"expandResponses": Object {},
|
||||
|
@ -1573,6 +1579,7 @@ exports[`Components SchemaView discriminator should correctly render SchemaView
|
|||
"allowedMdComponents": Object {},
|
||||
"disableSearch": false,
|
||||
"downloadDefinitionUrl": undefined,
|
||||
"downloadFileName": undefined,
|
||||
"enumSkipQuotes": false,
|
||||
"expandDefaultServerVariables": false,
|
||||
"expandResponses": Object {},
|
||||
|
@ -1862,6 +1869,7 @@ exports[`Components SchemaView discriminator should correctly render SchemaView
|
|||
"allowedMdComponents": Object {},
|
||||
"disableSearch": false,
|
||||
"downloadDefinitionUrl": undefined,
|
||||
"downloadFileName": undefined,
|
||||
"enumSkipQuotes": false,
|
||||
"expandDefaultServerVariables": false,
|
||||
"expandResponses": Object {},
|
||||
|
@ -2113,6 +2121,7 @@ exports[`Components SchemaView discriminator should correctly render SchemaView
|
|||
"allowedMdComponents": Object {},
|
||||
"disableSearch": false,
|
||||
"downloadDefinitionUrl": undefined,
|
||||
"downloadFileName": undefined,
|
||||
"enumSkipQuotes": false,
|
||||
"expandDefaultServerVariables": false,
|
||||
"expandResponses": Object {},
|
||||
|
@ -2340,6 +2349,7 @@ exports[`Components SchemaView discriminator should correctly render SchemaView
|
|||
"allowedMdComponents": Object {},
|
||||
"disableSearch": false,
|
||||
"downloadDefinitionUrl": undefined,
|
||||
"downloadFileName": undefined,
|
||||
"enumSkipQuotes": false,
|
||||
"expandDefaultServerVariables": false,
|
||||
"expandResponses": Object {},
|
||||
|
|
|
@ -27,6 +27,7 @@ export interface RedocRawOptions {
|
|||
untrustedSpec?: boolean | string;
|
||||
hideLoading?: boolean | string;
|
||||
hideDownloadButton?: boolean | string;
|
||||
downloadFileName?: string;
|
||||
downloadDefinitionUrl?: string;
|
||||
disableSearch?: boolean | string;
|
||||
onlyRequiredInSamples?: boolean | string;
|
||||
|
@ -226,6 +227,7 @@ export class RedocNormalizedOptions {
|
|||
pathInMiddlePanel: boolean;
|
||||
untrustedSpec: boolean;
|
||||
hideDownloadButton: boolean;
|
||||
downloadFileName?: string;
|
||||
downloadDefinitionUrl?: string;
|
||||
disableSearch: boolean;
|
||||
onlyRequiredInSamples: boolean;
|
||||
|
@ -293,6 +295,7 @@ export class RedocNormalizedOptions {
|
|||
this.pathInMiddlePanel = argValueToBoolean(raw.pathInMiddlePanel);
|
||||
this.untrustedSpec = argValueToBoolean(raw.untrustedSpec);
|
||||
this.hideDownloadButton = argValueToBoolean(raw.hideDownloadButton);
|
||||
this.downloadFileName = raw.downloadFileName;
|
||||
this.downloadDefinitionUrl = raw.downloadDefinitionUrl;
|
||||
this.disableSearch = argValueToBoolean(raw.disableSearch);
|
||||
this.onlyRequiredInSamples = argValueToBoolean(raw.onlyRequiredInSamples);
|
||||
|
|
|
@ -75,7 +75,38 @@ describe('Models', () => {
|
|||
expect(info.downloadFileName).toEqual('openapi.json');
|
||||
});
|
||||
|
||||
test('should correctly populate default download file is undefined when using specUrl', () => {
|
||||
parser = new OpenAPIParser(
|
||||
{
|
||||
openapi: '3.0.0',
|
||||
info: {
|
||||
description: 'Test description',
|
||||
},
|
||||
} as any,
|
||||
'/demo/openapi.yaml',
|
||||
opts,
|
||||
);
|
||||
|
||||
const info = new ApiInfoModel(parser);
|
||||
expect(info.downloadFileName).toEqual(undefined);
|
||||
});
|
||||
|
||||
test('should correctly populate download file name', () => {
|
||||
parser.spec = {
|
||||
info: {
|
||||
description: 'Test description',
|
||||
},
|
||||
} as any;
|
||||
|
||||
const opts = new RedocNormalizedOptions({
|
||||
downloadFileName: 'test.yaml',
|
||||
});
|
||||
|
||||
const info = new ApiInfoModel(parser, opts);
|
||||
expect(info.downloadFileName).toEqual('test.yaml');
|
||||
});
|
||||
|
||||
test('should correctly populate download link', () => {
|
||||
parser.spec = {
|
||||
openapi: '3.0.0',
|
||||
info: {
|
||||
|
@ -87,7 +118,24 @@ describe('Models', () => {
|
|||
downloadDefinitionUrl: 'https:test.com/filename.yaml',
|
||||
});
|
||||
const info = new ApiInfoModel(parser, opts);
|
||||
expect(info.downloadFileName).toEqual(undefined);
|
||||
expect(info.downloadLink).toEqual('https:test.com/filename.yaml');
|
||||
});
|
||||
|
||||
test('should correctly populate download link and download file name', () => {
|
||||
parser.spec = {
|
||||
openapi: '3.0.0',
|
||||
info: {
|
||||
description: 'Test description',
|
||||
},
|
||||
} as any;
|
||||
|
||||
const opts = new RedocNormalizedOptions({
|
||||
downloadDefinitionUrl: 'https:test.com/filename.yaml',
|
||||
downloadFileName: 'test.yaml',
|
||||
});
|
||||
const info = new ApiInfoModel(parser, opts);
|
||||
expect(info.downloadLink).toEqual('https:test.com/filename.yaml');
|
||||
expect(info.downloadFileName).toEqual('test.yaml');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -52,8 +52,8 @@ export class ApiInfoModel implements OpenAPIInfo {
|
|||
|
||||
private getDownloadFileName(): string | undefined {
|
||||
if (!this.parser.specUrl && !this.options.downloadDefinitionUrl) {
|
||||
return 'openapi.json';
|
||||
return this.options.downloadFileName || 'openapi.json';
|
||||
}
|
||||
return undefined;
|
||||
return this.options.downloadFileName;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user