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

Any way to get validation error line? #388

Open
kevin-postman opened this issue Jul 29, 2021 · 2 comments
Open

Any way to get validation error line? #388

kevin-postman opened this issue Jul 29, 2021 · 2 comments

Comments

@kevin-postman
Copy link

kevin-postman commented Jul 29, 2021

When calling the Validate function after loading an OpenAPI doc, whenever there is a failure.. in my case an invalid paths error is thrown, with unsupported 'format' value 'int64'.. which is NOT invalid.. I have no idea where in the file being parsed the error is at. Even more odd is that if I keep running the same validate call, sometimes I get a little more info back.. no idea why its random.. but in this particular file most of the time the error is:

invalid paths: unsupported 'format' value "int64"

But sometimes it says:

invalid paths: parameter "dateRangeFrom" schema is invalid: unsupported 'format' value "int64"

I figured out the actual reason the parsing fails.. but even so....

Is there any way to get the error line of the parsing error? Any idea why the response to the validation error changes?

@fenollp
Copy link
Collaborator

fenollp commented Jul 29, 2021

Validation error changes most probably because elements of the openapi document are validated inside for ... range map[...]... loops, which introduces nondeterminism.

There is no parsing error but you do get validation errors. Note that to get multiple errors at once there's https://pkg.go.dev/github.com/getkin/[email protected]/openapi3#MultiErrors

Something akin to JSON Path to point to the problematic place in both the schema and the data would be nice. I am not working on this though and #230 will probably bring this actually.

I'm curious what the reason was for unsupported 'format' value "int64"?

@kevin-postman
Copy link
Author

So.. the reason for invalid int64 was the type was number, not integer. Most of the types were set to integer. I thought that was odd too.. because the online validator says its completely valid. But the spec does indicate that if the type is integer, format can be int64 or int32 (if provided). So I think your validation is correct. I suspect maybe it was a number before and they didn't change that to integer.

I'll look at MultiErrors.. I was hoping there was some way to match it to the line number that it occurs at to match up to it in an editor. Makes it hard for us to visually mark the error in an editor without knowing where it occurs.

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

No branches or pull requests

2 participants