7

Swagger を使用して、Spring Boot API の API ドキュメントを提供したいと考えています。Springfox 2.3.0 を動作させることができ、ObjectNode を返すコントローラーを除いて、すべてが期待どおりに動作します。Swagger は、返されたクラス (ObjectNode) を JSON 表現に変換しようとします。結果は次のようになります。

{
    "array": true,
    "bigDecimal": true,
    "bigInteger": true,
    "binary": true,
    "boolean": true,
    "containerNode": true,
    "double": true,
    "float": true,
    "floatingPointNumber": true,
    "int": true,
    "integralNumber": true,
    "long": true,
    "missingNode": true,
    "nodeType": "ARRAY",
    "null": true,
    "number": true,
    "object": true,
    "pojo": true,
    "short": true,
    "textual": true,
    "valueNode": true
}

これで、作成した JSON に含まれる値を Swagger が推測できないことがわかりましたが、正しい ResponseModel を任意の形式で手動で追加したいと考えています。

コントローラーは次のようになります。

@ApiOperation(value = "NAME", notes = "NOTES")
@RequestMapping(value = "", method = RequestMethod.GET, produces="application/json")
public ResponseEntity<ObjectNode> getComponentByIdentification(
            @ApiParam(name="customerid", required=true, value="")
            @RequestParam (required = true)
            String customerId){
    return new ResponseEntity<ObjectNode>(someService.getCustomer(customerId), HttpStatus.OK);
}

モデル スキーマとしてドキュメントに示されているカスタム ResponseJSON を Swagger に提供する方法はありますか?

4

1 に答える 1