Skip to content

Commit

Permalink
fix: extend object literal expr for ctrl methods
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilmysliwiec committed Jun 5, 2023
1 parent a2470d6 commit 982922c
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions lib/plugin/visitors/controller-class.visitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,19 @@ export class ControllerClassVisitor extends AbstractFileVisitor {
factory.createNodeArray([objectLiteralExpr]);

const methodKey = node.name.getText();
metadata[methodKey] = objectLiteralExpr;
if (metadata[methodKey]) {
const existingObjectLiteralExpr = metadata[methodKey];
const existingProperties = existingObjectLiteralExpr.properties;
const updatedProperties = factory.createNodeArray([
...existingProperties,
...compact(properties)
]);
const updatedObjectLiteralExpr =
factory.createObjectLiteralExpression(updatedProperties);
metadata[methodKey] = updatedObjectLiteralExpr;
} else {
metadata[methodKey] = objectLiteralExpr;
}

if (apiOperationDecorator) {
const expr = apiOperationDecorator.expression as any as ts.CallExpression;
Expand Down Expand Up @@ -285,10 +297,14 @@ export class ControllerClassVisitor extends AbstractFileVisitor {
const methodKey = node.name.getText();
const existingExprOrUndefined = metadata[methodKey];
if (existingExprOrUndefined) {
factory.updateObjectLiteralExpression(objectLiteralExpr, [
...existingExprOrUndefined.properties,
...objectLiteralExpr.properties
const existingProperties = existingExprOrUndefined.properties;
const updatedProperties = factory.createNodeArray([
...existingProperties,
...compact(properties)
]);
const updatedObjectLiteralExpr =
factory.createObjectLiteralExpression(updatedProperties);
metadata[methodKey] = updatedObjectLiteralExpr;
} else {
metadata[methodKey] = objectLiteralExpr;
}
Expand Down

0 comments on commit 982922c

Please sign in to comment.