Skip to content

Commit 7c8b138

Browse files
committed
Added service interface for easy shorthands
1 parent f275f6c commit 7c8b138

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

src/WebApiToTypeScript/Endpoints/EndpointsService.cs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,13 @@ public void WriteEndpointClassToBlock(TypeScriptBlock endpointBlock, WebApiContr
4646
var controllerBlock = endpointBlock
4747
.AddAndUseBlock($"export {Config.NamespaceOrModuleName} {webApiController.Name}");
4848

49+
TypeScriptBlock serviceBlock = null;
50+
if (Config.GenerateService)
51+
{
52+
serviceBlock = controllerBlock
53+
.AddAndUseBlock($"export interface I{webApiController.Name}Service");
54+
}
55+
4956
var actions = webApiController.Actions;
5057

5158
foreach (var action in actions)
@@ -59,10 +66,16 @@ public void WriteEndpointClassToBlock(TypeScriptBlock endpointBlock, WebApiContr
5966

6067
WriteInterfaceToBlock(interfaceBlock, action);
6168

62-
var interfaceWithCallBlock = controllerBlock
63-
.AddAndUseBlock($"export interface I{actionName}WithCall extends I{actionName}, {IEndpoint}");
69+
if (Config.GenerateService)
70+
{
71+
var interfaceWithCallBlock = controllerBlock
72+
.AddAndUseBlock($"export interface I{actionName}WithCall extends I{actionName}, {IEndpoint}");
73+
74+
WriteInterfaceWithCallToBlock(interfaceWithCallBlock, action);
6475

65-
WriteInterfaceWithCallToBlock(interfaceWithCallBlock, action);
76+
serviceBlock
77+
.AddStatement($"{actionName}: (args?: I{actionName}) => I{actionName}WithCall");
78+
}
6679

6780
var classBlock = controllerBlock
6881
.AddAndUseBlock($"export class {actionName} implements I{actionName}, {IEndpoint}")

0 commit comments

Comments
 (0)