Skip to content

Schema error handling on OpenApiProvider #160

Open
@Thorium

Description

@Thorium

If there are any errors in schema, the OpenApiProvider just gives up:

...which is maybe good behaviour if you can actually fix the schema. But in many cases you are the user, so you can't. Also you cannot easily copy the error. The parser itself will response both a-partially-read-schema and the errors.

So maybe a better way to handle the error case on partial-succeeded-schema, would be creating an "Errors"-property to the root-type and save those as a list of properties, or to xml-comment.

Just a pseudo, something like this:

if diagnostic.Errors.Count > 0 && schema = null then
    failwithf "Schema parse errors:\n%s"
elif diagnostic.Errors.Count > 0 then
    let errorsResponse = ProvidedTypeDefinition("Errors", Some typeof<obj>)
    errorsResponse.AddMember(ProvidedConstructor([], empty))
    errorsResponse.AddMembers(fun () ->
        diagnostic.Errors |> Seq.map (fun e -> sprintf "%s @ %s" e.Message e.Pointer)
        |> Seq.toList |> List.map (fun e ->
            ProvidedProperty(e,typeof<unit>, getterCode = <@@ () @@>) :> MemberInfo
        )
    )
    errorsResponse.AddXmlDocComputed(fun () ->
        diagnostic.Errors
        |> Seq.map (fun e -> sprintf "%s @ %s" e.Message e.Pointer)
        |> String.concat "\n")
    ty.AddMember errorsResponse

//and then continue like nothing happened....
let defCompiler = DefinitionCompiler(schema, preferNullable)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions