mirror of
https://github.com/LukeHagar/redocly-cli.git
synced 2025-12-10 20:57:46 +00:00
fix: ignore case when inferring file extension from codeSample lang prop (#991)
This commit is contained in:
@@ -1,4 +1,10 @@
|
|||||||
import { getFallbackApisOrExit, isSubdir, pathToFilename, printConfigLintTotals } from '../utils';
|
import {
|
||||||
|
getFallbackApisOrExit,
|
||||||
|
isSubdir,
|
||||||
|
pathToFilename,
|
||||||
|
printConfigLintTotals,
|
||||||
|
langToExt,
|
||||||
|
} from '../utils';
|
||||||
import { ResolvedApi, Totals, isAbsoluteUrl } from '@redocly/openapi-core';
|
import { ResolvedApi, Totals, isAbsoluteUrl } from '@redocly/openapi-core';
|
||||||
import { red, yellow } from 'colorette';
|
import { red, yellow } from 'colorette';
|
||||||
import { existsSync } from 'fs';
|
import { existsSync } from 'fs';
|
||||||
@@ -236,3 +242,22 @@ describe('getFallbackApisOrExit', () => {
|
|||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('langToExt', () => {
|
||||||
|
it.each([
|
||||||
|
['php', '.php'],
|
||||||
|
['c#', '.cs'],
|
||||||
|
['shell', '.sh'],
|
||||||
|
['curl', '.sh'],
|
||||||
|
['bash', '.sh'],
|
||||||
|
['javascript', '.js'],
|
||||||
|
['js', '.js'],
|
||||||
|
['python', '.py'],
|
||||||
|
])('should infer file extension from lang - %s', (lang, expected) => {
|
||||||
|
expect(langToExt(lang)).toBe(expected);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should ignore case when inferring file extension', () => {
|
||||||
|
expect(langToExt('JavaScript')).toBe('.js');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import {
|
|||||||
writeYaml,
|
writeYaml,
|
||||||
exitWithError,
|
exitWithError,
|
||||||
escapeLanguageName,
|
escapeLanguageName,
|
||||||
|
langToExt,
|
||||||
} from '../../utils';
|
} from '../../utils';
|
||||||
import { isString, isObject, isEmptyObject } from '../../js-utils';
|
import { isString, isObject, isEmptyObject } from '../../js-utils';
|
||||||
import {
|
import {
|
||||||
@@ -106,20 +107,6 @@ function validateDefinitionFileName(fileName: string) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
function langToExt(lang: string) {
|
|
||||||
const langObj: any = {
|
|
||||||
php: '.php',
|
|
||||||
'c#': '.cs',
|
|
||||||
shell: '.sh',
|
|
||||||
curl: '.sh',
|
|
||||||
bash: '.sh',
|
|
||||||
javascript: '.js',
|
|
||||||
js: '.js',
|
|
||||||
python: '.py',
|
|
||||||
};
|
|
||||||
return langObj[lang];
|
|
||||||
}
|
|
||||||
|
|
||||||
function traverseDirectoryDeep(directory: string, callback: any, componentsFiles: object) {
|
function traverseDirectoryDeep(directory: string, callback: any, componentsFiles: object) {
|
||||||
if (!fs.existsSync(directory) || !fs.statSync(directory).isDirectory()) return;
|
if (!fs.existsSync(directory) || !fs.statSync(directory).isDirectory()) return;
|
||||||
const files = fs.readdirSync(directory);
|
const files = fs.readdirSync(directory);
|
||||||
|
|||||||
@@ -122,6 +122,20 @@ export function escapeLanguageName(lang: string) {
|
|||||||
return lang.replace(/#/g, '_sharp').replace(/\//, '_').replace(/\s/g, '');
|
return lang.replace(/#/g, '_sharp').replace(/\//, '_').replace(/\s/g, '');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function langToExt(lang: string) {
|
||||||
|
const langObj: any = {
|
||||||
|
php: '.php',
|
||||||
|
'c#': '.cs',
|
||||||
|
shell: '.sh',
|
||||||
|
curl: '.sh',
|
||||||
|
bash: '.sh',
|
||||||
|
javascript: '.js',
|
||||||
|
js: '.js',
|
||||||
|
python: '.py',
|
||||||
|
};
|
||||||
|
return langObj[lang.toLowerCase()];
|
||||||
|
}
|
||||||
|
|
||||||
export class CircularJSONNotSupportedError extends Error {
|
export class CircularJSONNotSupportedError extends Error {
|
||||||
constructor(public originalError: Error) {
|
constructor(public originalError: Error) {
|
||||||
super(originalError.message);
|
super(originalError.message);
|
||||||
|
|||||||
Reference in New Issue
Block a user