azure-functions-openapi-extension
azure-functions-openapi-extension copied to clipboard
Providing different versions of endpoints
Could you please provide any information on how I can handle versioning with your extension? Unfortunately, I haven't found any examples or information about versioning in this repo.
Example: I have two version of one function
[Function("HttpTrigger_V1")]
public static HttpResponseData RunV1(
[HttpTrigger(AuthorizationLevel.Function, "get", Route = "v1/httpTrigger")]
HttpRequestData req,
FunctionContext executionContext)
{
var response = req.CreateResponse(HttpStatusCode.OK);
response.Headers.Add("Content-Type", "text/plain; charset=utf-8");
response.WriteString("Welcome to Azure Functions! v1 ");
return response;
}
[Function("HttpTrigger_V2")]
public static HttpResponseData RunV2(
[HttpTrigger(AuthorizationLevel.Function, "get", Route = "v2/httpTrigger")]
HttpRequestData req,
FunctionContext executionContext)
{
var response = req.CreateResponse(HttpStatusCode.OK);
response.Headers.Add("Content-Type", "text/plain; charset=utf-8");
response.WriteString("Welcome to Azure Functions! v2");
return response;
}
How can I document it in a proper way to see that this is exactly one function with different versions in swagger?
@ihordyrman Thanks for the issue. In your specific case, you might like to use the route template.
[Function("HttpTrigger")]
[OpenApixxxx(...)]
[OpenApiParameter(name: "version", Type = typeof(string), In = ParameterLocation.Path ...)]
public static HttpResponseData Run(
[HttpTrigger(AuthorizationLevel.Function, "get", Route = "{version}/httpTrigger")]
HttpRequestData req,
string version,
FunctionContext executionContext)
{
if (version == "v1")
{
// DO SOMETHING FOR V1
}
else if (version == "v2")
{
// DO SOMETHING FOR V2
}
}
HTH
@justinyoo thank you for your response. Unfortunately, this is not exactly what I want to achieve.
I'm looking for a way to create a dropdown with available versions in swagger UI.
I'm looking for this same functionality, as working with tags is not fully satisfying me.
+1 to this request. @justinyoo If we could configure multiple IOpenApiConfigurationOptions, that would be ideal. This is how tools like Swashbuckle handle multiple Swagger documents.
i'm also looking for a way to do this. @justinyoo is there a solution for this?
I'm looking for this as well. I created a SO question which shows my exact situation here. @justinyoo do you have any other suggestions/workarounds?
Hello @justinyoo. This seems like a nice functionality to have. I know that Azure Functions were not intended for this, but people started building full fledge APIs on top of this technology.
Do you foresee in the future the development of versioning functionality in this library, how do you feel about it and what are your opinions?
If you think that this would be nice to have, I may have a look and try to develop it so everybody can use it.
Best regards, Valentin! _
To be able to define multiple Document Definitions would definitely be a great feature. We use it for example (with Azure App Services) to automatically import the OpenApi Spec into Azure API Management during the CI/CD process. Since most bigger MicroServices have endpoints which are for public and private use. This is a great way to publish only the the endpoints which are intended for public use on the Azure API Management.
For the In-Process functions we had to use tags to achieve the same. But in my opinion I find it more elegant to use multiple Document Definitions instead of tags.
We would love to be able to split our documents into multiple "versions" (private/public or v1/v2) as we want to individually import these docs into our API management with API version sets as @Valem suggests.