Azure / azure-functions-openapi-extension

This extension provides an Azure Functions app with Open API capability for better discoverability to consuming parties
https://www.nuget.org/packages/Microsoft.Azure.WebJobs.Extensions.OpenApi/
MIT License
367 stars 191 forks source link

System.Text.Json Support #154

Open justinyoo opened 3 years ago

justinyoo commented 3 years ago

Azure Functions v3 has a strong dependency on Newtonsoft.Json. For future proof, it should be decoupled from the runtime and support both System.Text.Json and Newtonsoft.Json on dev's choice, especially for .NET 5+ isolated worker environment.

pmeems commented 2 years ago

I agree. I use .NET6, Azure Functions v3 and OpenAPI v3 and I'm trying to remove the dependency on Newtonsoft.Json. I managed to change the deserialization of the body of the HttpTrigger, but I also use OpenApiExample and its Build method depends on Newtonsoft.Json.Serialization.NamingStrategy

justinyoo commented 2 years ago

@brennfoster It's a historical reason. That's why this issue is for - to give a choice to devs.

Skovvart commented 10 months ago

This is becoming increasingly important in isolated functions / preparation for the move to .NET 8. Forcing the worker configuration to depend on Newtonsoft is a huge hurdle when wanting to use use System.Text.Json everywhere else (HttpTrigger responses, cosmos serialization, etc.).

kylefossum commented 10 months ago

This is causing enormous headaches for us when trying to programmatically define Azure API Management operations for HTTP functions. It would be great if we could just generate an OpenAPI spec like we do for our .NET app services, but the JSON library mismatch blocks us from doing that. We have to either graphically import the Function definition from the APIM menu, or write some monstrosity of an az cli script to reproduce what the graphical import does under the hood. There's a good reason why declarative IAC is vastly preferred to procedural IAC and it would be ideal if we could just use Bicep everywhere as intended.

jassent commented 9 months ago

Would someone please help me understand the System.Text.Json support issue. My function works correctly with both serialization and deserialization using System.Text.Json. The SwaggerUI page also loads correctly. I am using NET8 with a function running in isolated/out-of-process mode.

My Program.cs includes this line: .ConfigureFunctionsWorkerDefaults()

Several iterations ago I was using this setup but no longer use it and don't find any problems:

.ConfigureFunctionsWorkerDefaults(worker =>
  {
    worker.UseNewtonsoftJson();
  })

NewtonsoftJson is only listed as a dependency of Microsoft.Azure.Functions.Worker.Extensions.OpenApi.

I was previously using Azure Functions with NewtonSoftJson but am now only using System.Text.Json.

I do have custom System.Text.Json.JsonSerializerOptions set with my preferred serializer options and custom converters. All seems to be working including DateTimeOffsets and Enums which require custom converters in System.Text.Json.

Long story short, what am I missing by not using worker.UseNewtonsoftJson?

Skovvart commented 8 months ago

Trying it out, you seem correct in that it is not actually a requirement that the plugin requires the host to .UseNewtonsoftJson(), which is great news. But really requiring that the supposed requirement is removed from documentation.

Long story short, what am I missing by not using worker.UseNewtonsoftJson?

It seems to me that the effect is that model-samples and openapi-schemas are presented incorrectly, particularly when customized.

For example, STJ's [JsonPropertyOrder(2), JsonPropertyName("SpecialCaseName"))] are not respected, instead using default NewtonsoftJson serialization, which is unfortunate (particularly JsonPropertyName, as generated clients etc. will get it wrong), but not a show-stopper like I previously expected.

lommez commented 2 months ago

Any news about that issue? Using System.Text.Json in a function using isolated worker environment is still not working. My function is using .Net 8.0 and Microsoft.Azure.Functions.Worker.Extensions.OpenApi version 1.5.1