2

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

基本结构相当经典

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 框架的路由文件中一样

/rpc/ 路由.RPCController.rpc()

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

参考:

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

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

4

0 回答 0