Forum Discussion

ramjet69's avatar
New Contributor
5 years ago

Generate endpoint with parameter binding in C#



I currently have this OpenAPI yml:


...snipped from an endpoint description....

        required: true
              $ref: '#/components/schemas/SubmitRequest'


this moustache:


public async Task<{{returnType}}> {{operationId}}({{#allParams}}{{>pathParam}}{{>queryParam}}{{>bodyParam}}{{#isPathParam}}{{#hasMore}},{{/hasMore}}{{/isPathParam}}{{^isPathParam}}{{#isQueryParam}}{{#hasMore}}, {{/hasMore}}{{/isQueryParam}}{{^isQueryParam}}{{#isBodyParam}}{{#hasMore}}, {{/hasMore}}{{/isBodyParam}}{{/isQueryParam}}{{/isPathParam}}{{/allParams}})


and it generates this endpoint:


 public async Task<ObjA> Post([FromBody]SubmitRequest submitRequest)



What I need is to add the C# Bind keyword so it looks like this:


 public async Task<ObjA> Post([FromBody,Bind]SubmitRequest submitRequest)



Reading here I see no way to do it with a yml directive.


I've tried some moustache trickery with vendor extensions but documentation on moustache is very sparse and I'm not sure if I am doing something wrong or it just can't be done.


If I do this in the YML:


        $ref: '#/components/schemas/SubmitRequest'

and this in moustache



public async Task<{{returnType}}> {{operationId}}({{#vendorExtensions.x-bindBody}}[FromBody,Bind]{{/vendorExtensions.x-bindBody}})

this is what I get....very close but not quite there.


public async Task<ObjA> Post([FromBody,Bind])


Any ideas?

No RepliesBe the first to reply