Jusas / NSwag.AzureFunctionsV2

NSwag for Azure Functions
MIT License
20 stars 5 forks source link

Function with POST trigger and POST body model does not show up #6

Closed RicoSuter closed 5 years ago

RicoSuter commented 5 years ago

This function

[FunctionName("PostWebhookAsync")]
[SwaggerResponse(200, typeof(WebhookResponse), Description = "OK result")]
public async Task<IActionResult> PostWebhookAsync(
    [HttpTrigger(AuthorizationLevel.Function, "post", Route = "tenants/{tenantId}/webhooks")] WebhookBodyRequest request,
    [NotNull]string tenantId, ILogger log)
{

does not show up in the spec.

If i change WebhookBodyRequest request to HttpRequest request then it shows up. Am I missing something?

Jusas commented 5 years ago

Yeah, that's because currently the discovery works by first trying to search for a parameter with the type HttpRequest and if it finds it, proceeds to get the trigger attribute from it:

            var httpRequestParameter = method.GetParameters()
                .SingleOrDefault(x => x.ParameterType.Name == "HttpRequest");
            var httpTriggerAttribute = httpRequestParameter?.GetCustomAttributes()
                .SingleOrDefault(x => x.GetType().Name == "HttpTriggerAttribute");

The main thing discovery wise is to find the HttpTriggerAttribute, and I suppose we could just check for any parameter having that attribute as that's mostly what matters.

RicoSuter commented 5 years ago

Ok, so there is currently no workaround or way to use this function at the moment?

Jusas commented 5 years ago

I'm afraid not, until a change to the discovery method is made.

Jusas commented 5 years ago

Fixing this as we speak. If you don't mind me asking, what's the use case? I haven't realized you could use something else than the HttpRequest in the signature.

RicoSuter commented 5 years ago

If you use an own class instead of HttpRequest for a POST function it will deserialize the JSON body to this class...

Jusas commented 5 years ago

Alright, the issue should now have been fixed and v1.1.3 should be available from Nuget momentarily.

RicoSuter commented 5 years ago

Thank you very much. Ill try it out tomorrow.

RicoSuter commented 5 years ago

Looks good now. Thank you.