sylvainlaurent / swagger-validator-maven-plugin

A maven plugin that validates swagger files in yaml and json formats
Apache License 2.0
11 stars 6 forks source link

NullPointerException on external $ref with relative path #21

Open pvdbosch opened 5 years ago

pvdbosch commented 5 years ago

A NPE occurs when there's an external $ref with a relative path, unless it leads with "./" .

E.g. $ref: 'person/identifier/v1beta/person-identifier-v1beta.yaml#/parameters/SsinPathParameter' fails

but $ref: './person/identifier/v1beta/person-identifier-v1beta.yaml#/parameters/SsinPathParameter' works fine

In other tooling and in the spec, both seem to be supported.

The stacktrace: Caused by: java.lang.NullPointerException at io.swagger.parser.processors.ParameterProcessor.processParameters (ParameterProcessor.java:47) at io.swagger.parser.processors.OperationProcessor.processOperation (OperationProcessor.java:26) at io.swagger.parser.processors.PathsProcessor.processPaths (PathsProcessor.java:101) at io.swagger.parser.SwaggerResolver.resolve (SwaggerResolver.java:50) at com.github.sylvainlaurent.maven.swaggervalidator.service.ValidationService.readSwaggerSpec (ValidationService.java:76) at com.github.sylvainlaurent.maven.swaggervalidator.service.ValidationService.validate (ValidationService.java:67) at com.github.sylvainlaurent.maven.swaggervalidator.ValidateMojo.execute (ValidateMojo.java:62)

I've tried upgrading the swagger-parser dependency to latest 1.0.44 version, but it isn't compatible with the swagger-validator-maven-plugin.

giuliopulina commented 5 years ago

Hi @pvdbosch, could you please provide an example of not working spec?

pvdbosch commented 5 years ago

Hi @giuliopulina , validator-relativeref-test.zip provides an example.

giuliopulina commented 5 years ago

@pvdbosch as I suspected, the issue is related to swagger libraries. I can't precisely describe what the issue is, because I didn't have the time to compare how the two version of libraries create the path from the spec, but I created a branch (and added/amended tests) to demonstrate the issue resolution (you can check the branch in my fork here)

Let me know if you can give it a try and if it's ok for you, then I will open a PR.

update: @pvdbosch I found a problem while updating my branch with latest version from master, so the issue is not yet solved.

rantoniuk commented 4 years ago

I am also experiencing NPE with the SNAPSHOT build from the bugfix branch, not sure though if that's the same case:

Caused by: java.lang.NullPointerException
    at com.github.sylvainlaurent.maven.swaggervalidator.semantic.validator.path.ResponseValidator.validateSchema (ResponseValidator.java:45)
    at com.github.sylvainlaurent.maven.swaggervalidator.semantic.validator.path.ResponseValidator.validate (ResponseValidator.java:39)
    at com.github.sylvainlaurent.maven.swaggervalidator.semantic.validator.path.PathValidatorTemplate.visit (PathValidatorTemplate.java:79)
    at java.util.ArrayList.forEach (ArrayList.java:1249)
    at com.github.sylvainlaurent.maven.swaggervalidator.semantic.validator.path.PathValidatorTemplate.visit (PathValidatorTemplate.java:63)
    at java.util.HashMap$Values.forEach (HashMap.java:980)
    at com.github.sylvainlaurent.maven.swaggervalidator.semantic.validator.path.PathValidatorTemplate.visit (PathValidatorTemplate.java:54)
    at com.github.sylvainlaurent.maven.swaggervalidator.semantic.validator.path.PathValidatorTemplate.visit (PathValidatorTemplate.java:44)
    at com.github.sylvainlaurent.maven.swaggervalidator.semantic.validator.path.PathValidatorTemplate.validate (PathValidatorTemplate.java:36)
    at com.github.sylvainlaurent.maven.swaggervalidator.service.SemanticValidationService.validate (SemanticValidationService.java:77)
    at com.github.sylvainlaurent.maven.swaggervalidator.service.ValidationService.validateSwagger (ValidationService.java:99)
    at com.github.sylvainlaurent.maven.swaggervalidator.service.ValidationService.validate (ValidationService.java:69)
    at com.github.sylvainlaurent.maven.swaggervalidator.ValidateMojo.execute (ValidateMojo.java:67)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:210)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:956)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:288)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:192)
    at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:498)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
giuliopulina commented 4 years ago

Hi @warden, I don't think it's the same case, could you please provide a sample failing spec file?