NSwag
NSwag copied to clipboard
How to integrate NSwag with Azure Function Worker and Microsoft.Azure.Functions.Worker.Extensions.Http.AspNetCore
Hello,
I am working on a project that involves Microsoft.Azure.Functions.Worker
and Microsoft.Azure.Functions.Worker.Extensions.Http.AspNetCore
Right now I am using the NSwag studio to get the JSON specification from the link, but I would like to do it automatically when building in the Azure DevOps pipeline.
I would like to know if there would be a way to integrate NSwag
at build time with Azure Function Worker to generate .Net Clients.
Could you please share some guidance or resources on this topic? I appreciate your help.
Thank you.
To generate .Net client with NSwag you need OpenAPI definition file. For NSwag client generation it doesn't matter where that file comes from (azure function worker or anywhere else). So no special guidance is needed for client generation IMO.
To generate .Net client with NSwag you need OpenAPI definition file. For NSwag client generation it doesn't matter where that file comes from (azure function worker or anywhere else). So no special guidance is needed for client generation IMO.
Sorry, my first language is not english.
What I wanted to ask in the first place is:
I am trying to get the OpenApi/Swagger JSON specification file from the the Azure function at BUILD time.
Azure Function is using the Microsoft.Azure.Functions.Worker.Extensions.Http.AspNetCore
(which has the Asp.Net core request response types) integration with HttpTriggers
and Microsoft.Azure.Functions.Worker.Extensions.OpenApi
which has the OpenApi requried attributes.
Would it be possible?
Thanks again for your help.
It seems that Microsoft has a recommended solution for this: https://github.com/Azure/azure-functions-openapi-extension/blob/main/docs/generic-cicd-pipeline-support.md which involves running PowerShell or bash script in CI/CD pipeline. I don't think they are using NSwag library in functions' OpenAPI extension, so I doubt you could use NSwag there...
It seems that Microsoft has a recommended solution for this: https://github.com/Azure/azure-functions-openapi-extension/blob/main/docs/generic-cicd-pipeline-support.md which involves running PowerShell or bash script in CI/CD pipeline. I don't think they are using NSwag library in functions' OpenAPI extension, so I doubt you could use NSwag there...
We are using that script, but if you are using any of the following Triggers ServiceBus, EventGrid, or EventHub, you'll have to disable them somehow when running in CI/CD Pipeline and sometimes it will time out because the AzureFunction takes a bit of time to do the initialization, even if you increase the time it will still time out some times.
Anyway, thank you for your time.