Skip to content

Fails when document doesn't contain paths #190

Closed

Description

@Johnlon

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.

Activity

  1. Johnlon commented on May 8, 2021

    @Johnlon
    Author

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

  2. JFCote commented on May 10, 2021

    @JFCote
    Member

    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.

  3. added this to the v1.8.0 milestone on Sep 24, 2021
  4. gervaisb commented on Oct 12, 2021

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

  5. JFCote commented on Oct 12, 2021

    @JFCote
    Member

    @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.
  6. gervaisb commented on Oct 12, 2021

    @gervaisb
    Contributor

    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.

  7. Johnlon commented on Nov 29, 2021

    @Johnlon
    Author

    Hi any progress? Thanks

  8. gervaisb commented on Nov 30, 2021

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

  9. JFCote commented on Apr 27, 2022

    @JFCote
    Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions