{"id":288339,"date":"2018-08-22T07:10:02","date_gmt":"2018-08-22T03:10:02","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=288339"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=288339","title":{"rendered":"\u041f\u0440\u0435\u0434\u0431\u043e\u043b\u044c\u043d\u0438\u0447\u043d\u044b\u0439 \u0445\u043e\u0442\u0444\u0438\u043a\u0441 \u0438\u043b\u0438 \u201c\u042d\u0439, Swagger! \u0410 \u0433\u0434\u0435 \u043c\u043e\u0438 \u043e\u0448\u0438\u0431\u043a\u0438\u201d?"},"content":{"rendered":"\n<div data-io-article-url=\"https:\/\/habr.com\/post\/420841\/\" class=\"post__text post__text-html js-mediator-article\">\u0421\u043b\u0443\u0447\u0430\u043b\u043e\u0441\u044c \u043b\u0438 \u0432\u0430\u043c \u043d\u0430\u043b\u0430\u0436\u0430\u0442\u044c \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u0445\u043e\u0442\u0444\u0438\u043a\u0441\u0430 \u0432 \u043c\u0430\u0441\u0442\u0435\u0440? \u041d\u0435\u0442?! \u0410 \u0432\u043e\u0442 \u043c\u043d\u0435 \u0443\u0434\u0430\u043b\u043e\u0441\u044c!<br \/>  \u042d\u0442\u0430 \u0438\u0441\u0442\u043e\u0440\u0438\u044f \u043e \u0442\u043e\u043c, \u043a\u0430\u043a \u044f \u0437\u0430\u0431\u044b\u043b \u043e\u0431\u043d\u043e\u0432\u0438\u0442\u044c \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044e. \u041a\u0430\u043a \u0432 \u0438\u0442\u043e\u0433\u0435, \u043d\u0430\u043f\u0438\u0441\u0430\u043b \u043f\u043b\u0430\u0433\u0438\u043d \u0434\u043b\u044f Swagger (\u0441\u043e \u0432\u0442\u043e\u0440\u043e\u0433\u043e \u0440\u0430\u0437\u0430). \u0418 \u043a\u0430\u043a \u0443\u0432\u043b\u0435\u043a\u0441\u044f \u044d\u0442\u0438\u043c \u0442\u0430\u043a, \u0447\u0442\u043e \u0437\u0430\u0431\u044b\u043b \u043f\u0440\u043e \u0441\u0432\u043e\u0439 \u0431\u043e\u043b\u044c\u043d\u0438\u0447\u043d\u044b\u0439 \u0438 \u043f\u043e\u0448\u0435\u043b \u043d\u0430 \u043f\u043e\u043f\u0440\u0430\u0432\u043a\u0443! <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/tc\/r_\/ox\/tcr_ox0au0jawbc0ugh48ssogeu.png\"><\/p>\n<p>  \u0410 \u0435\u0449\u0435 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043f\u0440\u043e Optional <b>\u043d\u0435<\/b> \u0438\u0437 Java 8.<\/p>\n<p>  <a name=\"habracut\"><\/a><br \/>  \u0414\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0438\u043d\u0442\u0435\u0440\u0430\u043a\u0442\u0438\u0432\u043d\u043e\u0439 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c <a href=\"https:\/\/swagger.io\">Swagger<\/a>.<br \/>  \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043a\u043e\u0433\u0434\u0430 \u0441\u043e\u0437\u0434\u0430\u0435\u0448\u044c \u043c\u0435\u0442\u043e\u0434 \u0432 API, \u0442\u043e:<br \/>  0. \u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0448\u044c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438, \u0442\u0438\u043f\u0430 @RequestMapping \u0438 \u043f\u0440\u043e\u0447\u0435\u0435.<br \/>  1. \u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0448\u044c @ErrorCodes (\u043d\u0430\u0448\u0430 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u0430\u044f \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044f), \u0438 \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u044f\u0435\u0448\u044c \u0441\u0442\u0440\u043e\u043a\u043e\u0432\u044b\u0435 \u043a\u043e\u0434\u044b \u043e\u0448\u0438\u0431\u043e\u043a, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0436\u0435\u0442 \u0432\u0435\u0440\u043d\u0443\u0442\u044c \u044d\u0442\u043e\u0442 \u043c\u0435\u0442\u043e\u0434 \u0432 \u043e\u0442\u0432\u0435\u0442\u0435.<br \/>  2. \u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0448\u044c @ApiOperation \u0438 \u0432 \u043f\u043e\u043b\u0435 notes \u0434\u0443\u0431\u043b\u0438\u0440\u0443\u0435\u0448\u044c \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e\u0431 \u044d\u0442\u0438\u0445 \u043e\u0448\u0438\u0431\u043a\u0430\u0445.<br \/>  3. \u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0448\u044c \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438\u2026<\/p>\n<p>  \u0412\u044b\u0433\u043b\u044f\u0434\u0435\u043b\u043e \u044d\u0442\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0432\u043e\u0442 \u0442\u0430\u043a (\u0443\u0431\u0440\u0430\u043b \u043b\u0438\u0448\u043d\u0435\u0435 \u0438 \u0443\u043f\u0440\u043e\u0441\u0442\u0438\u043b):  <\/p>\n<pre><code class=\"java\">@ApiOperation(     value = \"Some description.\",     notes = \"List of possible error codes:\" +             \"&lt;ul&gt;\" +             \"   &lt;li&gt;sms.verification.code.fail&lt;\/li&gt;\" +             \"&lt;\/ul&gt;\") @PostMapping(\"\/security\/confirmation\/check\") @ErrorCodes(values = {\"sms.verification.code.fail\"}) public ResponseDto check(@ApiParam @RequestBody @Valid RequestDto request) {... } <\/code><\/pre>\n<p>  \u0418\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u043e\u043c \u043c\u043e\u0435\u0433\u043e \u043f\u0440\u043e\u0432\u0430\u043b\u0430 \u0441\u0442\u0430\u043b \u043f\u0443\u043d\u043a\u0442 2, \u043a\u043e\u0433\u0434\u0430 \u044f \u0434\u043e\u0431\u0430\u0432\u0438\u043b @ErrorCodes, \u043d\u043e \u0437\u0430\u0431\u044b\u043b \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0438\u0442\u044c \u0441\u0442\u0440\u043e\u043a\u043e\u0432\u044b\u0435 \u043a\u043e\u0434\u044b \u043e\u0448\u0438\u0431\u043e\u043a \u0432 @ApiOperation. \u0414\u043e\u0432\u043e\u043b\u044c\u043d\u044b\u0439 \u0441\u043e\u0431\u043e\u0439, \u043d\u043e \u0441 \u043b\u0451\u0433\u043a\u0438\u043c \u0447\u0443\u0432\u0441\u0442\u0432\u043e\u043c \u0442\u0440\u0435\u0432\u043e\u0433\u0438 \u044f \u043e\u0442\u0434\u0430\u043b \u0441\u0432\u043e\u0439 Pull Request \u043d\u0430 Code Review. \u0418 \u0432\u043e\u0442 \u0442\u0443\u0442 \u043c\u043d\u0435 \u0441\u043e\u043e\u0431\u0449\u0438\u043b\u0438, \u0447\u0442\u043e \u044f \u0437\u0430\u0431\u044b\u043b \u043f\u0440\u043e notes! \u0410 \u0435\u0449\u0435 \u043e\u0431\u044a\u044f\u0441\u043d\u0438\u043b\u0438, \u0447\u0442\u043e Swagger \u043d\u0435 \u043f\u043e\u0434\u0445\u0432\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u0438\u0437 @ErrorCodes \u0438 \u0438\u043c\u0435\u043d\u043d\u043e \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0435\u0435 \u043f\u0440\u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u0432\u0440\u0443\u0447\u043d\u0443\u044e. \u0412 \u0442\u043e\u0442 \u0432\u0435\u0447\u0435\u0440 \u0432\u0441\u0451 \u0437\u0430\u043a\u043e\u043d\u0447\u0438\u043b\u043e\u0441\u044c \u0431\u043b\u0430\u0433\u043e\u043f\u043e\u043b\u0443\u0447\u043d\u043e. \u0418\u0441\u043f\u0440\u0430\u0432\u0438\u043b \u0441\u0432\u043e\u0439 \u043d\u0435\u0434\u043e\u0447\u0435\u0442 \u0438 \u0443\u0448\u0451\u043b \u043d\u0430 \u0431\u043e\u043b\u044c\u043d\u0438\u0447\u043d\u044b\u0439.<\/p>\n<p>  \u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u0431\u044b\u043b\u043e \u0431\u044b \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e \u0432\u0437\u044f\u0442\u044c \u0438 \u043f\u043e\u0439\u0442\u0438 \u0434\u0430\u043b\u044c\u0448\u0435. \u041f\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0441\u0435\u0431\u0435 \u0433\u0430\u043b\u043e\u0447\u043a\u0443 \u043d\u0430 \u043f\u043e\u043b\u043e\u0447\u043a\u0443 \u043a \u0434\u0440\u0443\u0433\u0438\u043c \u0442\u0430\u043a\u0438\u043c \u0436\u0435, \u0447\u0442\u043e \u043c\u043e\u043b, \u041c\u0430\u043a\u0441, \u0431\u0443\u0434\u044c \u0432\u043d\u0438\u043c\u0430\u0442\u0435\u043b\u044c\u043d\u0435\u0435, \u043e\u0431\u0440\u0430\u0449\u0430\u0439 \u043d\u0430 \u044d\u0442\u043e \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435\u2026<\/p>\n<p>  \u041d\u043e \u0443 \u043c\u0435\u043d\u044f \u043d\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c. \u0412\u0435\u0441\u044c \u0432\u0435\u0447\u0435\u0440 \u0438 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435 \u0443\u0442\u0440\u043e \u0431\u044b\u043b\u0438 \u043f\u043e\u0442\u0440\u0430\u0447\u0435\u043d\u044b \u043d\u0430 \u0442\u043e, \u0447\u0442\u043e\u0431\u044b \u043d\u0430\u0443\u0447\u0438\u0442\u044c Swagger \u0447\u0438\u0442\u0430\u0442\u044c \u043d\u0430\u0448\u0443 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044e \u0438 \u0441\u0430\u043c\u043e\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u043d\u043e \u0434\u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u0432 notes \u044d\u0442\u0438 \u0441\u0430\u043c\u044b\u0435 \u043a\u043e\u0434\u044b.<\/p>\n<h3>\u0414\u0435\u0439\u0441\u0442\u0432\u0438\u0435 1. \u0417\u0434\u0435\u0441\u044c \u043a\u0442\u043e-\u0442\u043e \u0431\u044b\u043b&#8230;<\/h3>\n<p>  \u0418\u0437 \u0431\u0435\u0433\u043b\u043e\u0433\u043e \u043f\u043e\u0438\u0441\u043a\u0430 \u0443\u0434\u0430\u043b\u043e\u0441\u044c \u0432\u044b\u044f\u0441\u043d\u0438\u0442\u044c, \u0447\u0442\u043e \u043a\u0442\u043e-\u0442\u043e \u0443\u0436\u0435 <a href=\"https:\/\/github.com\/springfox\/springfox\/issues\/2030\">\u043f\u044b\u0442\u0430\u043b\u0441\u044f<\/a> \u043f\u043e\u0434\u0440\u0443\u0436\u0438\u0442\u044c Swagger \u0441\u043e \u0441\u0432\u043e\u0435\u0439 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0435\u0439. \u0422\u0430\u043c \u0436\u0435 \u0431\u044b\u043b\u0430 \u0441\u0441\u044b\u043b\u043e\u0447\u043a\u0430 \u043d\u0430 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044e SpringFox \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0433\u043e\u0432\u043e\u0440\u0438\u043b\u043e\u0441\u044c \u043e \u0442\u043e\u043c, \u0447\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043f\u043b\u0430\u0433\u0438\u043d!<\/p>\n<p>  \u0421\u0447\u0430\u0441\u0442\u043b\u0438\u0432\u043e\u0435 \u0441\u0447\u0430\u0441\u0442\u044c\u0435 \u043d\u0430\u043a\u0440\u044b\u043b\u043e \u043c\u0435\u043d\u044f \u043d\u0430\u0441\u0442\u043e\u043b\u044c\u043a\u043e, \u0447\u0442\u043e \u0434\u0430\u0436\u0435 \u0437\u0430\u0431\u044b\u043b \u043e \u043f\u0440\u043e\u0441\u0442\u0443\u0434\u0435 \u0438 \u0431\u043e\u043b\u044c\u043d\u0438\u0447\u043d\u043e\u043c! \u0412 \u0441\u0432\u043e\u0435\u0439 \u0431\u0443\u0434\u0443\u0449\u0435\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 <b>\u00ab\u041a\u0430\u043a \u0442\u0440\u0438 \u0440\u0430\u0437\u0430 \u043d\u0435 \u0443\u0432\u043e\u043b\u0438\u0442\u044c\u0441\u044f \u0438\u0437 \u043a\u043e\u043c\u043f\u0430\u043d\u0438\u0438\u00bb<\/b> \u044f \u0434\u0435\u043b\u044e\u0441\u044c \u0442\u0440\u0435\u043c\u044f \u0438\u0441\u0442\u043e\u0440\u0438\u044f\u043c\u0438 \u0441\u043f\u0430\u0441\u0435\u043d\u0438\u044f \u0443\u0442\u043e\u043f\u0430\u044e\u0449\u0438\u0445. \u041e\u0434\u043d\u0430 \u0438\u0437 \u043d\u0438\u0445 \u043e \u0442\u043e\u043c, \u043a\u0430\u043a \u043c\u043d\u0435 \u0443\u0434\u0430\u043b\u043e\u0441\u044c \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043f\u043b\u0430\u0433\u0438\u043d \u0434\u043b\u044f Chrome + Firefox, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0440\u0430\u0437 \u0443\u0441\u043a\u043e\u0440\u044f\u043b \u0440\u0430\u0431\u043e\u0442\u0443 \u0441 Jenkins. \u041c\u043d\u0435 \u0431\u044b\u043b\u043e \u0442\u0430\u043a \u043f\u0440\u0438\u043a\u043e\u043b\u044c\u043d\u043e \u0435\u0433\u043e \u043f\u0438\u0441\u0430\u0442\u044c! \u0412\u0435\u0434\u044c \u044d\u0442\u043e \u043c\u0438\u043a\u0440\u043e\u043f\u0440\u043e\u0435\u043a\u0442! \u041c\u043e\u0439 \u0441\u0430\u043c\u044b\u0439-\u0441\u0430\u043c\u044b\u0439 \u043f\u0440\u043e\u0441\u0442\u0435\u043d\u044c\u043a\u0438\u0439 \u0441\u0442\u0430\u0440\u0442\u0430\u043f, \u043d\u043e \u0441 \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u043c\u0438 \u043b\u044e\u0434\u044c\u043c\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438\u043c \u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f. \u0422\u043e\u0433\u0434\u0430 \u044f \u0432\u043d\u043e\u0432\u044c \u0432\u044b\u0431\u0440\u0430\u043b\u0441\u044f \u0438\u0437 \u0440\u0443\u0442\u0438\u043d\u044b \u0438 \u043e\u0431\u0440\u0435\u043b \u0432\u0434\u043e\u0445\u043d\u043e\u0432\u0435\u043d\u0438\u0435. \u0412\u044b\u0433\u043e\u0440\u0430\u043d\u0438\u0435 \u0443\u0448\u043b\u043e. \u041d\u043e \u043e\u0431 \u044d\u0442\u043e\u043c \u043b\u0443\u0447\u0448\u0435 \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0443 \u0432 \u0431\u0443\u0434\u0443\u0449\u0435\u0439 \u0441\u0442\u0430\u0442\u044c\u0435. \u0410 \u043f\u043e\u043a\u0430 \u0432\u0435\u0440\u043d\u0435\u043c\u0441\u044f \u043a \u043f\u043b\u0430\u0433\u0438\u043d\u0443 \u0434\u043b\u044f Swagger.<\/p>\n<h3>\u0414\u0435\u0439\u0441\u0442\u0432\u0438\u0435 2. \u0420\u0430\u0431\u043e\u0442\u0430\u0435\u0442!<\/h3>\n<p>  \u041d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0447\u0442\u043e-\u0442\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0449\u0435\u0435 \u043e\u043a\u0430\u0437\u0430\u043b\u043e\u0441\u044c \u043b\u0435\u0433\u043a\u043e. \u0412\u0437\u044f\u043b \u043f\u0440\u0438\u043c\u0435\u0440 \u043f\u043b\u0430\u0433\u0438\u043d\u0430 \u0438\u0437 \u043e\u0444\u0438\u0446\u0438\u0430\u043b\u044c\u043d\u043e\u0439 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 SpringFox, \u0443\u0431\u0440\u0430\u043b \u0432\u0441\u0451 \u043b\u0438\u0448\u043d\u0435\u0435 \u0438 \u0434\u043e\u0431\u0430\u0432\u0438\u043b \u043d\u0443\u0436\u043d\u043e\u0435.  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041f\u043b\u0430\u0433\u0438\u043d. \u0412\u0435\u0440\u0441\u0438\u044f 1<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"java\">@Component @Order(SwaggerPluginSupport.SWAGGER_PLUGIN_ORDER + 1) public class SwaggerErrorCodesConfiguration implements OperationBuilderPlugin {      \/**      * Appends note of operation. Adds error codes to note of operation.      * &lt;code&gt;      *     &lt;h3&gt;List of possible errors:&lt;\/h3&gt;      *     &lt;ul&gt;      *         &lt;li&gt;error.code.1&lt;\/li&gt;      *         &lt;li&gt;error.code.2&lt;\/li&gt;      *         &lt;li&gt;error.code.3&lt;\/li&gt;      *     &lt;\/ul&gt;      * &lt;\/code&gt;      * @param context operation context      *\/     @Override     public void apply(OperationContext context) {         Method operationMethod = context.getHandlerMethod().getMethod();          \/\/ Check method is annotated by @ErrorCodes         ErrorCodes errorCodes = findAnnotation(operationMethod, ErrorCodes.class);         if (errorCodes == null) {             return;         }          StringBuilder errorCodesNote = new StringBuilder();         errorCodesNote.append(\"&lt;h3&gt;List of possible errors:&lt;\/h3&gt;\");         errorCodesNote.append(\"&lt;ul&gt;\");          for (String errorCode: errorCodes.values()) {             errorCodesNote.append(\"&lt;li&gt;\").append(errorCode).append(\"&lt;\/li&gt;\");         }          errorCodesNote.append(\"&lt;\/ul&gt;\");          \/\/ Write new version of notes.         context.operationBuilder().notes(errorCodesNote.toString()).build();     }      @Override     public boolean supports(DocumentationType delimiter) {         return SwaggerPluginSupport.pluginDoesApply(delimiter);     }  } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u0422\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u044f \u043d\u0430\u0447\u0430\u043b \u0441 \u043c\u0435\u0442\u043e\u0434\u0430 \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043d\u0435 \u0443\u043a\u0430\u0437\u0430\u043d\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0434\u043b\u044f notes \u0432 @ApiOperation.  <\/p>\n<pre><code class=\"java\">@ApiOperation(value = \"Some description.\") @PostMapping(\"\/security\/confirmation\/check\") @ErrorCodes(values = {\"sms.verification.code.fail\"}) public ResponseDto check(@ApiParam @RequestBody @Valid RequestDto request) { ... } <\/code><\/pre>\n<p>  \u0417\u0430\u043f\u0443\u0441\u043a \u0438\u2026 \u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442! \u0423\u0440\u0430, \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442! \u0421\u0442\u0440\u043e\u043a\u043e\u0432\u044b\u0439 \u043a\u043e\u0434 <b>sms.verification.code.fail<\/b> \u043f\u043e\u044f\u0432\u0438\u043b\u0441\u044f \u0432 notes!<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/es\/hy\/eb\/eshyeb-3rgb9ctzrn4yki4strgc.png\"><\/p>\n<h3>\u0414\u0435\u0439\u0441\u0442\u0432\u0438\u0435 3. \u0420\u0430\u0431\u043e\u0442\u0430\u0435\u0442, \u043d\u043e \u043d\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442.<\/h3>\n<p>  \u041f\u043e\u0442\u043e\u043c \u044f \u0434\u043e\u0431\u0430\u0432\u0438\u043b \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u043b\u043e\u0432 \u0432 notes \u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0441\u044f \u0432\u043e\u0442 \u0442\u0430\u043a\u043e\u0439 \u043a\u043e\u0434:  <\/p>\n<pre><code class=\"java\">@ApiOperation(value = \"Some description.\", notes = \"Some initial note.\") @PostMapping(\"\/security\/confirmation\/check\") @ErrorCodes(values = {\"sms.verification.code.fail\"}) public ResponseDto check(@ApiParam @RequestBody @Valid RequestDto request) { ... } <\/code><\/pre>\n<p>  \u0417\u0430\u043f\u0443\u0441\u0442\u0438\u043b \u0441\u043d\u043e\u0432\u0430. \u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043e\u043a\u0430\u0437\u0430\u043b\u0441\u044f\u2026 \u043d\u0435\u043e\u0436\u0438\u0434\u0430\u043d\u043d\u044b\u043c. SpringFox \u043f\u043b\u0430\u0433\u0438\u043d \u043f\u0435\u0440\u0435\u0437\u0430\u043f\u0438\u0441\u0430\u043b \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 notes \u043f\u0440\u0438 \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 (\u041e_\u043e)!<\/p>\n<p>  \u0421\u043c\u043e\u0442\u0440\u044e \u043a\u0430\u043a \u0443\u0441\u0442\u0440\u043e\u0435\u043d <b>context.operationBuilder().notes(String)<\/b> \u0438 \u0432\u0438\u0436\u0443 \u0442\u0430\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435:  <\/p>\n<pre><code class=\"java\">public OperationBuilder notes(String notes) {     this.notes = (String)BuilderDefaults.defaultIfAbsent(notes, this.notes);     return this; } <\/code><\/pre>\n<p>  \u042d\u043c\u2026 \u041e\u043a, \u0442\u043e\u0433\u0434\u0430 \u0431\u0443\u0434\u0435\u043c \u0431\u0440\u0430\u0442\u044c \u0442\u0435\u043a\u0443\u0449\u0435\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 notes \u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c error codes. \u041e\u0441\u0442\u0430\u0435\u0442\u0441\u044f \u0434\u043e\u0441\u0442\u0430\u0442\u044c \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044e @ApiOperation, \u0432\u0437\u044f\u0442\u044c \u043d\u0443\u0436\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0438 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043a \u0442\u043e\u043c\u0443, \u0447\u0442\u043e \u0444\u043e\u0440\u043c\u0438\u0440\u0443\u044e \u0441\u0430\u043c.<\/p>\n<p>  \u0418\u0442\u0430\u043a, \u0444\u0438\u043d\u0430\u043b\u044c\u043d\u0430\u044f \u0432\u0435\u0440\u0441\u0438\u044f (<a href=\"https:\/\/gist.github.com\/atygaev\/f75fae1b8ac5215ade1143d5bdaa63dc\">\u0434\u043e\u0441\u0442\u0443\u043f\u043d\u0430\u044f \u043d\u0430 gist.github.com<\/a>)  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041f\u043b\u0430\u0433\u0438\u043d. \u0412\u0435\u0440\u0441\u0438\u044f 2<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"java\">@Component @Order(SwaggerPluginSupport.SWAGGER_PLUGIN_ORDER + 1) public class SwaggerErrorCodesConfiguration implements OperationBuilderPlugin {      \/**      * Appends note of operation. Adds error codes to note of operation.      * &lt;code&gt;      *     &lt;h3&gt;List of possible errors:&lt;\/h3&gt;      *     &lt;ul&gt;      *         &lt;li&gt;error.code.1&lt;\/li&gt;      *         &lt;li&gt;error.code.2&lt;\/li&gt;      *         &lt;li&gt;error.code.3&lt;\/li&gt;      *     &lt;\/ul&gt;      * &lt;\/code&gt;      * @param context operation context      *\/     @Override     public void apply(OperationContext context) {         Method operationMethod = context.getHandlerMethod().getMethod();          \/\/ Check method is annotated by @ApiOperation         ApiOperation apiOperation = findApiOperationAnnotation(operationMethod).orNull();         if (apiOperation == null) {             return;         }          \/\/ Check method is annotated by @ErrorCodes         ErrorCodes errorCodes = findAnnotation(operationMethod, ErrorCodes.class);         if (errorCodes == null) {             return;         }          \/\/ Prepend notes by using current value of notes in @ApiOperation         StringBuilder errorCodesNote = new StringBuilder(apiOperation.notes());         errorCodesNote.append(\"&lt;h3&gt;List of possible errors:&lt;\/h3&gt;\");         errorCodesNote.append(\"&lt;ul&gt;\");          for (String errorCode: errorCodes.values()) {             errorCodesNote.append(\"&lt;li&gt;\").append(errorCode).append(\"&lt;\/li&gt;\");         }          errorCodesNote.append(\"&lt;\/ul&gt;\");          \/\/ Write new version of notes.         context.operationBuilder().notes(errorCodesNote.toString()).build();     }      @Override     public boolean supports(DocumentationType delimiter) {         return SwaggerPluginSupport.pluginDoesApply(delimiter);     } } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c \u043a\u0430\u043a \u043d\u0430\u0434\u043e!<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/nt\/7q\/be\/nt7qbel09ikjwifcwq8zxj8j9wi.png\"><\/p>\n<h3>\u0414\u0435\u0439\u0441\u0442\u0432\u0438\u0435 4. \u0427\u0442\u043e \u0442\u0430\u043c \u043f\u0440\u043e Optional \u043d\u0435 \u0438\u0437 Java 8?<\/h3>\n<p>  \u0412 \u0441\u0430\u043c\u043e\u043c \u043d\u0430\u0447\u0430\u043b\u0435 \u0440\u0430\u0431\u043e\u0442\u044b \u043d\u0430\u0434 \u043f\u043b\u0430\u0433\u0438\u043d\u043e\u043c \u043d\u0435 \u043c\u043e\u0433 \u043f\u043e\u043d\u044f\u0442\u044c \u0447\u0442\u043e \u043d\u0435 \u0442\u0430\u043a \u0441 \u0442\u0435\u043c Optional, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u043f\u0440\u0438 \u043f\u043e\u0438\u0441\u043a\u0435 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438. \u0423 \u044d\u0442\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 \u043d\u0435 \u0431\u044b\u043b\u043e \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432, \u043a \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u043f\u0440\u0438\u0432\u044b\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u044f \u0441 <a href=\"https:\/\/docs.oracle.com\/javase\/8\/docs\/api\/java\/util\/Optional.html\">java.util.Optional<\/a>. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043d\u0435\u0442 \u043c\u0435\u0442\u043e\u0434\u0430 <b>ifPresent<\/b>, \u0437\u0430\u0442\u043e \u0435\u0441\u0442\u044c \u043c\u0435\u0442\u043e\u0434 <b>orNull<\/b>.<br \/>  \u0412\u044b\u044f\u0441\u043d\u0438\u043b\u043e\u0441\u044c, \u0447\u0442\u043e SpringFox \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 <a href=\"https:\/\/google.github.io\/guava\/releases\/19.0\/api\/docs\/com\/google\/common\/base\/Optional.html\">Optional<\/a> \u0438\u0437 <a href=\"https:\/\/github.com\/google\/guava\">Guava<\/a>.<\/p>\n<h2>TL;DR<\/h2>\n<p>  \u041d\u0430\u043f\u0438\u0441\u0430\u043b \u043f\u043b\u0430\u0433\u0438\u043d \u0434\u043b\u044f SpringFox, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f Spring \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u043c \u0438 \u043d\u0430 \u044d\u0442\u0430\u043f\u0435 \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0447\u0442\u0435\u043d\u0438\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0438\u0437 \u043d\u0430\u0448\u0435\u0439 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438 @ErrorCodes.<br \/>  \u041f\u043b\u0430\u0433\u0438\u043d \u0434\u043e\u0441\u0442\u0443\u043f\u0435\u043d \u043d\u0430 <a href=\"https:\/\/gist.github.com\/atygaev\/f75fae1b8ac5215ade1143d5bdaa63dc\">gist.github.com<\/a>.<\/div>\n<p>        <script class=\"js-mediator-script\">!function(e){function t(t,n){if(!(n in e)){for(var r,a=e.document,i=a.scripts,o=i.length;o--;)if(-1!==i[o].src.indexOf(t)){r=i[o];break}if(!r){r=a.createElement(\"script\"),r.type=\"text\/javascript\",r.async=!0,r.defer=!0,r.src=t,r.charset=\"UTF-8\";var d=function(){var e=a.getElementsByTagName(\"script\")[0];e.parentNode.insertBefore(r,e)};\"[object Opera]\"==e.opera?a.addEventListener?a.addEventListener(\"DOMContentLoaded\",d,!1):e.attachEvent(\"onload\",d):d()}}}t(\"\/\/mediator.mail.ru\/script\/2820404\/\",\"_mediator\")}(window);<\/script>     <br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/post\/420841\/\"> https:\/\/habr.com\/post\/420841\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div data-io-article-url=\"https:\/\/habr.com\/post\/420841\/\" class=\"post__text post__text-html js-mediator-article\">\u0421\u043b\u0443\u0447\u0430\u043b\u043e\u0441\u044c \u043b\u0438 \u0432\u0430\u043c \u043d\u0430\u043b\u0430\u0436\u0430\u0442\u044c \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u0445\u043e\u0442\u0444\u0438\u043a\u0441\u0430 \u0432 \u043c\u0430\u0441\u0442\u0435\u0440? \u041d\u0435\u0442?! \u0410 \u0432\u043e\u0442 \u043c\u043d\u0435 \u0443\u0434\u0430\u043b\u043e\u0441\u044c!<br \/>  \u042d\u0442\u0430 \u0438\u0441\u0442\u043e\u0440\u0438\u044f \u043e \u0442\u043e\u043c, \u043a\u0430\u043a \u044f \u0437\u0430\u0431\u044b\u043b \u043e\u0431\u043d\u043e\u0432\u0438\u0442\u044c \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044e. \u041a\u0430\u043a \u0432 \u0438\u0442\u043e\u0433\u0435, \u043d\u0430\u043f\u0438\u0441\u0430\u043b \u043f\u043b\u0430\u0433\u0438\u043d \u0434\u043b\u044f Swagger (\u0441\u043e \u0432\u0442\u043e\u0440\u043e\u0433\u043e \u0440\u0430\u0437\u0430). \u0418 \u043a\u0430\u043a \u0443\u0432\u043b\u0435\u043a\u0441\u044f \u044d\u0442\u0438\u043c \u0442\u0430\u043a, \u0447\u0442\u043e \u0437\u0430\u0431\u044b\u043b \u043f\u0440\u043e \u0441\u0432\u043e\u0439 \u0431\u043e\u043b\u044c\u043d\u0438\u0447\u043d\u044b\u0439 \u0438 \u043f\u043e\u0448\u0435\u043b \u043d\u0430 \u043f\u043e\u043f\u0440\u0430\u0432\u043a\u0443! <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/tc\/r_\/ox\/tcr_ox0au0jawbc0ugh48ssogeu.png\"><\/p>\n<p>  \u0410 \u0435\u0449\u0435 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043f\u0440\u043e Optional <b>\u043d\u0435<\/b> \u0438\u0437 Java 8.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-288339","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/288339","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=288339"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/288339\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=288339"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=288339"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=288339"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}