You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
...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 =nullthen
failwithf "Schema parse errors:\n%s"elif diagnostic.Errors.Count >0thenleterrorsResponse= 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....letdefCompiler= DefinitionCompiler(schema, preferNullable)
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?
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``
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
typeOpenApiReaderError={Messag:string, Position:string}typeProvidedType/// <summary>OpenApi Reader Errors:/// - External reference cannot be loaded (postition)</summary>memberx.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")
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.
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.
Activity
sergey-tihon commentedon Jun 7, 2020
Generally I am OK with this change...Just not sure about most useful format.
What about
Errors:string listand allow user work with errors as with data?Thorium commentedon Jun 7, 2020
I'm not sure about the format either, that's why this is a question, not PR :-)
A few points:
myProvider.Errors.[0].``There is an incorrect character in $ref/item/data/my^item``sergey-tihon commentedon Jun 8, 2020
Agree with
SchemaReaderErrorsname.It should not be an issue. We can add it to root level
PetStore. SchemaReaderErrorson the same level where we add client for communicationSchemaReaderErrors.Client. All other provided type definitions can moved deeper (likePetStore.Types.*)XML comment also good idea. So it may look like
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
github-actions commentedon Mar 14, 2026
🤖 This is an automated response from Repo Assist.
A related improvement landed recently: PR #300 added the
IgnoreParseErrorsstatic parameter toOpenApiClientProvider. When set totrue, the provider continues generating types even when the OpenAPI parser reports validation errors, and emits each error tostderrviaeprintfn.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
SchemaReaderErrorsproperty 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 thediagnostic.Errorscollection into a provided member after the schema parse, which is still a worthwhile enhancement to do properly.Add SchemaReaderErrors static property to OpenApiClientProvider (fixes …
[Repo Assist] Add SchemaReaderErrors property to OpenApiClientProvider (