swagger-api / swagger-api/swagger-codegen
[ASPNETCORE] Generate partial controller with Impl method
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Dears
Please help me to find right direction to move further
I've get almost the same problem as was described in the #8875
If I generate c# controller once and implement some logic there, each new source generation (if new method is added for example) requires manual merge from the generated code to the current one.
I'm thinking can C# partial class definition be used to keep controller declaration away from the logic implemented. This may reduce manual work in case if openAPI yml definition file has been changed and controllers were generated again.
For example, controllers are generated like partial classes in the src\generated project folder but with modified method body:
public partial OrderController : Controller
{
public virtual IActionResult OrderGet([FromRoute][Required]int? oderId)
{
return OrderGetImpl(orderId);
}
}
Operator logic is implemented in the OderControllerImpl.cs controller in the src\Impl that is written manually.
This Impl file will not be overwritten by controller source code generator
It will have *Impl operations and (probably) constructor with dependency arguments:
public partial OrderController : Controller
{
read-only IExternalService service;
public OrderController(IExternalService service)
{
this.service = service;
}
public virtual IActionResult OrderGetImpl(int? oderId)
{
return service.GetOrder(orderId) ; // or something like that
}
}
Is it better to add partial class switch to the existing aspnetcore template processing or create a new template, like aspnetcorepartial ?
Regards
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing the existing aspnetcore template processing and the related issue #8875. Compare the generated controller structure under src\generated with the manually maintained implementation under src\Impl. Done would require a decided design for partial controllers or a new template, plus corresponding generator changes and tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- api, backend, tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100