Implement SwaggerAPI
All checks were successful
Deploy App / docker (ubuntu-latest, 2.44.0, 17, 3.8.5) (push) Successful in 1m26s

This commit is contained in:
Braydon 2024-04-10 04:51:18 -04:00
parent 931e6c2de1
commit 0831b509e1
8 changed files with 31 additions and 273 deletions

@ -20,10 +20,10 @@ Hi there! Looking for usage? View the [Wiki](https://git.rainnny.club/Rainnny/RE
--- ---
## Postman ## Swagger API
View the [Postman Collection](https://documenter.getpostman.com/view/24401599/2sA35Mxdu3) for easy testing! View the [Swagger API Docs](https://mc.rainnny.club/swagger-ui.html) for easy testing!
![Postman Logo](https://avatars.githubusercontent.com/u/10251060?s=72) ![Swagger Logo](https://avatars.githubusercontent.com/u/7658037?s=74)
## YourKit ## YourKit
YourKit supports open source projects with innovative and intelligent tools for monitoring and profiling Java and .NET applications. YourKit supports open source projects with innovative and intelligent tools for monitoring and profiling Java and .NET applications.

10
pom.xml

@ -13,7 +13,7 @@
<!-- Project Details --> <!-- Project Details -->
<groupId>me.braydon</groupId> <groupId>me.braydon</groupId>
<artifactId>RESTfulMC</artifactId> <artifactId>RESTfulMC</artifactId>
<version>1.0-dev</version> <version>1.0.0</version>
<!-- Properties --> <!-- Properties -->
<properties> <properties>
@ -110,6 +110,14 @@
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
<!-- SwaggerUI -->
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>2.0.2</version>
<scope>compile</scope>
</dependency>
<!-- Tests --> <!-- Tests -->
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>

File diff suppressed because one or more lines are too long

@ -25,6 +25,10 @@ package me.braydon.mc;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.GsonBuilder; import com.google.gson.GsonBuilder;
import io.swagger.v3.oas.annotations.OpenAPIDefinition;
import io.swagger.v3.oas.annotations.info.Contact;
import io.swagger.v3.oas.annotations.info.Info;
import io.swagger.v3.oas.annotations.info.License;
import lombok.NonNull; import lombok.NonNull;
import lombok.SneakyThrows; import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@ -42,6 +46,13 @@ import java.util.Objects;
*/ */
@SpringBootApplication(exclude = { JacksonAutoConfiguration.class }) @SpringBootApplication(exclude = { JacksonAutoConfiguration.class })
@Slf4j(topic = "RESTfulMC") @Slf4j(topic = "RESTfulMC")
@OpenAPIDefinition(info = @Info(
title = "RESTfulMC",
description = "A simple, yet useful RESTful API for Minecraft utilizing Springboot.",
version = "1.0.0",
contact = @Contact(name = "Braydon (Rainnny)", url = "https://rainnny.club", email = "braydonrainnny@gmail.com"),
license = @License(name = "MIT License", url = "https://opensource.org/license/MIT")
))
public class RESTfulMC { public class RESTfulMC {
public static final Gson GSON = new GsonBuilder() public static final Gson GSON = new GsonBuilder()
.setDateFormat("MM-dd-yyyy HH:mm:ss") .setDateFormat("MM-dd-yyyy HH:mm:ss")

@ -29,6 +29,7 @@ import lombok.NonNull;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import me.braydon.mc.RESTfulMC; import me.braydon.mc.RESTfulMC;
import org.springframework.http.HttpMethod; import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import java.io.IOException; import java.io.IOException;
import java.net.URI; import java.net.URI;
@ -113,7 +114,7 @@ public final class JsonWebRequest {
try { try {
HttpResponse<String> response = HTTP_CLIENT.send(request.build(), HttpResponse.BodyHandlers.ofString()); HttpResponse<String> response = HTTP_CLIENT.send(request.build(), HttpResponse.BodyHandlers.ofString());
status = response.statusCode(); // Set the response status status = response.statusCode(); // Set the response status
if (status != 200) { // Status code is not OK, raise an exception if (status != HttpStatus.OK.value()) { // Status code is not OK, raise an exception
throw new IOException("Failed to make a %s request to %s: %s".formatted(method.name(), endpoint, status)); throw new IOException("Failed to make a %s request to %s: %s".formatted(method.name(), endpoint, status));
} }
// Return with the response as the type // Return with the response as the type

@ -23,6 +23,7 @@
*/ */
package me.braydon.mc.controller; package me.braydon.mc.controller;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.NonNull; import lombok.NonNull;
import lombok.extern.log4j.Log4j2; import lombok.extern.log4j.Log4j2;
import me.braydon.mc.exception.impl.BadRequestException; import me.braydon.mc.exception.impl.BadRequestException;
@ -45,6 +46,7 @@ import org.springframework.web.bind.annotation.*;
@RestController @RestController
@RequestMapping(value = "/player", produces = MediaType.APPLICATION_JSON_VALUE) @RequestMapping(value = "/player", produces = MediaType.APPLICATION_JSON_VALUE)
@Log4j2(topic = "Player Controller") @Log4j2(topic = "Player Controller")
@Tag(name = "Player Controller", description = "The controller for handling player related requests.")
public final class PlayerController { public final class PlayerController {
/** /**
* The Mojang service to use for player information. * The Mojang service to use for player information.

@ -23,6 +23,7 @@
*/ */
package me.braydon.mc.controller; package me.braydon.mc.controller;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.NonNull; import lombok.NonNull;
import lombok.extern.log4j.Log4j2; import lombok.extern.log4j.Log4j2;
import me.braydon.mc.exception.impl.BadRequestException; import me.braydon.mc.exception.impl.BadRequestException;
@ -47,6 +48,7 @@ import java.util.Map;
@RestController @RestController
@RequestMapping(value = "/server", produces = MediaType.APPLICATION_JSON_VALUE) @RequestMapping(value = "/server", produces = MediaType.APPLICATION_JSON_VALUE)
@Log4j2(topic = "Server Controller") @Log4j2(topic = "Server Controller")
@Tag(name = "Server Controller", description = "The controller for handling server related requests.")
public final class ServerController { public final class ServerController {
/** /**
* The Mojang service to use for server information. * The Mojang service to use for server information.

@ -3,6 +3,8 @@ server:
address: 0.0.0.0 address: 0.0.0.0
port: 7500 port: 7500
publicUrl: "http://localhost:7500" # The publicly accessible URL for this app publicUrl: "http://localhost:7500" # The publicly accessible URL for this app
servlet:
context-path: /
# Log Configuration # Log Configuration
logging: logging: