diff --git a/README.md b/README.md index f2efc98e..134107b3 100644 --- a/README.md +++ b/README.md @@ -232,7 +232,7 @@ You can use all of the following options with standalone version on tag * `expandResponses` - specify which responses to expand by default by response codes. Values should be passed as comma-separated list without spaces e.g. `expandResponses="200,201"`. Special value `"all"` expands all responses by default. Be careful: this option can slow-down documentation rendering time. * `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 file name and format of downloaded spec file, e.g. `openapi.yaml`, default `swagger.json`. +* `downloadFileName` - set file name of downloaded spec file, e.g. `swagger.json`, default `openapi.json`. Spec file in `JSON` format. (only `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. * `hideSchemaPattern` - if set, the pattern is not shown in the schema. diff --git a/src/services/RedocNormalizedOptions.ts b/src/services/RedocNormalizedOptions.ts index a143eb6e..918a8cb7 100644 --- a/src/services/RedocNormalizedOptions.ts +++ b/src/services/RedocNormalizedOptions.ts @@ -1,4 +1,3 @@ -import * as path from 'path'; import defaultTheme, { ResolvedThemeInterface, resolveTheme, ThemeInterface } from '../theme'; import { querySelector } from '../utils/dom'; import { isNumeric, mergeObjects } from '../utils/helpers'; @@ -155,20 +154,6 @@ export class RedocNormalizedOptions { return 0; } - static normalizeDownloadFileName(value: RedocRawOptions['downloadFileName']): string { - if (value) { - const extname = path.extname(value); - if (extname === '.json' || extname === '.yaml') { - return value; - } else { - console.warn(`downloadFileName must be a JSON or YAML file.`); - } - } - - // Default value - return 'openapi.json'; - } - private static normalizeJsonSampleExpandLevel(level?: number | string | 'all'): number { if (level === 'all') { return +Infinity; @@ -249,7 +234,7 @@ export class RedocNormalizedOptions { this.pathInMiddlePanel = argValueToBoolean(raw.pathInMiddlePanel); this.untrustedSpec = argValueToBoolean(raw.untrustedSpec); this.hideDownloadButton = argValueToBoolean(raw.hideDownloadButton); - this.downloadFileName = RedocNormalizedOptions.normalizeDownloadFileName(raw.downloadFileName); + this.downloadFileName = raw.downloadFileName || 'openapi.json'; this.disableSearch = argValueToBoolean(raw.disableSearch); this.onlyRequiredInSamples = argValueToBoolean(raw.onlyRequiredInSamples); this.showExtensions = RedocNormalizedOptions.normalizeShowExtensions(raw.showExtensions); diff --git a/src/services/__tests__/models/ApiInfo.test.ts b/src/services/__tests__/models/ApiInfo.test.ts index b02527da..85390067 100644 --- a/src/services/__tests__/models/ApiInfo.test.ts +++ b/src/services/__tests__/models/ApiInfo.test.ts @@ -72,7 +72,7 @@ describe('Models', () => { } as any; const info = new ApiInfoModel(parser); - expect(info.downloadFileName).toEqual('swagger.json'); + expect(info.downloadFileName).toEqual('openapi.json'); }); test('should correctly populate download file name', () => { @@ -83,22 +83,9 @@ describe('Models', () => { }, } as any; - const opts = new RedocNormalizedOptions({ downloadFileName: 'openapi.yaml' }); + const opts = new RedocNormalizedOptions({ downloadFileName: 'filename.json' }); const info = new ApiInfoModel(parser, opts); - expect(info.downloadFileName).toEqual('openapi.yaml'); - }); - - test('should correctly populate default download file name if invalid extension is used', () => { - parser.spec = { - openapi: '3.0.0', - info: { - description: 'Test description', - }, - } as any; - - const opts = new RedocNormalizedOptions({ downloadFileName: 'nope.txt' }); - const info = new ApiInfoModel(parser, opts); - expect(info.downloadFileName).toEqual('swagger.json'); + expect(info.downloadFileName).toEqual('filename.json'); }); }); }); diff --git a/src/services/models/ApiInfo.ts b/src/services/models/ApiInfo.ts index d7b9e436..e9172443 100644 --- a/src/services/models/ApiInfo.ts +++ b/src/services/models/ApiInfo.ts @@ -1,5 +1,3 @@ -import * as path from 'path'; -import * as yaml from 'js-yaml'; import { OpenAPIContact, OpenAPIInfo, OpenAPILicense } from '../../types'; import { IS_BROWSER } from '../../utils/'; import { OpenAPIParser } from '../OpenAPIParser'; @@ -41,13 +39,7 @@ export class ApiInfoModel implements OpenAPIInfo { } if (IS_BROWSER && window.Blob && window.URL && window.URL.createObjectURL) { - let specString: string; - if (path.extname(this.options.downloadFileName) === '.yaml') { - specString = yaml.dump(this.parser.spec); - } else { - specString = JSON.stringify(this.parser.spec, null, 2); - } - const blob = new Blob([specString], { + const blob = new Blob([JSON.stringify(this.parser.spec, null, 2)], { type: 'application/json', }); return window.URL.createObjectURL(blob);