简体   繁体   中英

Enunciate with Swagger - cannot generate documentation resource models when using generics

I'm facing similar issue than the one described in that thread :

Can Enunciate generate docs for an API that handles generic types?

I am using enunciate 1.28 with spring and swagger modules enabled.

So considering an abstract resource class like :

public abstract class AbstractResource<T> {

    @Autowired
    private SomeService<T> service;

    @Path("/{id}")
    @GET
    public T get(@PathParam("id") String id) {
        return service.get(id);
    }

    @POST
    public Response post(T entity) {
        return service.post(entity);
    }
}

and one concrete implementation :

@Path("/authors")
public class AuthorResource extends AbstractResource<Author> { }
  1. Enunciate docs are not generated with the proper "Author" Data Model for both GET and POST methods.

For GET I have :

Response Body element:  (custom)`

and POST :

Request Body element: entity`
  1. For Swagger the Author model is not showing as the JSON model for GET as "responseClass" and POST for the body "dataType". Instead I get string for both.

However the Author model is listed in the AuthorResource.json generated in swagger/ui directory. The responseClass and dataType fields are just missing the link to the model.

Manually replacing :

"responseClass" : "string"` by `"responseClass" : "ns0_Author" (GET)
"dataType" : "string"` by `"dataType" : "ns0_Author" (POST)

does the trick.

Note : I confirm that on my side Author is annotated with @XmlRootElement and the Author class is included in my <api-import pattern="com.my.package.**"/> which is located in a jar file on the classpath.

Any ideas on how to tweak the Enunciate/Swagger documentation generation in that case ?

Thanks

Smells like a bug. Tracking it here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM