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
Describe the bug
Fails with an NPE if the OAS is missing a paths section
To Reproduce
Validate a doc without "paths"
Expected behavior
The library should report the OAS as invalid due to lack of a key feature
Additional context
I expect the library is equally lacking in assumptions it makes about other OAS features that might be missing..
A NPE is always a software error.
You are right, an NPE is always a software error. I will need to check where it comes from because it depends who made the assumption. Either it's swagger-parser or its my code (probably my code!!)
I don't have a lot of time these days + having problems with my eyes/headache so I don't know when I'll be able to look at this but if you have time to create a PR, I will try to look at it quickly.
Isn't the role of the open-api-generator-cli (with validate command) to spot the structural issues. The openapi-style-validator is a complement of the first one that can enforce some finer rules and enterprise conventions.
@gervaisb Yes, at a higher level, you are right. The thing is that we are using swagger-parser to get and object representation of the OpenAPI specification. So the problem is either:
swagger-parser is not handling the missing path correctly and throw a null pointer exception instead of a clear error message.
we are having code that think there is always at least one path and we are throwing a null pointer exception. If that's the case, we should check if there is a path and/or throw a meaningful error.
Do we have to throw an exception or just no trying to validate the path?
As written by @jmini in #93; "at least one of paths, components or webhooks" is required. One user may want to validate the style of a webhooks only specification.
From a quick test, it seems that OpenAPI#getPaths() returns null when there are no paths (or only the keyword). So we can easily test that case into OpenApiSpecStyleValidator#validateOperations. We only have to decide what to do... IMHO we should skip the validation without raising any errors since the specification may still be valid without paths. Later we can add a stronger test to verify if at least one of paths, components or webhooks is set.
Activity
Johnlon commentedon May 8, 2021
I see there are other similar bugs.
Suggest a complete review of the processing logic with comprehensive tests.
JFCote commentedon May 10, 2021
Hi @Johnlon !
Thanks for the bug report!
You are right, an NPE is always a software error. I will need to check where it comes from because it depends who made the assumption. Either it's
swagger-parseror its my code (probably my code!!)I don't have a lot of time these days + having problems with my eyes/headache so I don't know when I'll be able to look at this but if you have time to create a PR, I will try to look at it quickly.
gervaisb commentedon Oct 12, 2021
Isn't the role of the
open-api-generator-cli(withvalidatecommand) to spot the structural issues. Theopenapi-style-validatoris a complement of the first one that can enforce some finer rules and enterprise conventions.JFCote commentedon Oct 12, 2021
@gervaisb Yes, at a higher level, you are right. The thing is that we are using
swagger-parserto get and object representation of the OpenAPI specification. So the problem is either:gervaisb commentedon Oct 12, 2021
Do we have to throw an exception or just no trying to validate the path?
As written by @jmini in #93; "at least one of paths, components or webhooks" is required. One user may want to validate the style of a webhooks only specification.
From a quick test, it seems that
OpenAPI#getPaths()returnsnullwhen there are no paths (or only the keyword). So we can easily test that case intoOpenApiSpecStyleValidator#validateOperations. We only have to decide what to do... IMHO we should skip the validation without raising any errors since the specification may still be valid withoutpaths. Later we can add a stronger test to verify if at least one ofpaths,componentsorwebhooksis set.Johnlon commentedon Nov 29, 2021
Hi any progress? Thanks
gervaisb commentedon Nov 30, 2021
Hi @Johnlon, thank for your interest.
This should be fixed with this PR; #251
You can build the master branch if you want to test it before the release.
JFCote commentedon Apr 27, 2022
Since this is fixed in #251 I'm closing this.