@JsonApiResource(type = PersonDto.RESOURCE_TYPE) @EntityMapping(entityClass = Person.class) //@ResourceAccess(readOnly = true) @ApiResource(group = ApiResourceGroup.CONTACT_AND_ACTIVITY) public class PersonDto extends PartyDto { }
将@ResourceAccess(readOnly = true)注释掉,则,重新编译项目,访问ip/backstop/api-docs/index.html#!/_People,则发现,在people对应下,由原来只有get/post变成了get/post/delete/patch四种请求都有。
simon告诉我,这是基于反射的原理。具体内部如下:
web.xml:
<servlet> <servlet-name>Jersey Katharsis Service</servlet-name> <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class> <init-param> <param-name>javax.ws.rs.Application</param-name> <param-value>com.backstopsolutions.api.KatharsisApplication</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet>
kathasisApplication:
@Singleton @ApplicationPath("/") public class KatharsisApplication extends ResourceConfig { public static final String API_PATH_PREFIX = "/backstop/api"; public static final String API_PACKAGE_NAME = "com.backstopsolutions.api"; public KatharsisApplication() { property(KatharsisProperties.RESOURCE_SEARCH_PACKAGE, API_PACKAGE_NAME + ",io.katharsis"); property(KatharsisProperties.WEB_PATH_PREFIX, API_PATH_PREFIX); register(BackstopContext.getInjector().getInstance(KatharsisDynamicFeature.class)); } }
kathasisDynamicFeature:
@Override public boolean configure(FeatureContext context) { if (!super.configure(context)) { return false; } // Swagger filter context.register(injector.getInstance(ApiDocFilter.class)); // API usage filter context.register(injector.getInstance(ApiUsageFilter.class)); // API version filter context.register(injector.getInstance(ApiVersionFilter.class)); // Clean up context.register(injector.getInstance(ApiContextCleanUpFilter.class)); apiContext.initialize(); return true; }
ApiDocFilter:
和swagger关联,具体,内部怎么反射变成swagger调试工具,不是很懂。如有同事能解释清楚,望补充。