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
View the [Postman Collection](https://documenter.getpostman.com/view/24401599/2sA35Mxdu3) for easy testing!
## Swagger API
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 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 -->
<groupId>me.braydon</groupId>
<artifactId>RESTfulMC</artifactId>
<version>1.0-dev</version>
<version>1.0.0</version>
<!-- Properties -->
<properties>
@ -110,6 +110,14 @@
<scope>compile</scope>
</dependency>
<!-- SwaggerUI -->
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>2.0.2</version>
<scope>compile</scope>
</dependency>
<!-- Tests -->
<dependency>
<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.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.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
@ -42,6 +46,13 @@ import java.util.Objects;
*/
@SpringBootApplication(exclude = { JacksonAutoConfiguration.class })
@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 static final Gson GSON = new GsonBuilder()
.setDateFormat("MM-dd-yyyy HH:mm:ss")

@ -29,6 +29,7 @@ import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import me.braydon.mc.RESTfulMC;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import java.io.IOException;
import java.net.URI;
@ -113,7 +114,7 @@ public final class JsonWebRequest {
try {
HttpResponse<String> response = HTTP_CLIENT.send(request.build(), HttpResponse.BodyHandlers.ofString());
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));
}
// Return with the response as the type

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

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

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