Organize folder structure for generated typescript handlers #855
-
Hi, Is there a way to organize the handler code generated by the Smithy model into subfolders? The default setup places all the handlers in a single "src" folder, which can become difficult to manage with multiple resources in the Smithy model. If I manually move the files into separate folders, new handlers are automatically generated in the "src" and "test" folders on the next build. This is the current folder structure for handlers for 2 resource APIs (Groups, ShoppingLists)
Desired folder structure
Smithy model
Any suggestions would be helpful :) Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Hey Fahad! I'm afraid the To achieve your custom directory setup you have to do a little bit of customisation - what I'd recommend is something like:
new TypeSafeApiProject({
...
handlers: {
languages: [Language.TYPESCRIPT],
options: {
typescript: {
handlerEntryPoints: ['src/groups/*.ts*', 'src/shopping-lists/*.ts']
}
}
}
});
Hopefully that'll do the trick! :) I imagine it's fairly common to want to group handlers in subfolders especially as apis grow to larger numbers of operations - feel free to raise this as a feature request (or even better a PR 😄)! We could add eg a Thanks, |
Beta Was this translation helpful? Give feedback.
Hey Fahad!
I'm afraid the
@handler
trait in the Smithy model will always generate the handlers in the root of thesrc
folder.To achieve your custom directory setup you have to do a little bit of customisation - what I'd recommend is something like:
@handler
trait as normal when you add an operationpdk build
to generate the new handler and test, as well as the CDK lambda function construct@handler
trait from the operationpackages/api/generated/infrastructure/typescript/src/functions.ts
into your infrastructure package. Make sure you update the asset path to point to yourpa…