cancel
Showing results for 
Search instead for 
Did you mean: 

Generate endpoint with parameter binding in C#

New Contributor

Generate endpoint with parameter binding in C#

Hello,

 

I currently have this OpenAPI yml:

 

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

requestBody:
        required: true
        content:
          application/json:
            schema:
              $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:

 

      x-bindBody:
        $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?

New Here?
Join us and watch the welcome video:
SeptemberNews
Join our online event
SeptemberHubBub
Top Kudoed Authors
Join the September Hub-bub to show off, learn and win