Skip to content

Commit

Permalink
OIC-60323: Handle valid file name
Browse files Browse the repository at this point in the history
  • Loading branch information
paullanoracle committed Aug 8, 2024
1 parent 8555ead commit fb0dea3
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/commands/compress-add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ import { firstValueFrom, switchMap } from 'rxjs';
import * as api from '../api';
import { fs } from '../utils';
import { SharedNs } from '../webview-shared-lib';
import { getAddName } from '../workspace-manager';
import { getAddDisplayNameAsFilename } from '../workspace-manager';
import { callApiAndShowADDDocument } from './add-operation-helper';

export const callADDCompressApiAndShowDocument = async (addFile: vscode.Uri, config?: SharedNs.WebviewCommandPayloadADDCompressRequests) => {
return callApiAndShowADDDocument(
{
operationName: `Compressing ${fs.parseFilename(addFile)}`,
newAddName: getAddName(addFile),
newAddName: getAddDisplayNameAsFilename(addFile),
apiCall: (file1, cfg) => api.conversion.compress(file1, cfg),
file1: addFile,
config,
Expand Down
2 changes: 1 addition & 1 deletion src/commands/convert-postman-collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const getPostmanCollectionName = (postmanFile: vscode.Uri) => getPostmanCollecti
map(postman => postman.info.name)
);
const getPostmanCollectionNameAsFileName = (postmanFile: vscode.Uri) => getPostmanCollectionName(postmanFile).pipe(
map(postmanCollectionName => fs.getFileNameFromPostmanCollectionName(postmanCollectionName))
map(postmanCollectionName => fs.getValidFileName(postmanCollectionName))
);

export const callPostmanConversionApiAndShowDocument = async (postmanFile: vscode.Uri, postmanConfig?: SharedNs.WebviewCommandPayloadPostmanSelectRequests, addFile?: vscode.Uri,) => {
Expand Down
6 changes: 3 additions & 3 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -468,12 +468,12 @@ export namespace fs {
);
};

export const getFileNameFromPostmanCollectionName = (name: string) => {
export const getValidFileName = (name: string) => {
return name.replace(/[^a-zA-Z0-9-. ]/g, '_');
};

export const getFileNameFromOpenAPIName = (name: string) => {
return getFileNameFromPostmanCollectionName(name);
return getValidFileName(name);
};

export const checkWorkspaceInitialized = () => from(isWorkSpaceInitialized())
Expand Down Expand Up @@ -510,7 +510,7 @@ export namespace fs {

export const ensureAddFile = (addFileName: string = '', defaultFileContent?: string) => {

addFileName = getFileNameFromPostmanCollectionName(addFileName);
addFileName = getValidFileName(addFileName);

let ws = getWorkspaceRoot() || '';

Expand Down
4 changes: 2 additions & 2 deletions src/workspace-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,10 +212,10 @@ export function getAddFile(fileName: string = "main", allowFallBack?: boolean, i

}

export function getAddName(addFile: vscode.Uri) {
export function getAddDisplayNameAsFilename(addFile: vscode.Uri) {
try {
const add = JSON.parse(fs.readFileSync(addFile.fsPath, 'utf8')) as RabAddNs.Root;
return add?.info?.displayName;
return fsUtils.getValidFileName(add?.info?.displayName ?? '');
} catch (error) {
log.error(`Unable to parse ADD ${addFile.fsPath}`);
return '';
Expand Down

0 comments on commit fb0dea3

Please sign in to comment.