vitalybibikov / AzureExtensions.Swashbuckle

This extension enriches Azure Functions with Swagger/ Open API support
https://www.linkedin.com/in/vitali-bibikov/
MIT License
68 stars 54 forks source link

Add support for Newtonsoft.Json in Swashbuckle #108

Closed jfjalburquerque closed 7 months ago

jfjalburquerque commented 9 months ago

This pull request enhances Swashbuckle to support Newtonsoft.Json library for Azure Functions. Currently, Swashbuckle does not recognize JsonProperty annotations in models. With this update, Swashbuckle now properly handles models annotated with JsonProperty.

Additionally, this update introduces a new feature to enable or disable Newtonsoft.Json support during Swashbuckle initialization in Azure Functions Startup. By setting the AddNewtonsoftSupport property to true, developers can activate support for Newtonsoft.Json. By default, Newtonsoft is disabled.

Example usage:

builder.AddSwashBuckle(Assembly.GetExecutingAssembly(), opts =>
{
    opts.SpecVersion = OpenApiSpecVersion.OpenApi3_0;
    opts.AddCodeParameter = true;
    opts.PrependOperationWithRoutePrefix = true;

    // Enable Newtonsoft.Json support
    opts.AddNewtonsoftSupport = true;

    opts.Title = "Testing api";
    opts.ConfigureSwaggerGen = (x =>
    {
        x.CustomOperationIds(apiDesc =>
        {
            return apiDesc.TryGetMethodInfo(out MethodInfo methodInfo)
                ? methodInfo.Name
                : Guid.NewGuid().ToString();
        });
    });
});

This update provides more flexibility and compatibility for developers working with Azure Functions and Swashbuckle, ensuring seamless integration with Newtonsoft.Json serialization.

jfjalburquerque commented 9 months ago

Issue associated: https://github.com/vitalybibikov/AzureExtensions.Swashbuckle/issues/74