azure-functions-openapi-extension icon indicating copy to clipboard operation
azure-functions-openapi-extension copied to clipboard

Providing different versions of endpoints

Open ihordyrman opened this issue 2 years ago • 9 comments

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 avatar Apr 04 '22 05:04 ihordyrman

@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 avatar Apr 05 '22 13:04 justinyoo

@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. image

ihordyrman avatar Apr 05 '22 16:04 ihordyrman

I'm looking for this same functionality, as working with tags is not fully satisfying me.

vgool avatar Dec 20 '22 14:12 vgool

+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.

VultureJD avatar Jan 17 '23 22:01 VultureJD

i'm also looking for a way to do this. @justinyoo is there a solution for this?

adeliab avatar Jan 30 '23 13:01 adeliab

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?

MattNewbill avatar Jun 29 '23 19:06 MattNewbill

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! _

Valkozaur avatar Aug 23 '23 14:08 Valkozaur

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.

image

Valem avatar Sep 20 '23 08:09 Valem

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.

Joeghanoe avatar Oct 04 '23 12:10 Joeghanoe