cxf-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jeffrey Crump <jcr...@constantcontact.com>
Subject Swagger2Feature not finding @Api annotations in interfaces
Date Fri, 05 Aug 2016 22:54:07 GMT
Hi,

I'm trying to use the Swagger2Feature on my CXF application.  I've got
interfaces defined in an "api" module, and the implementation classes in an
"impl" module (different maven modules, different JARs).

My Swagger annotations are on the interface definitions, not on the
implementation classes. The interface definitions don't seem to be getting
scanned.

When I put some fake annotations on the implementation classes, though,
they are found correctly -- even though I have set the resource package to
my API module.

The interface looks like this:

@Api(value="/real")
@Path("/real")
package com.foo.api.v1.rs;
public interface MyResource {
  @Path("/{id}")
  @ApiOperation(value="...")
  public String getSomething(String id);
}

The implementation class (in a different JAR) looks like this:

public class MyResourceImpl implements MyResource {
}

The generated swagger.json does not include this method.

However, when I put some fake annotations in the implementation class, e.g.:

@Api("/fake")
public class MyResourceImpl implements MyResource {
  @ApiOperation('/{id}')
  public String getSomething(String id) {
  }
}

all of the methods implemented in MyResourceImpl show up in the
swagger.json (as "fake" and not "real")

@Autowired MyResource res;

JAXRSServerFactoryBean endpoint = new JAXRSServerFactoryBean();
endpoint.setBus(bus);
endpoint.setServiceBeans(Arrays.<Object>asList(res));
endpoint.setAddress("/api-docs");

Swagger2Feature feature = new Swagger2Feature();
feature.setResourcePackage("com.foo.api.v1.rs");
endpoint.setFeatures(Arrays.asList(feature));

How do I get CXF Swagger2Feature to look at those interfaces and not the
concrete implementation classes?

Also, it doesn't seem to matter what I use as the endpoint address, it's
being ignored (but CXF throws if it's not supplied.  So I'm not quite sure
if I'm doing that part correctly.

Thanks for your help.

Jeff

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message