Swagger overrides Path-Annotations

前端 未结 1 1030
眼角桃花
眼角桃花 2021-01-27 13:46

I just got swagger to produces a valid swagger.json. I configured swagger by using the Application-config method. However, as soon as I override the getClasses-Method to add the

相关标签:
1条回答
  • 2021-01-27 14:15

    You can use a javax.ws.rs.core.Feature. Just register the classes through the callback's FeatureContext. Annotating the feature with @Provider will have it registered through the scanning.

    @Provider
    public class SwaggerFeature implements Feature {
    
        @Override
        public boolean configure(FeatureContext context) {
            context.register(ApiListingResource.class);
            context.register(SwaggerSerializers.class);
            return true;
        }
    }
    

    But note that if the application is already registering the resources and providers by class-path scanning, I imagine it should also pick up the Swagger classes, as they are annotated with @Path[1] and @Provider[2]. Those are the annotations the class-path scan looks for.

    I haven't tried it myself (I stopped using class-path scanning[3]), but have you tried just not registering them at all? In theory the class-path scan should pick it up.

    1. io.swagger.jaxrs.listing.ApiListingResource
    2. io.swagger.jaxrs.listing.SwaggerSerializers
    3. When to Use JAX-RS Class-path Scanning Mechanism

    0 讨论(0)
提交回复
热议问题