diff options
author | Vitaly Takmazov | 2023-01-13 17:38:06 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2023-01-13 18:11:56 +0300 |
commit | 35d25bbc9d261e7b5585d0fd1d398dff3ab4a176 (patch) | |
tree | 68a4d0b0190635615438343f6f6c52cacc213179 /src/main/java/com/juick/www/controllers | |
parent | 8b70eded6c9cc3b9cf634356239701fe65779791 (diff) |
Fix OpenAPI generation
* Use HandlerMethodArgumentResolver to pass visitor
* Hide visitor from OpenAPI definitions
* Drop unused AsciiDoc template
Diffstat (limited to 'src/main/java/com/juick/www/controllers')
5 files changed, 24 insertions, 20 deletions
diff --git a/src/main/java/com/juick/www/controllers/Help.java b/src/main/java/com/juick/www/controllers/Help.java index 32d96a53..ec60d7df 100644 --- a/src/main/java/com/juick/www/controllers/Help.java +++ b/src/main/java/com/juick/www/controllers/Help.java @@ -21,6 +21,7 @@ import com.juick.model.User; import com.juick.util.HttpNotFoundException; import com.juick.service.HelpService; import com.juick.www.WebApp; +import io.swagger.v3.oas.annotations.Parameter; import org.commonmark.parser.Parser; import org.commonmark.renderer.html.HtmlRenderer; import org.springframework.stereotype.Controller; @@ -49,7 +50,7 @@ public class Help { @GetMapping({"/help/", "/help", "/help/{langOrPage}", "/help/{lang}/{page}"}) public String showHelp( - @ModelAttribute User visitor, + @Parameter(hidden = true) User visitor, Locale locale, @PathVariable(required = false, name = "lang") String lang, @PathVariable(required = false, name = "page") String page, diff --git a/src/main/java/com/juick/www/controllers/Settings.java b/src/main/java/com/juick/www/controllers/Settings.java index f2cd4aa9..bc6b6614 100644 --- a/src/main/java/com/juick/www/controllers/Settings.java +++ b/src/main/java/com/juick/www/controllers/Settings.java @@ -38,6 +38,7 @@ import com.juick.util.HttpBadRequestException; import com.juick.util.HttpUtils; import com.juick.www.WebApp; +import io.swagger.v3.oas.annotations.Parameter; import jakarta.mail.Message; import jakarta.mail.MessagingException; import jakarta.mail.Session; @@ -88,7 +89,7 @@ public class Settings { @GetMapping("/settings") protected String doGet( - @ModelAttribute User visitor, + @Parameter(hidden = true) User visitor, Locale locale, @RequestParam(required = false, defaultValue = "main") String page, @RequestParam(required = false) String code, ModelMap model) { @@ -125,7 +126,7 @@ public class Settings { @PostMapping("/settings") protected String doPost( - @ModelAttribute User visitor, + @Parameter(hidden = true) User visitor, HttpServletRequest request, HttpServletResponse response, @RequestParam(required = false) MultipartFile newAvatar, ModelMap model) @@ -271,7 +272,7 @@ public class Settings { } @PostMapping("/settings/unsubscribe") public String unsubscribeOneClick( - @ModelAttribute User user, + User user, @RequestParam(name = "List-Unsubscribe") String unsubscribe, ModelMap model) { if (!user.isAnonymous()) { diff --git a/src/main/java/com/juick/www/controllers/SignUp.java b/src/main/java/com/juick/www/controllers/SignUp.java index b746c09b..87182ebd 100644 --- a/src/main/java/com/juick/www/controllers/SignUp.java +++ b/src/main/java/com/juick/www/controllers/SignUp.java @@ -24,6 +24,7 @@ import com.juick.www.WebApp; import com.juick.service.EmailService; import com.juick.service.UserService; import com.juick.service.security.entities.JuickUser; +import io.swagger.v3.oas.annotations.Parameter; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import org.springframework.security.authentication.RememberMeAuthenticationToken; @@ -58,7 +59,7 @@ public class SignUp { @GetMapping("/signup") protected String doGet( - @ModelAttribute User visitor, + @Parameter(hidden = true) User visitor, @RequestParam String type, @RequestParam String hash, ModelMap model) { if (hash.length() > 36 || !type.matches("^[a-zA-Z0-9\\-]+$") || !hash.matches("^[a-zA-Z0-9\\-]+$")) { @@ -99,7 +100,7 @@ public class SignUp { protected String doPost( HttpServletRequest request, HttpServletResponse response, - @ModelAttribute User visitor, + @Parameter(hidden = true) User visitor, @RequestParam String type, @RequestParam String hash, @RequestParam String action, diff --git a/src/main/java/com/juick/www/controllers/Site.java b/src/main/java/com/juick/www/controllers/Site.java index 217bb798..f4f8f744 100644 --- a/src/main/java/com/juick/www/controllers/Site.java +++ b/src/main/java/com/juick/www/controllers/Site.java @@ -26,6 +26,7 @@ import com.juick.util.WebUtils; import com.juick.www.WebApp; import com.juick.www.api.activity.model.Context; +import io.swagger.v3.oas.annotations.Parameter; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpSession; @@ -79,7 +80,7 @@ public class Site { @Value("${telegram_botname:Juick_bot}") private String tgBot; - private void fillUserModel(ModelMap model, User user, User visitor) { + private void fillUserModel(ModelMap model, User user, @Parameter(hidden = true) User visitor) { user.setAvatar(webApp.getAvatarWebPath(user)); model.addAttribute("user", user); model.addAttribute("isSubscribed", userService.isSubscribed(visitor.getUid(), user.getUid())); @@ -98,7 +99,7 @@ public class Site { } @GetMapping("/login") - public String getloginForm(@ModelAttribute User visitor, + public String getloginForm(@Parameter(hidden = true) User visitor, @RequestParam(name = "retpath", required = false, defaultValue = "/") String retPath, HttpSession session, ModelMap model) { @@ -126,7 +127,7 @@ public class Site { } @GetMapping("/") - protected String doGet(@ModelAttribute User visitor, Locale locale, @RequestParam(required = false) String tag, + protected String doGet(@Parameter(hidden = true) User visitor, Locale locale, @RequestParam(required = false) String tag, @RequestParam(name = "show", required = false) String paramShow, @RequestParam(name = "search", required = false) String paramSearch, @RequestParam(name = "before", required = false, defaultValue = "0") Integer paramBefore, @@ -218,7 +219,7 @@ public class Site { } @GetMapping(path = "/{uname}/", headers = "Connection!=Upgrade") - protected String doGetBlog(@ModelAttribute User visitor, @RequestParam(required = false, name = "show") String paramShow, + protected String doGetBlog(@Parameter(hidden = true) User visitor, @RequestParam(required = false, name = "show") String paramShow, @RequestParam(required = false, name = "tag") String paramTagStr, @RequestParam(required = false, name = "search") String paramSearch, @RequestParam(required = false, name = "page", defaultValue = "0") Integer page, @PathVariable String uname, @@ -325,7 +326,7 @@ public class Site { } @GetMapping("/{uname}/tags") - protected String doGetTags(@ModelAttribute User visitor, @PathVariable String uname, ModelMap model) { + protected String doGetTags(@Parameter(hidden = true) User visitor, @PathVariable String uname, ModelMap model) { User user = userService.getUserByName(uname); if (visitor.isBanned()) { throw new HttpNotFoundException(); @@ -345,7 +346,7 @@ public class Site { } @GetMapping("/{uname}/friends") - protected String doGetFriends(@ModelAttribute User visitor, @PathVariable String uname, ModelMap model) { + protected String doGetFriends(@Parameter(hidden = true) User visitor, @PathVariable String uname, ModelMap model) { User user = userService.getUserByName(uname); if (visitor.isBanned()) { throw new HttpNotFoundException(); @@ -361,7 +362,7 @@ public class Site { } @GetMapping("/{uname}/readers") - protected String doGetReaders(@ModelAttribute User visitor, @PathVariable String uname, ModelMap model) { + protected String doGetReaders(@Parameter(hidden = true) User visitor, @PathVariable String uname, ModelMap model) { User user = userService.getUserByName(uname); visitor.setAvatar(webApp.getAvatarWebPath(visitor)); model.addAttribute("title", "Читатели " + user.getName()); @@ -374,7 +375,7 @@ public class Site { } @GetMapping("/{uname}/bl") - protected String doGetBL(@ModelAttribute User visitor, @PathVariable String uname, ModelMap model) { + protected String doGetBL(@Parameter(hidden = true) User visitor, @PathVariable String uname, ModelMap model) { User user = userService.getUserByName(uname); if (visitor.getUid() != user.getUid()) { throw new HttpForbiddenException(); @@ -390,7 +391,7 @@ public class Site { } @GetMapping("/tag/{tagName}") - protected String tagAction(@ModelAttribute User visitor, HttpServletRequest request, @PathVariable String tagName, + protected String tagAction(@Parameter(hidden = true) User visitor, HttpServletRequest request, @PathVariable String tagName, @RequestParam(required = false, defaultValue = "0") int before, ModelMap model) { visitor.setAvatar(webApp.getAvatarWebPath(visitor)); String paramTagStr = StringEscapeUtils.unescapeHtml4(tagName); @@ -453,7 +454,7 @@ public class Site { } @GetMapping("/pm/inbox") - protected String doGetInbox(@ModelAttribute User visitor, ModelMap model) { + protected String doGetInbox(@Parameter(hidden = true) User visitor, ModelMap model) { visitor.setAvatar(webApp.getAvatarWebPath(visitor)); String title = "PM: Inbox"; List<Message> msgs = chatService.getInbox(visitor.getUid()); @@ -467,7 +468,7 @@ public class Site { } @GetMapping("/pm/sent") - protected String doGetSent(@ModelAttribute User visitor, @RequestParam(required = false) String uname, ModelMap model) { + protected String doGetSent(@Parameter(hidden = true) User visitor, @RequestParam(required = false) String uname, ModelMap model) { visitor.setAvatar(webApp.getAvatarWebPath(visitor)); String title = "PM: Sent"; List<Message> msgs = chatService.getOutbox(visitor.getUid()); @@ -492,7 +493,7 @@ public class Site { } @GetMapping(value = "/{uname}/{mid}", produces = { MediaType.TEXT_HTML_VALUE, MediaType.ALL_VALUE }) - protected String threadAction(@ModelAttribute User visitor, ModelMap model, @PathVariable String uname, + protected String threadAction(@Parameter(hidden = true) User visitor, ModelMap model, @PathVariable String uname, @PathVariable int mid, @CookieValue(name = "sape_cookie", required = false, defaultValue = StringUtils.EMPTY) String sapeCookie) { if (!messagesService.canViewThread(mid, visitor.getUid())) { @@ -585,7 +586,7 @@ public class Site { } @GetMapping("/post") - protected String postAction(@ModelAttribute User visitor, @RequestParam(required = false) String body, ModelMap model) { + protected String postAction(@Parameter(hidden = true) User visitor, @RequestParam(required = false) String body, ModelMap model) { fillUserModel(model, visitor, visitor); visitor.setAvatar(webApp.getAvatarWebPath(visitor)); model.addAttribute("title", "Написать"); diff --git a/src/main/java/com/juick/www/controllers/SocialLogin.java b/src/main/java/com/juick/www/controllers/SocialLogin.java index 4e26ab99..b43b65c6 100644 --- a/src/main/java/com/juick/www/controllers/SocialLogin.java +++ b/src/main/java/com/juick/www/controllers/SocialLogin.java @@ -193,7 +193,7 @@ public class SocialLogin { } @GetMapping("/_twitter") - protected void doTwitterLogin(@ModelAttribute com.juick.model.User user, HttpServletRequest request, + protected void doTwitterLogin(com.juick.model.User user, HttpServletRequest request, HttpServletResponse response) throws IOException, ExecutionException, InterruptedException { String hash = StringUtils.EMPTY, request_token = StringUtils.EMPTY, request_token_secret = StringUtils.EMPTY; String verifier = request.getParameter("oauth_verifier"); |