[Question]: Controller & Service file naming convention
epiphanizer opened this issue · comments
Migrating from Swagger 2.* to OpenAPI, and I am wondering... is there not a way to keep my file names for Controllers & Services? The naming convention was much better in Swagger IMO...
For example, for a path /account/{accountId}/client/{clientId}/contacts, I could priorly have it just route to a AccountsContoller.js file... When working with oas-tools, it generated something hideous like
/generated-server/controllers/accountaccountIdclientclientIdcontactsController.js for the path.
Ideally I'd like to have multiple paths pertaining to "accounts" just live in one controller, rather than individual controllers for each path. Is this possible? Seems like it should be.
If I have to use that convention, I will have to redo all my pathing in addition to copy+pasting in the old controller code.
For illustration's sake, I've attached what I want my folder to look like, vs. what oas-tools generated.
Any suggestions?
Yes, there is a way to give custom names to your files. You just need to declare the x-router-controller
field in the OAS document, as explained here in the docs.
Also, if you declare the x-router-controller
for more than one path/operation, the framework will look for functions that match the operationId
inside the controller file.
Thank you for this @alesancor1! My old spec still had x-swagger-router-controller in it, thus oasTools was not operating as I hoped / expected.