BAEL-5326 - Documenting Enum in swagger using swagger maven plugin (#11811)

* BAEL-5326 - Documenting Enum in swagger using swagger maven plugin

* BAEL-5326 - Documenting Enum in swagger using swagger maven plugin
Changes:
HireControllerTest -> HireControllerUnitTest
hireEmployee_RoleEngineer_ReturnsRoleString -> givenRoleEngineer_whenHireEmployee_thenReturnsRoleInString

* Moved to module: spring-boot-swagger
This commit is contained in:
Parikshit Murria
2022-02-14 12:43:32 -05:00
committed by GitHub
parent 7a15270fc3
commit fc4c77ed94
7 changed files with 186 additions and 0 deletions
@@ -0,0 +1,13 @@
package com.baeldung.swaggerenums;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class SwaggerEnumsApplication {
public static void main(String[] args) {
SpringApplication.run(SwaggerEnumsApplication.class, args);
}
}
@@ -0,0 +1,22 @@
package com.baeldung.swaggerenums.controller;
import com.baeldung.swaggerenums.model.Employee;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
@Api
@Path(value="/hire")
@Produces({"application/json"})
public class HireController {
@POST
@ApiOperation(value = "This method is used to hire employee with a specific role")
public String hireEmployee(@ApiParam(value = "role", required = true) Employee employee) {
return String.format("Hired for role: %s", employee.role.name());
}
}
@@ -0,0 +1,17 @@
package com.baeldung.swaggerenums.model;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
@ApiModel
public class Employee {
@ApiModelProperty
public Role role;
public Role getRole() {
return role;
}
public void setRole(Role role) {
this.role = role;
}
}
@@ -0,0 +1,8 @@
package com.baeldung.swaggerenums.model;
import io.swagger.annotations.ApiModel;
@ApiModel
public enum Role {
Engineer, Clerk, Driver, Janitor;
}
@@ -0,0 +1,25 @@
package com.baeldung.swaggerenums.controller;
import com.baeldung.swaggerenums.model.Employee;
import com.baeldung.swaggerenums.model.Role;
import org.junit.Assert;
import org.junit.Test;
public class HireControllerUnitTest {
@Test
public void givenRoleEngineer_whenHireEmployee_thenReturnsRoleInString() {
//Arrange
Role testRole = Role.Engineer;
Employee employee = new Employee();
employee.setRole(testRole);
//Act
HireController hireController = new HireController();
String response = hireController.hireEmployee(employee);
//Assert
Assert.assertEquals(String.format("Hired for role: %s", testRole),
response);
}
}