stoicflame / enunciate-openapi

OpenAPI3 module for Enunciate
Apache License 2.0
10 stars 10 forks source link

Cannot use this module with spring-web module #2

Closed hlavki closed 6 years ago

hlavki commented 6 years ago

Getting error:

Caused by: java.lang.NullPointerException
    at com.webcohesion.enunciate.modules.spring_web.SpringWebApiRegistry.getResourceApis (SpringWebApiRegistry.java:33)
    at com.webcohesion.enunciate.api.AggregatedApiRegistry.getResourceApis (AggregatedApiRegistry.java:44)
    at dk.jyskebank.tools.enunciate.modules.openapi.OpenApiModule.call (OpenApiModule.java:141)
    at com.webcohesion.enunciate.io.InvokeEnunciateModule.onNext (InvokeEnunciateModule.java:46)

Full log: enunciate.log

Related enunciate issue: https://github.com/stoicflame/enunciate/issues/856

jskov-jyskebank-dk commented 6 years ago

I had a quick look at the SpringWebApiRegistry, and it looks like this:


  private final EnunciateSpringWebContext context;

  public SpringWebApiRegistry(EnunciateSpringWebContext context) {
    this.context = context;
  }

  @Override
  public List<ServiceApi> getServiceApis(ApiRegistrationContext context) {
    return Collections.emptyList();
  }

  @Override
  public List<ResourceApi> getResourceApis(ApiRegistrationContext context) {
    return this.context.getControllers().isEmpty() ? Collections.<ResourceApi>emptyList() : Collections.singletonList((ResourceApi) new SpringWebResourceApi(this.context, context));
  }

The call chain in the stack trace shows that OpenApiModule calls AggregateApiRegistry with a non-null argument. I am not sure how that ApiRegistry in spring_web is supposed to behave, but it is not something I can fix from the OpenApi module.

At a guess, it has been initialized in a faulty manner. Or it is supposed to use that input argument context, rather than this.context.

stoicflame commented 6 years ago

It looks like you need to add "spring-web" as a dependency module at OpenApiModule.java line 75. I'd bet that would fix the issue.

jskov-jyskebank-dk commented 6 years ago

Interesting @stoicflame . Do I need to add the other provider modules as well (jaxws and jackson1)?

I can easily add those dependency modules.

stoicflame commented 6 years ago

Yes, you'll want to add those, too.

jskov-jyskebank-dk commented 6 years ago

I have released 1.0.5 which fixes this problem.