diff --git a/README.md b/README.md index f8db285f..f33ed231 100644 --- a/README.md +++ b/README.md @@ -212,6 +212,7 @@ You can use all of the following options with the standalone version of the { 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'); }); }); }); diff --git a/src/services/models/ApiInfo.ts b/src/services/models/ApiInfo.ts index b5d71802..0c4d91eb 100644 --- a/src/services/models/ApiInfo.ts +++ b/src/services/models/ApiInfo.ts @@ -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; } }