Swagger docs
All checks were successful
Deploy App / docker (ubuntu-latest, 2.44.0, 17, 3.8.5) (push) Successful in 1m53s

This commit is contained in:
Braydon 2024-04-10 06:12:05 -04:00
parent b6ebe767ee
commit a4a3486341
2 changed files with 21 additions and 8 deletions

@ -23,6 +23,7 @@
*/ */
package me.braydon.mc.controller; package me.braydon.mc.controller;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.NonNull; import lombok.NonNull;
import lombok.extern.log4j.Log4j2; import lombok.extern.log4j.Log4j2;
@ -69,8 +70,9 @@ public final class PlayerController {
*/ */
@GetMapping("/{query}") @GetMapping("/{query}")
@ResponseBody @ResponseBody
public ResponseEntity<CachedPlayer> getPlayer(@PathVariable @NonNull String query) public ResponseEntity<CachedPlayer> getPlayer(
throws BadRequestException, ResourceNotFoundException, MojangRateLimitException { @Parameter(description = "The player username or UUID to get", example = "Rainnny") @PathVariable @NonNull String query
) throws BadRequestException, ResourceNotFoundException, MojangRateLimitException {
return ResponseEntity.ofNullable(mojangService.getPlayer(query, false)); return ResponseEntity.ofNullable(mojangService.getPlayer(query, false));
} }
@ -92,8 +94,11 @@ public final class PlayerController {
*/ */
@GetMapping(value = "/{partName}/{query}.{extension}", produces = { MediaType.IMAGE_PNG_VALUE, MediaType.IMAGE_JPEG_VALUE }) @GetMapping(value = "/{partName}/{query}.{extension}", produces = { MediaType.IMAGE_PNG_VALUE, MediaType.IMAGE_JPEG_VALUE })
@ResponseBody @ResponseBody
public ResponseEntity<byte[]> getPartTexture(@PathVariable @NonNull String partName, @PathVariable @NonNull String query, public ResponseEntity<byte[]> getPartTexture(
@PathVariable @NonNull String extension, @RequestParam(required = false) String size @Parameter(description = "The skin part to get the texture of", example = "head") @PathVariable @NonNull String partName,
@Parameter(description = "The player username or UUID to get", example = "Rainnny") @PathVariable @NonNull String query,
@Parameter(description = "The image extension", example = "png") @PathVariable @NonNull String extension,
@Parameter(description = "The size to scale the skin part texture to", example = "256") @RequestParam(required = false) String size
) throws BadRequestException { ) throws BadRequestException {
return ResponseEntity.ok() return ResponseEntity.ok()
.contentType(extension.equalsIgnoreCase("png") ? MediaType.IMAGE_PNG : MediaType.IMAGE_JPEG) .contentType(extension.equalsIgnoreCase("png") ? MediaType.IMAGE_PNG : MediaType.IMAGE_JPEG)

@ -23,6 +23,7 @@
*/ */
package me.braydon.mc.controller; package me.braydon.mc.controller;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.NonNull; import lombok.NonNull;
import lombok.extern.log4j.Log4j2; import lombok.extern.log4j.Log4j2;
@ -72,8 +73,10 @@ public final class ServerController {
*/ */
@GetMapping("/{platform}/{hostname}") @GetMapping("/{platform}/{hostname}")
@ResponseBody @ResponseBody
public ResponseEntity<CachedMinecraftServer> getServer(@PathVariable @NonNull String platform, @PathVariable @NonNull String hostname, public ResponseEntity<CachedMinecraftServer> getServer(
@RequestParam(required = false) String port @Parameter(description = "The platform of the server", example = "java") @PathVariable @NonNull String platform,
@Parameter(description = "The hostname of the server", example = "hypixel.net") @PathVariable @NonNull String hostname,
@Parameter(description = "The port of the server", example = "25565") @RequestParam(required = false) String port
) throws BadRequestException, ResourceNotFoundException { ) throws BadRequestException, ResourceNotFoundException {
return ResponseEntity.ofNullable(mojangService.getMinecraftServer(platform, hostname, port)); return ResponseEntity.ofNullable(mojangService.getMinecraftServer(platform, hostname, port));
} }
@ -87,7 +90,9 @@ public final class ServerController {
*/ */
@GetMapping("/blocked/{hostname}") @GetMapping("/blocked/{hostname}")
@ResponseBody @ResponseBody
public ResponseEntity<Map<String, Object>> isServerBlocked(@PathVariable @NonNull String hostname) { public ResponseEntity<Map<String, Object>> isServerBlocked(
@Parameter(description = "The hostname of the server", example = "hypixel.net") @PathVariable @NonNull String hostname
) {
return ResponseEntity.ok(Map.of( return ResponseEntity.ok(Map.of(
"blocked", mojangService.isServerBlocked(hostname) "blocked", mojangService.isServerBlocked(hostname)
)); ));
@ -103,7 +108,10 @@ public final class ServerController {
*/ */
@GetMapping(value = "/icon/{hostname}", produces = MediaType.IMAGE_PNG_VALUE) @GetMapping(value = "/icon/{hostname}", produces = MediaType.IMAGE_PNG_VALUE)
@ResponseBody @ResponseBody
public ResponseEntity<byte[]> getServerFavicon(@PathVariable @NonNull String hostname, @RequestParam(required = false) String port) { public ResponseEntity<byte[]> getServerFavicon(
@Parameter(description = "The hostname of the server", example = "hypixel.net") @PathVariable @NonNull String hostname,
@Parameter(description = "The port of the server", example = "25565") @RequestParam(required = false) String port
) {
return ResponseEntity.ok() return ResponseEntity.ok()
.contentType(MediaType.IMAGE_PNG) .contentType(MediaType.IMAGE_PNG)
.header(HttpHeaders.CONTENT_DISPOSITION, "inline; filename=%s.png".formatted(hostname)) .header(HttpHeaders.CONTENT_DISPOSITION, "inline; filename=%s.png".formatted(hostname))