feat: configurable filename separator for split command (#610)

* Make file path separator configurable in split command

* chore: add tests for the file name separator

* chore: update snapshots

* docs: split separator option description

* chore: code style fixes
This commit is contained in:
volodymyr-rutskyi
2022-03-28 18:44:43 +03:00
committed by GitHub
parent 3e8b08449d
commit 1f10c7cd77
9 changed files with 54 additions and 15 deletions

View File

@@ -28,6 +28,7 @@ describe('#split', () => {
{
entrypoint: filePath,
outDir: openapiDir,
separator: '_',
}
);
@@ -41,12 +42,31 @@ describe('#split', () => {
);
});
it('should use the correct separator', async () => {
const filePath = "./packages/cli/src/commands/split/__tests__/fixtures/spec.json";
const utils = require('../../../utils');
jest.spyOn(utils, 'pathToFilename').mockImplementation(() => 'newFilePath');
await handleSplit (
{
entrypoint: filePath,
outDir: openapiDir,
separator: '_',
}
);
expect(utils.pathToFilename).toBeCalledWith(expect.anything(), '_');
utils.pathToFilename.mockRestore();
});
it('should have correct path with paths', () => {
const openapi = require("./fixtures/spec.json");
jest.spyOn(openapiCore, 'slash').mockImplementation(() => 'paths/test.yaml');
jest.spyOn(path, 'relative').mockImplementation(() => 'paths/test.yaml');
iteratePathItems(openapi.paths, openapiDir, path.join(openapiDir, 'paths'), componentsFiles);
iteratePathItems(openapi.paths, openapiDir, path.join(openapiDir, 'paths'), componentsFiles, '_');
expect(openapiCore.slash).toHaveBeenCalledWith('paths/test.yaml');
expect(path.relative).toHaveBeenCalledWith('test', 'test/paths/test.yaml');