NPE at io.swagger.jackson.ModelResolver.handleUnwrapped()

334 views
Skip to first unread message

Dan Tran

unread,
May 25, 2017, 10:32:00 PM5/25/17
to Swagger

Hi 

I am using swagger-maven-plugin to generate swagger spec and NPE at swagger-core


    private void handleUnwrapped(List<Property> props, Model innerModel, String prefix, String suffix) {
        if (StringUtils.isBlank(suffix) && StringUtils.isBlank(prefix)) {
            props.addAll(innerModel.getProperties().values());
        } else {
            if (prefix == null) {
                prefix = "";
            }
            if (suffix == null) {
                suffix = "";
            }
            for (Property prop : innerModel.getProperties().values()) {
                props.add(prop.rename(prefix + prop.getName() + suffix));
            }
        }
    }

with this stack trace

Caused by: java.lang.NullPointerException
        at io.swagger.jackson.ModelResolver.handleUnwrapped(ModelResolver.java:608)
        at io.swagger.jackson.ModelResolver.resolve(ModelResolver.java:441)
        at com.github.kongchen.swagger.docgen.reader.ModelModifier.resolve(ModelModifier.java:96)
        at io.swagger.jackson.ModelResolver.resolve(ModelResolver.java:183)
        at com.github.kongchen.swagger.docgen.reader.ModelModifier.resolve(ModelModifier.java:90)
        at io.swagger.converter.ModelConverterContextImpl.resolve(ModelConverterContextImpl.java:100)
        at io.swagger.converter.ModelConverters.read(ModelConverters.java:66)
        at com.github.kongchen.swagger.docgen.reader.AbstractReader.updateApiResponse(AbstractReader.java:431)
        at com.github.kongchen.swagger.docgen.reader.JaxrsReader.parseMethod(JaxrsReader.java:341)


Debug true shows   innerModel is null

What could be a potential problem i an look further?

Thanks

-D

tony tam

unread,
May 25, 2017, 10:56:36 PM5/25/17
to swagger-sw...@googlegroups.com
Can you please share the definition that you’re using?  Looks to me like you have something like this:

type: array

without an inner items type:

type: array
items:
  type: string


--
You received this message because you are subscribed to the Google Groups "Swagger" group.
To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Dan Tran

unread,
May 26, 2017, 12:47:10 AM5/26/17
to Swagger

Hi Tam,

Not sure what you mean by 'the definition'. But our module is Spring base with Hateoas. After compile phase, we pass the  java package to swagger-m-p to generate swagger jsonschema spec

We use swagger-m-p with latest swagger-core to get support for @JsonUnwrap. Even if remove all @JsonUnwrap anotion, still see same NPE 

Appreciate any help

-Dan

To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggersocket+unsub...@googlegroups.com.

Dan Tran

unread,
May 26, 2017, 1:37:20 AM5/26/17
to Swagger
here is maven debug log

[DEBUG] resolve class org.springframework.hateoas.Resource
[DEBUG] trying extension com.github.kongchen.swagger.docgen.reader.ModelModifier@1de4285e
[DEBUG] defineModel Resource io.swagger.models.ModelImpl@67d75b4c
[DEBUG] resolve [simple type, class java.lang.Object]
[DEBUG] trying extension com.github.kongchen.swagger.docgen.reader.ModelModifier@1de4285e
[DEBUG] Can't check class [simple type, class java.lang.Object], java.lang.Object
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE


Spring   hateoas.Resource is suspicious 

-Dan

tony tam

unread,
May 26, 2017, 1:39:20 AM5/26/17
to swagger-sw...@googlegroups.com
Yes, likely it’s trying to build a schema of that model, and it doesn’t like it.  Not sure what one would expect for that definition in JSON Schema.

--
You received this message because you are subscribed to the Google Groups "Swagger" group.
To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.

Dan Tran

unread,
May 26, 2017, 3:23:30 AM5/26/17
to Swagger
Ah, now we toasted.  

swagger-m-p-3.1.3 which uses swagger-core 1.5.5 still working for us with limitation.  

:(


To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggersocket+unsub...@googlegroups.com.

Dan Tran

unread,
May 26, 2017, 3:53:37 AM5/26/17
to Swagger

swagger-3.1.4 + swagger-model-1.5.9 work,  and it does not scan Spring Hateoas. Is there a option with swagger-core-1.5.12+ to do the same?

Thanks

-Dan

Dan Tran

unread,
May 27, 2017, 1:44:15 AM5/27/17
to Swagger
Further investigation shows that   swagger-m-p 3.1.4 + swagger-core-1.5.10 works.  Its debug logs also show springframework.hateoas.Resource does get processed

however, with swagger-core-1.5.11 which also introducing   @JsonUnwrapped handling, this is where NPE shows up

I wonder of any one able to get @JsonUnwrapped working with and without Spring?

Thanks

-Dan

Dan Tran

unread,
May 27, 2017, 10:33:08 PM5/27/17
to Swagger

I am able to reproduce the NPE with a small maven project. it has nothing to do with Spring Hateoas.  NPE only happens with  @JsonUnwrapped field where it class has no 'get' method.

-D


Dan Tran

unread,
May 28, 2017, 12:59:31 AM5/28/17
to Swagger
Drill down some more.  I found the innerModel is null b/c its propType ls [simple type, class java.lang.Object] (from debugger).  

Here is the line 

  handleUnwrapped(props, context.resolve(propType), uw.prefix(), uw.suffix());

By ignore this NPE, my build is good, the generated @JsonUnwrapped looks good.  Not sure what else I miss thou

Thoughts?

Very appreciated any help

-Dan

Calder Carey

unread,
May 28, 2017, 11:17:13 AM5/28/17
to swagger-sw...@googlegroups.com

--------------------------------------------
On Sun, 5/28/17, Dan Tran <dan...@gmail.com> wrote:

Subject: Re: NPE at io.swagger.jackson.ModelResolver.handleUnwrapped()
To: "Swagger" <swagger-sw...@googlegroups.com>
Date: Sunday, May 28, 2017, 7:59 AM
--

You received this message because you are subscribed to the
Google Groups "Swagger" group.

To unsubscribe from this group and stop receiving emails
from it, send an email to swagger-swaggers...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.
7pirea la Galitia a avut importante consecinte social-pohtice etnice si

tony tam

unread,
May 28, 2017, 2:57:37 PM5/28/17
to swagger-sw...@googlegroups.com
I don’t think this PR is from you, but it looks like it’s on the same topic:


Can you please test that fix locally and if that doesn’t fix it, file an issue in GitHub?

--
You received this message because you are subscribed to the Google Groups "Swagger" group.
To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.

Dan Tran

unread,
May 28, 2017, 5:21:13 PM5/28/17
to Swagger
I am able to pin point to a couple of scenarios, filed the issue at   https://github.com/swagger-api/swagger-core/issues/2222
Reply all
Reply to author
Forward
0 new messages