-
Notifications
You must be signed in to change notification settings - Fork 10.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support F# option type in OpenApi schema generator #59528
Comments
@Lanayx Thanks for filing this issue! The OpenAPI implementation uses System.Text.Json's schema generation under the hood which follow's STJ's serialization semantics. To that end, I think your issue might be related to dotnet/runtime#55744. Baring official support for F# DUs in STJ, I think having the dotnet/runtime#105769 API implemented might also help get the desired behavior here. Let me know if this assessment makes sense to you! For now, I'll stick this in the backlog. I'm hoping there will be progress on the STJ end here to make things a little easier. |
@captainsafia Thanks for answering, but I don't want to generalize it to any DU at this point (untill STJ supports them). But as long as STJ supports fsharp options and value options, I'd expect them to be supported in OpenApi as well. I think it should be special cased just as NRT https://github.com/dotnet/aspnetcore/blob/main/src/OpenApi/src/Services/OpenApiGenerator.cs#L308 |
@Lanayx Have you experimented with using schema transformers to see if you can achieve the desired behavior? See these docs. |
Thanks, I'll have a look. Still, if I manage to add the right transformer, this will fix the issue for Oxpecker, but not for any other F#-based generation. |
@Lanayx Correct! If there's interest in the issue, the transformer implementation can serve as the basis for something we'd include by default. |
@captainsafia I've tried transformer and now I'm not sure if it's possible to leverage it, since the first options.AddSchemaTransformer(fun schema context ct ->
let t = context.JsonTypeInfo.Type
if t.IsGenericType && t.GetGenericTypeDefinition() = typedefof<Option<_>> then
Console.WriteLine("Transforming Option")
Task.CompletedTask
) |> ignore |
Is there an existing issue for this?
Is your feature request related to a problem? Please describe the problem.
OpenAPI support has recently been add in F# web frameworks (Oxpecker, Giraffe, Falco). However there is a problem, that F# option type is not respected well. Here is an example with Oxpecker:
Generates the following schema:
Describe the solution you'd like
I expect it to generate the same schema as with just
int
, but without making this field required:Additional context
Note that FSharp option is already respected by System.Text.Json.
ValueOption
type should also be supported in the same way.The text was updated successfully, but these errors were encountered: