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

Fails when document doesn't contain paths #190

Closed
Johnlon opened this issue May 8, 2021 · 8 comments
Closed

Fails when document doesn't contain paths #190

Johnlon opened this issue May 8, 2021 · 8 comments
Labels
Milestone

Comments

@Johnlon
Copy link

Johnlon commented May 8, 2021

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.

@Johnlon
Copy link
Author

Johnlon commented May 8, 2021

I see there are other similar bugs.
Suggest a complete review of the processing logic with comprehensive tests.

@JFCote
Copy link
Member

JFCote commented 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-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.

@JFCote JFCote added the bug label May 10, 2021
@JFCote JFCote added this to the v1.8.0 milestone Sep 24, 2021
@gervaisb
Copy link
Contributor

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.

@JFCote
Copy link
Member

JFCote commented Oct 12, 2021

@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.

@gervaisb
Copy link
Contributor

gervaisb commented 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() 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.

@Johnlon
Copy link
Author

Johnlon commented Nov 29, 2021

Hi any progress? Thanks

@gervaisb
Copy link
Contributor

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
Copy link
Member

JFCote commented Apr 27, 2022

Since this is fixed in #251 I'm closing this.

@JFCote JFCote closed this as completed Apr 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants