私は非常に単純な削除方法を持っています:
/**
* Delete the question with the specified id
*
* @return a <code>204 NO CONTENT</code> on success or a <code>404 NOT FOUND</code> if there is no question available
* @successResponse 204 The question was successfully deleted
* @errorResponse 404 The question does not exist
*/
@DELETE
public Response delete(@PathParam("questionId") final Long questionId) {
final Question question = findByQuestionId(questionId); // throws NotFoundException
questionService.delete(question.getQuestionId());
return Response.noContent().build();
}
ご覧のとおり、JavaDoc タグを使用して、成功とエラーの応答コードを指定しました。メソッド内で、コンテンツなしの応答 (ステータス コード 204) を作成します。これは、swagger-doclet が生成するものです。
{
"method" : "DELETE",
"nickname" : "delete",
"type" : "Response",
"parameters" : [ {
"type" : "integer",
"format" : "int64",
"paramType" : "path",
"name" : "questionId",
"required" : true
} ],
"summary" : "Delete the question with the specified id",
"responseMessages" : [ {
"code" : 204,
"message" : "The question was successfully deleted"
}, {
"code" : 404,
"message" : "The question does not exist"
} ],
"produces" : [ "application/json" ]
}
これまでのところ、うまくいっています。成功とエラーの応答コードを含む JavaDoc タグが必要です。また、メソッドのreturn文からとったと思われる「Response」型もあります。Swagger UI を開くと、次のビューが表示されます。
上部に「応答クラス (ステータス 200)」が表示されます。「応答クラス」は正しいですが、「ステータス 200」は間違っています。このメソッドのどこにもステータス コード 200 (OK) が返されません。この出力を修正する有効な解決策が見つかりませんでした。
私が使用するもの:
- Java 8
- Maven 3.3.9
- ドロップウィザード 0.9.2
- org.apache.maven.plugins.maven-javadoc-plugin 2.10.3
- com.tenxerconsulting.swagger-doclet 1.1.3
試してみたい場合は、完全なプロジェクトが GitHub にあります: https://github.com/McPringle/moodini
正しい Swagger API ドキュメントを入手できれば、本当に素晴らしいことです。どんな助けでも大歓迎です。
どうもありがとうございました!