Skip to content
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 OpenApi Schema generation #46

Open
Swoorup opened this issue Feb 22, 2020 · 2 comments
Open

Support OpenApi Schema generation #46

Swoorup opened this issue Feb 22, 2020 · 2 comments
Labels
enhancement New feature or request

Comments

@Swoorup
Copy link

Swoorup commented Feb 22, 2020

It would be nice if we could add OpenApi 3.0 schema generation. So F# types could directly be exposed in REST models. Its possible to override schema using SchemaFilter in Swashbuckle.

@Swoorup Swoorup changed the title Question regarding Swashbuckle or Nswag Support OpenApi Schema generation Feb 23, 2020
@Swoorup
Copy link
Author

Swoorup commented Feb 27, 2020

I am hacking out a initial implementation like this:

        interface ISchemaFilter with
            member this.Apply (schema: OpenApiSchema, context: SchemaFilterContext) =
                let objType = context.Type
                if objType |> IsUnion then
                    schema.Properties <- Dictionary()
                    
                    let cases =
                        GetUnionCases objType
                        |> Seq.map (fun field ->
                            let case = OpenApiSchema()
                            case.Title <- field.Key
                            case
                            )
                        |> BCLConverters.seqToList
                    
                    let obj = OpenApiSchema()
                    obj.Type <- "object"
                    obj.OneOf <- cases
                    
                    let caseProp = OpenApiSchema(Type = "string")
                    
                    schema.Properties.Add("Case", caseProp)
                    schema.Properties.Add("Fields", obj)
                    ()
                

Which generates the following:
image

However the code is duplicated. Any ideas so it can be unified across the serializer as well as openapi generation?

@xperiandri
Copy link
Contributor

@Swoorup maybe it should go to Microsoft.OpenAPI package?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants