Skip to content
This repository has been archived by the owner on Sep 3, 2022. It is now read-only.

Commit

Permalink
fix: remove naming conflicts for index.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
baetheus committed Jul 29, 2019
1 parent b9dd3a5 commit 9ab5292
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions src/printers/typescript/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,17 +247,13 @@ const toRequestTypeDeclaration = (
}

return t.typeDeclaration(
operation.name + 'Request',
operation.name + 'Req',
t.typeCombinator(requestProperties),
true
);
};
const toResponseTypeDeclaration = (operation: Operation): t.TypeDeclaration => {
return t.typeDeclaration(
operation.name + 'Response',
operation.response,
true
);
return t.typeDeclaration(operation.name + 'Res', operation.response, true);
};

const getFile = (
Expand All @@ -266,14 +262,16 @@ const getFile = (
content: string
): File => toFile(path.join(C.dst, name), content);

const printControllerReader = (
const printControllerFactory = (
{ name, method, key }: Operation,
responeType: t.TypeDeclaration,
requestType?: t.TypeDeclaration
): string => {
const resName = responeType.name;
if (requestType) {
return `export const ${name}Reader = u.controllerFactory<${requestType.name}, ${name}Response>(${name}Response, '${method}', '${key}')`;
return `export const ${name}Factory = u.controllerFactory<${requestType.name}, ${resName}>(${resName}, '${method}', '${key}')`;
}
return `export const ${name}Reader = u.requestlessControllerFactory<${name}Response>(${name}Response, '${method}', '${key}')`;
return `export const ${name}Factory = u.requestlessControllerFactory<${resName}>(${resName}, '${method}', '${key}')`;
};

const printOperationDescription = (operation: Operation): string => {
Expand All @@ -298,7 +296,13 @@ const printOperation = (operation: Operation): string => {
output.push(responseRuntime);
output.push('');
output.push(operationDescription);
output.push(printControllerReader(operation, requestTypeDeclaration));
output.push(
printControllerFactory(
operation,
responseTypeDeclaration,
requestTypeDeclaration
)
);

return output.join('\n');
};
Expand Down

0 comments on commit 9ab5292

Please sign in to comment.