我正在实现一个RPC类型的API应用程序 . 我在play框架上使用Java . 我已经使用了swagger模块为简单的rest API生成了swagger文档,其中每个“URL”映射到我的控制器中的不同静态函数 . 但在这里,我需要将一个URL和一个静态函数映射到API文档中的多个Actions .

基本结构非常经典

abstract class RPCActionRequest implements Serializable{
  public int actionCode; //this might be an enum too
  public RPCActionParam param;
}

interface RPCActionParam implements Serializable{
}

abstract class RPCAction {
  public int actionCode;
  public abstract RPCActionResult execute(RPCActionParam param);
}

interface RPCActionResult implements Serializable{
  public int responseCode; //sUCCESS, ERROR, FAIL, ... whatever errors my system needs to
                           //communicate to the client.
}

每个动作都映射到我的RPCController映射器中的相同静态函数,就像在play框架的routes文件中一样

/ rpc / routes.RPCController.rpc()

如何使用swagger和swagger-core doc生成来记录所有操作,参数类和结果类?是否可以只使用swagger-play2模块的@ Api *注释?

裁判:

-Swagger:https://developers.helloreverb.com/swagger/

-Swagger-core:https://github.com/wordnik/swagger-core