swagger-api / swagger-parser

Swagger Spec to Java POJOs
http://swagger.io
Apache License 2.0
778 stars 525 forks source link

[Java/Jaxrs/Resteasy] NPE thrown when response is defined with $ref without content #925

Open tnmtechnologies opened 5 years ago

tnmtechnologies commented 5 years ago

We wanted to fix swagger-api/swagger-codegen/issues/8859 in OpenAPITools/openapi-generator thanks to this PR OpenAPITools/openapi-generator/pull/1416

Then we faced this issue OpenAPITools/openapi-generator/issues/1420. It seems to come from swagger parser.

Here is the exception :

[WARNING] Exception while reading:
java.lang.NullPointerException
    at io.swagger.v3.parser.ResolverCache.updateLocalRefs(ResolverCache.java:162)
    at io.swagger.v3.parser.ResolverCache.loadRef(ResolverCache.java:152)
    at io.swagger.v3.parser.processors.ExternalRefProcessor.processRefToExternalResponse(ExternalRefProcessor.java:205)
    at io.swagger.v3.parser.processors.ResponseProcessor.processReferenceResponse(ResponseProcessor.java:76)
    at io.swagger.v3.parser.processors.ResponseProcessor.processResponse(ResponseProcessor.java:38)
    at io.swagger.v3.parser.processors.OperationProcessor.processOperation(OperationProcessor.java:56)
    at io.swagger.v3.parser.processors.PathsProcessor.processPaths(PathsProcessor.java:83)
    at io.swagger.v3.parser.OpenAPIResolver.resolve(OpenAPIResolver.java:49)
    at io.swagger.v3.parser.OpenAPIV3Parser.readLocation(OpenAPIV3Parser.java:53)
    at io.swagger.parser.OpenAPIParser.readLocation(OpenAPIParser.java:19)
    at org.openapitools.codegen.config.CodegenConfigurator.toClientOptInput(CodegenConfigurator.java:552)
    at org.openapitools.codegen.plugin.CodeGenMojo.execute(CodeGenMojo.java:582)

Please what is your point of view about this issue?

We used OpenAPITools/openapi-generator 3.3.3-SNAPSHOT (java/jaxrs/resteasy).

ymohdriz commented 5 years ago

Hi @tnmtechnologies,

Can you please add the OAI spec to reproduce this issue?

Thanks, Mohammed

tnmtechnologies commented 5 years ago

Hi @ymohdriz , The OAI spec is openapi: 3.0.0 . KR

ymohdriz commented 5 years ago

Please attach the input openapi document to reproduce this issue

tnmtechnologies commented 5 years ago

Hi @ymohdriz ,

Please find in attachment the OAI spec files. The yaml file to use as input file is the file TS29510_Nnrf_NFManagement.yaml. You will see that it contains a lot of responses '501' defined as

        '501':
          $ref: './TS29571_CommonData.yaml#/components/responses/501'

In such cases, the exception is thrown.

If we replace the error '501' in file TS29510_Nnrf_NFManagement.yaml by its declaration defined in file TS29571_CommonData.yaml then the exception is not thrown.

    '501':
      description: Not Implemented

Exception is thrown with openapi-generator tool version 3.3.3.

TT

TS.ZIP