Skip to content

Schema error handling on OpenApiProvider #160

Closed

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)

Activity

  1. sergey-tihon commented on Jun 7, 2020

    @sergey-tihon
    Member

    Generally I am OK with this change...Just not sure about most useful format.
    What about Errors:string list and allow user work with errors as with data?

  2. Thorium commented on Jun 7, 2020

    @Thorium
    MemberAuthor

    I'm not sure about the format either, that's why this is a question, not PR :-)
    A few points:

    • Current implementation is rendering the provider un-usable on any error
    • Some schemas may have .Errors-property for business scenarios that should not be messed with technical errors. So basically SchemaReaderErrors would be better.
    • But the errors should be clearly visible. ".S" is far away in the property list, so that's why Errors would be better. Or some note to top-level XML-comment?
    • Schema reader errors are design-time things, so I was thinking user experience like this:
      myProvider.Errors.[0].``There is an incorrect character in $ref/item/data/my^item``
  3. sergey-tihon commented on Jun 8, 2020

    @sergey-tihon
    Member

    Agree with SchemaReaderErrors name.

    But the errors should be clearly visible. ".S" is far away in the property list, so that's why Errors would be better. Or some note to top-level XML-comment?

    It should not be an issue. We can add it to root level PetStore. SchemaReaderErrors on the same level where we add client for communication SchemaReaderErrors.Client. All other provided type definitions can moved deeper (like PetStore.Types.*)

    XML comment also good idea. So it may look like

    type OpenApiReaderError = {Messag:string, Position:string}
    
    type ProvidedType
       /// <summary>OpenApi Reader Errors:
       /// - External reference cannot be loaded (postition)</summary>
       member x. SchemaReaderErrors() =
          [{Message="External reference cannot be loaded"; Position="position"}]

    I was thinking user experience like this:
    myProvider.Errors.[0].There is an incorrect character in $ref/item/data/my^item

    This experience is also possible, but I believe that there should be an easily copy error message or position to google it, report an issues, find exact position in schema and fix, etc.

    In number of error is large you may want to process them somehow

    PetStore.SchemaReaderErrors
    |> List.filter (fun x -> not <| x.Message.Contain("$ref"))
    |> List.sortBy (fun x -> x.Position)
    |> List.iter (printfn "%A")
  4. github-actions commented on Mar 14, 2026

    @github-actions
    Contributor

    🤖 This is an automated response from Repo Assist.

    A related improvement landed recently: PR #300 added the IgnoreParseErrors static parameter to OpenApiClientProvider. When set to true, the provider continues generating types even when the OpenAPI parser reports validation errors, and emits each error to stderr via eprintfn.

    type MyClient = OpenApiClientProvider<"schema.yaml", IgnoreParseErrors=true>

    This is a partial step towards what was requested here — the provider is now usable with imperfect schemas without requiring the schema to be fixed first. However, the SchemaReaderErrors property discussed in this thread (programmatic access to parse errors as a list in the provided type) has not yet been implemented. That feature would require wiring the diagnostic.Errors collection into a provided member after the schema parse, which is still a worthwhile enhancement to do properly.

    Generated by Repo Assist · ◷

    To install this agentic workflow, run

    gh aw add githubnext/agentics/workflows/repo-assist.md@346204513ecfa08b81566450d7d599556807389f
    
  5. added a commit that references this issue on Mar 17, 2026
    4c86ab5
  6. added a commit that references this issue on Mar 26, 2026
    250f832
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions