Task - Spring Boot - Swagger #70
akash-coded
started this conversation in
Tasks
Replies: 5 comments
|
#Response.json {
"swagger": "2.0",
"info": {
"description": "Api Documentation",
"version": "1.0",
"title": "Api Documentation",
"termsOfService": "urn:tos",
"contact": {},
"license": {
"name": "Apache 2.0",
"url": "http://www.apache.org/licenses/LICENSE-2.0"
}
},
"host": "localhost:8080",
"basePath": "/",
"tags": [
{
"name": "worker-controller",
"description": "Worker Controller"
}
],
"paths": {
"/worker": {
"get": {
"tags": [
"worker-controller"
],
"summary": "getAll",
"operationId": "getAllUsingGET",
"produces": [
"*/*"
],
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "array",
"items": {
"$ref": "#/definitions/WorkerRes"
}
}
},
"401": {
"description": "Unauthorized"
},
"403": {
"description": "Forbidden"
},
"404": {
"description": "Not Found"
}
}
}
},
"/worker/addworker": {
"post": {
"tags": [
"worker-controller"
],
"summary": "addWorker",
"operationId": "addWorkerUsingPOST",
"consumes": [
"application/json"
],
"produces": [
"*/*"
],
"parameters": [
{
"in": "body",
"name": "worker",
"description": "worker",
"required": true,
"schema": {
"$ref": "#/definitions/WorkerReq"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "string"
}
},
"201": {
"description": "Created"
},
"401": {
"description": "Unauthorized"
},
"403": {
"description": "Forbidden"
},
"404": {
"description": "Not Found"
}
}
}
},
"/worker/updateworker": {
"patch": {
"tags": [
"worker-controller"
],
"summary": "updateWorkerDetails",
"operationId": "updateWorkerDetailsUsingPATCH",
"consumes": [
"application/json"
],
"produces": [
"*/*"
],
"parameters": [
{
"name": "department",
"in": "query",
"description": "department",
"required": true,
"type": "string"
},
{
"name": "id",
"in": "query",
"description": "id",
"required": true,
"type": "integer",
"format": "int32"
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "string"
}
},
"204": {
"description": "No Content"
},
"401": {
"description": "Unauthorized"
},
"403": {
"description": "Forbidden"
}
}
}
},
"/worker/{id}": {
"get": {
"tags": [
"worker-controller"
],
"summary": "getWorker",
"operationId": "getWorkerUsingGET",
"produces": [
"*/*"
],
"parameters": [
{
"name": "id",
"in": "path",
"description": "id",
"required": true,
"type": "integer",
"format": "int32"
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/WorkerRes"
}
},
"401": {
"description": "Unauthorized"
},
"403": {
"description": "Forbidden"
},
"404": {
"description": "Not Found"
}
}
}
}
},
"definitions": {
"TimestampReq": {
"type": "object",
"properties": {
"date": {
"type": "integer",
"format": "int32"
},
"hours": {
"type": "integer",
"format": "int32"
},
"minutes": {
"type": "integer",
"format": "int32"
},
"month": {
"type": "integer",
"format": "int32"
},
"nanos": {
"type": "integer",
"format": "int32"
},
"seconds": {
"type": "integer",
"format": "int32"
},
"time": {
"type": "integer",
"format": "int64"
},
"year": {
"type": "integer",
"format": "int32"
}
},
"title": "TimestampReq"
},
"TimestampRes": {
"type": "object",
"properties": {
"date": {
"type": "integer",
"format": "int32"
},
"day": {
"type": "integer",
"format": "int32"
},
"hours": {
"type": "integer",
"format": "int32"
},
"minutes": {
"type": "integer",
"format": "int32"
},
"month": {
"type": "integer",
"format": "int32"
},
"nanos": {
"type": "integer",
"format": "int32"
},
"seconds": {
"type": "integer",
"format": "int32"
},
"time": {
"type": "integer",
"format": "int64"
},
"timezoneOffset": {
"type": "integer",
"format": "int32"
},
"year": {
"type": "integer",
"format": "int32"
}
},
"title": "TimestampRes"
},
"WorkerReq": {
"type": "object",
"properties": {
"department": {
"type": "string"
},
"firstName": {
"type": "string"
},
"joiningDate": {
"$ref": "#/definitions/TimestampReq"
},
"lastName": {
"type": "string"
},
"salary": {
"type": "integer",
"format": "int32"
},
"workerId": {
"type": "integer",
"format": "int32"
}
},
"title": "WorkerReq"
},
"WorkerRes": {
"type": "object",
"properties": {
"department": {
"type": "string"
},
"firstName": {
"type": "string"
},
"joiningDate": {
"$ref": "#/definitions/TimestampRes"
},
"lastName": {
"type": "string"
},
"salary": {
"type": "integer",
"format": "int32"
},
"workerId": {
"type": "integer",
"format": "int32"
}
},
"title": "WorkerRes"
}
}
}#Screenshots of Swagger UI |
0 replies
//VisweshwaranMModelWorker.java@ApiModel(description = "Represent a Single Worker DB record")
public class Worker implements Comparable<Worker> {
@ApiModelProperty(notes = "Unique Worker ID")
Integer workerId;
@ApiModelProperty(notes = "First Name of Worker")
String firstName;
@ApiModelProperty(notes = "Last name of Worker")
String lastName;
@ApiModelProperty(notes = "Salary of a Worker")
Integer salary;
@ApiModelProperty(notes = "Date of Joinnig of a Worker")
Timestamp joiningDate;
@ApiModelProperty(notes = "Dept of a worker")
String department;
public Worker() {
super();
}
public Worker(Integer workerId, String firstName, String lastName, Integer salary, String department) {
super();
this.workerId = workerId;
this.firstName = firstName;
this.lastName = lastName;
this.salary = salary;
this.department = department;
}
public Worker(Integer workerId, String firstName, String lastName, Integer salary, Timestamp joiningDate,
String department) {
super();
this.workerId = workerId;
this.firstName = firstName;
this.lastName = lastName;
this.salary = salary;
this.joiningDate = joiningDate;
this.department = department;
}
public Integer getWorkerId() {
return workerId;
}
public void setWorkerId(Integer workerId) {
this.workerId = workerId;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public Integer getSalary() {
return salary;
}
public void setSalary(Integer salary) {
this.salary = salary;
}
public Timestamp getJoiningDate() {
return joiningDate;
}
public void setJoiningDate(Timestamp joiningDate) {
this.joiningDate = joiningDate;
}
public String getDepartment() {
return department;
}
public void setDepartment(String department) {
this.department = department;
}
@Override
public int hashCode() {
return Objects.hash(department, workerId);
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (!(obj instanceof Worker))
return false;
Worker other = (Worker) obj;
return Objects.equals(department, other.department) && Objects.equals(workerId, other.workerId);
}
@Override
public int compareTo(Worker o) {
if (this.workerId < o.workerId) {
return -1;
}
if (this.workerId > o.workerId) {
return 1;
}
if (this.equals(o)) {
return 0;
}
return this.department.compareTo(o.department);
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("Worker [workerId=").append(workerId).append(", firstName=").append(firstName)
.append(", lastName=").append(lastName).append(", salary=").append(salary).append(", joiningDate=")
.append(joiningDate).append(", department=").append(department).append("]");
return builder.toString();
}
}WorkerController.java@RestController
@RequestMapping("/worker")
public class WorkerController {
@Autowired
private WorkerService workerService;
public WorkerController(WorkerService workerService) {
this.workerService = workerService;
}
@GetMapping("/allWorkers")
@ApiOperation(value = "Fetch all Worker Records", notes = "Select * Workers", response = String.class)
public String getAllWorkers() {
try {
return this.workerService.getAllWorkers().stream().map(String::valueOf).collect(Collectors.joining("<br>"));
} catch (MyResourceNotFoundException e) {
e.printStackTrace();
}
return "error";
}
@PostMapping("/insertWorker")
@ApiOperation(value = "Insert New Worker Records", response = String.class)
public String create(@RequestParam Integer id, @RequestParam String firstName, @RequestParam String lastName,
@RequestParam Integer salary, @RequestParam String department) {
Worker worker = new Worker(id, firstName, lastName, salary, department);
try {
this.workerService.addWorker(worker);
return "New worker record created successfully.";
} catch (MyResourceNotCreatedException e) {
return e.getMessage();
}
}
@GetMapping("/get/{id}")
@ApiOperation(value = "Fetch a single Worker Record", response = String.class)
public Worker get(Integer id) {
try {
return this.workerService.getWorker(id);
} catch (MyResourceNotFoundException e) {
return null;
}
}
public String getAll() {
try {
return this.workerService.getAllWorkers().toString();
} catch (MyResourceNotFoundException e) {
return e.getMessage();
}
}
public String getDepartmentWorkers(String department) {
try {
return this.workerService.getWorkersByDepartment(department).toString();
} catch (MyResourceNotFoundException e) {
return e.getMessage();
}
}
@PatchMapping("/update/department")
public String update(Integer id, String department) {
try {
this.workerService.updateWorker(id, department);
return String.format("Record of worker with ID %d updated successfully.", id);
} catch (MyResourceNotFoundException | MyResourceNotUpdatedException e) {
return e.getMessage();
}
}
public String updateSalaryForDepartment(String department, Integer bonusFactor) {
try {
this.workerService.updateDepartmentWorkerSalaries(department, bonusFactor);
return String.format("Updated the salaries of all %s department workers.", department);
} catch (MyResourceNotUpdatedException e) {
return e.getMessage();
}
}
@DeleteMapping("/delete/{id}")
public String delete(Integer id) {
try {
this.workerService.deleteWorker(id);
return String.format("Record of worker with ID %d deleted successfully", id);
} catch (MyResourceNotDeletedException e) {
return e.getMessage();
}
}
}
Driver@SpringBootApplication
@EnableSwagger2
public class SpringBootNTierAppApplication {
public static void main(String[] args) {
SpringApplication.run(SpringBootNTierAppApplication.class, args);
}
@Bean
public Docket swaggerConfiguration() {
return new Docket(DocumentationType.SWAGGER_2).select()
.apis(RequestHandlerSelectors.basePackage("com.spring.boot.ntierapp")).build().apiInfo(apiDetails());
}
private ApiInfo apiDetails() {
return new ApiInfoBuilder().title("Sping Boot Swagger Prectice project")
.description("Spring Boot n tier app with Swagger").version("1.0").termsOfServiceUrl("No terms")
.license("No license")
.contact(new Contact("VisweshwaranM", "https://github.com/Svishva", "abc@example.com")).build();
}
@Bean
public DataSource dataSource() {
DriverManagerDataSource dataSource = new DriverManagerDataSource();
dataSource.setUrl("jdbc:mysql://localhost:3306/jdbc_demo");
dataSource.setUsername("VisweshwaranM");
dataSource.setPassword("################");
return dataSource;
}
@Bean
public WorkerRepository getWorkerRepositoryBean() {
WorkerRepository workerRepository = new WorkerRepository();
workerRepository.setDataSource(dataSource());
return workerRepository;
}
@Bean
public WorkerService getWorkerServiceBean() {
return new WorkerService(getWorkerRepositoryBean());
}
}POM.xml<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.6.7</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<groupId>com.spring.boot</groupId>
<artifactId>spring-boot-n-tier-app</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>spring-boot-n-tier-app</name>
<description>Demo project for Spring Boot n Tier app</description>
<properties>
<java.version>17</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jdbc</artifactId>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-boot-starter</artifactId>
<version>3.0.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
ScreenshotsScreenshots 1 (http://localhost:8080/swagger-ui/)Screenshots 2Screenshots 3Screenshots 4Screenshots 5api-docs.json (http://localhost:8080/v2/api-docs){
"swagger": "2.0",
"info": {
"description": "Spring Boot n tier app with Swagger",
"version": "1.0",
"title": "Sping Boot Swagger Prectice project",
"termsOfService": "No terms",
"contact": {
"name": "VisweshwaranM",
"url": "https://github.com/Svishva",
"email": "abc@example.com"
},
"license": {
"name": "No license"
}
},
"host": "localhost:8080",
"basePath": "/",
"tags": [
{
"name": "worker-controller",
"description": "Worker Controller"
}
],
"paths": {
"/worker/allWorkers": {
"get": {
"tags": [
"worker-controller"
],
"summary": "Fetch all Worker Records",
"description": "Select * Workers",
"operationId": "getAllWorkersUsingGET",
"produces": [
"*/*"
],
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "string"
}
},
"401": {
"description": "Unauthorized"
},
"403": {
"description": "Forbidden"
},
"404": {
"description": "Not Found"
}
}
}
},
"/worker/delete/{id}": {
"delete": {
"tags": [
"worker-controller"
],
"summary": "delete",
"operationId": "deleteUsingDELETE",
"produces": [
"*/*"
],
"parameters": [
{
"name": "id",
"in": "query",
"description": "id",
"required": false,
"type": "integer",
"format": "int32"
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "string"
}
},
"204": {
"description": "No Content"
},
"401": {
"description": "Unauthorized"
},
"403": {
"description": "Forbidden"
}
}
}
},
"/worker/get/{id}": {
"get": {
"tags": [
"worker-controller"
],
"summary": "Fetch a single Worker Record",
"operationId": "getUsingGET",
"produces": [
"*/*"
],
"parameters": [
{
"name": "id",
"in": "query",
"description": "id",
"required": false,
"type": "integer",
"format": "int32"
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/Worker"
}
},
"401": {
"description": "Unauthorized"
},
"403": {
"description": "Forbidden"
},
"404": {
"description": "Not Found"
}
}
}
},
"/worker/insertWorker": {
"post": {
"tags": [
"worker-controller"
],
"summary": "Insert New Worker Records",
"operationId": "createUsingPOST",
"consumes": [
"application/json"
],
"produces": [
"*/*"
],
"parameters": [
{
"name": "department",
"in": "query",
"description": "department",
"required": true,
"type": "string"
},
{
"name": "firstName",
"in": "query",
"description": "firstName",
"required": true,
"type": "string"
},
{
"name": "id",
"in": "query",
"description": "id",
"required": true,
"type": "integer",
"format": "int32"
},
{
"name": "lastName",
"in": "query",
"description": "lastName",
"required": true,
"type": "string"
},
{
"name": "salary",
"in": "query",
"description": "salary",
"required": true,
"type": "integer",
"format": "int32"
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "string"
}
},
"201": {
"description": "Created"
},
"401": {
"description": "Unauthorized"
},
"403": {
"description": "Forbidden"
},
"404": {
"description": "Not Found"
}
}
}
},
"/worker/update/department": {
"patch": {
"tags": [
"worker-controller"
],
"summary": "update",
"operationId": "updateUsingPATCH",
"consumes": [
"application/json"
],
"produces": [
"*/*"
],
"parameters": [
{
"name": "department",
"in": "query",
"description": "department",
"required": false,
"type": "string"
},
{
"name": "id",
"in": "query",
"description": "id",
"required": false,
"type": "integer",
"format": "int32"
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "string"
}
},
"204": {
"description": "No Content"
},
"401": {
"description": "Unauthorized"
},
"403": {
"description": "Forbidden"
}
}
}
}
},
"definitions": {
"Timestamp": {
"type": "object",
"properties": {
"date": {
"type": "integer",
"format": "int32"
},
"day": {
"type": "integer",
"format": "int32"
},
"hours": {
"type": "integer",
"format": "int32"
},
"minutes": {
"type": "integer",
"format": "int32"
},
"month": {
"type": "integer",
"format": "int32"
},
"nanos": {
"type": "integer",
"format": "int32"
},
"seconds": {
"type": "integer",
"format": "int32"
},
"time": {
"type": "integer",
"format": "int64"
},
"timezoneOffset": {
"type": "integer",
"format": "int32"
},
"year": {
"type": "integer",
"format": "int32"
}
},
"title": "Timestamp"
},
"Worker": {
"type": "object",
"properties": {
"department": {
"type": "string",
"description": "Dept of a worker"
},
"firstName": {
"type": "string",
"description": "First Name of Worker"
},
"joiningDate": {
"description": "Date of Joinnig of a Worker",
"$ref": "#/definitions/Timestamp"
},
"lastName": {
"type": "string",
"description": "Last name of Worker"
},
"salary": {
"type": "integer",
"format": "int32",
"description": "Salary of a Worker"
},
"workerId": {
"type": "integer",
"format": "int32",
"description": "Unique Worker ID"
}
},
"title": "Worker",
"description": "Represent a Single Worker DB record"
}
}
} @akash-coded After adding the below line in the application.properties and Upgraded Spring Boot from 2.5.6 to 2.6.7, It worked fine as expected. Thanks. |
0 replies
{
"swagger": "2.0",
"info": {
"description": "Spring Boot demo application with Swagger",
"version": "1.0",
"title": "Spring Boot Swagger Demo API",
"termsOfService": "Free to use",
"contact": {
"name": "Kalairajavadivel",
"url": "https://github.com/Kalairajavadivel?tab=repositories/",
"email": "kalairajavadivel@gmail.com"
},
"license": {
"name": "API License",
"url": "https://github.com/Kalairajavadivel?tab=repositories/"
}
},
"host": "localhost:8086",
"basePath": "/",
"tags": [
{
"name": "admin-controller",
"description": "Admin Controller"
},
{
"name": "order-controller",
"description": "Order Controller"
},
{
"name": "product-controller",
"description": "Product Controller"
},
{
"name": "user-controller",
"description": "User Controller"
}
],
"paths": {
"/admins/add": {
"post": {
"tags": [
"admin-controller"
],
"summary": "addAdmin",
"operationId": "addAdminUsingPOST",
"consumes": [
"application/json"
],
"produces": [
"*/*"
],
"parameters": [
{
"in": "body",
"name": "admin",
"description": "admin",
"required": true,
"schema": {
"$ref": "#/definitions/AdminModel"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/AdminModel"
}
},
"201": {
"description": "Created"
},
"401": {
"description": "Unauthorized"
},
"403": {
"description": "Forbidden"
},
"404": {
"description": "Not Found"
}
}
}
},
"/admins/all": {
"get": {
"tags": [
"admin-controller"
],
"summary": "Fetch Admins by admin_id",
"description": "Fetching admin_id",
"operationId": "allProductUsingGET",
"produces": [
"*/*"
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/Iterable«AdminModel»"
}
},
"401": {
"description": "Unauthorized"
},
"403": {
"description": "Forbidden"
},
"404": {
"description": "Not Found"
}
}
}
},
"/admins/update": {
"put": {
"tags": [
"admin-controller"
],
"summary": "updateOrder",
"operationId": "updateOrderUsingPUT",
"consumes": [
"application/json"
],
"produces": [
"*/*"
],
"parameters": [
{
"in": "body",
"name": "admin",
"description": "admin",
"required": true,
"schema": {
"$ref": "#/definitions/AdminModel"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/AdminModel"
}
},
"201": {
"description": "Created"
},
"401": {
"description": "Unauthorized"
},
"403": {
"description": "Forbidden"
},
"404": {
"description": "Not Found"
}
}
}
},
"/admins/{ADMIN_ID}": {
"get": {
"tags": [
"admin-controller"
],
"summary": "Find Admins by admin_id",
"description": "Provide an admin_id",
"operationId": "productByIdUsingGET",
"produces": [
"*/*"
],
"parameters": [
{
"name": "ADMIN_ID",
"in": "path",
"description": "ADMIN_ID",
"required": true,
"type": "integer",
"format": "int32"
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/AdminModel"
}
},
"401": {
"description": "Unauthorized"
},
"403": {
"description": "Forbidden"
},
"404": {
"description": "Not Found"
}
}
},
"delete": {
"tags": [
"admin-controller"
],
"summary": "deleteProduct",
"operationId": "deleteProductUsingDELETE",
"produces": [
"*/*"
],
"parameters": [
{
"name": "ADMIN_ID",
"in": "path",
"description": "ADMIN_ID",
"required": true,
"type": "integer",
"format": "int32"
}
],
"responses": {
"200": {
"description": "OK"
},
"204": {
"description": "No Content"
},
"401": {
"description": "Unauthorized"
},
"403": {
"description": "Forbidden"
}
}
}
},
"/orders/add": {
"post": {
"tags": [
"order-controller"
],
"summary": "addCountry",
"operationId": "addCountryUsingPOST",
"consumes": [
"application/json"
],
"produces": [
"*/*"
],
"parameters": [
{
"in": "body",
"name": "order",
"description": "order",
"required": true,
"schema": {
"$ref": "#/definitions/OrderModel"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/OrderModel"
}
},
"201": {
"description": "Created"
},
"401": {
"description": "Unauthorized"
},
"403": {
"description": "Forbidden"
},
"404": {
"description": "Not Found"
}
}
}
},
"/orders/all": {
"get": {
"tags": [
"order-controller"
],
"summary": "Fetch orders by order_id",
"description": "Fetching order_id",
"operationId": "allProductUsingGET_1",
"produces": [
"*/*"
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/Iterable«OrderModel»"
}
},
"401": {
"description": "Unauthorized"
},
"403": {
"description": "Forbidden"
},
"404": {
"description": "Not Found"
}
}
}
},
"/orders/update": {
"put": {
"tags": [
"order-controller"
],
"summary": "updateOrder",
"operationId": "updateOrderUsingPUT_1",
"consumes": [
"application/json"
],
"produces": [
"*/*"
],
"parameters": [
{
"in": "body",
"name": "order",
"description": "order",
"required": true,
"schema": {
"$ref": "#/definitions/OrderModel"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/OrderModel"
}
},
"201": {
"description": "Created"
},
"401": {
"description": "Unauthorized"
},
"403": {
"description": "Forbidden"
},
"404": {
"description": "Not Found"
}
}
}
},
"/orders/{order_id}": {
"get": {
"tags": [
"order-controller"
],
"summary": "Fetch orders by order_id",
"description": "Fetching order_id",
"operationId": "productByIdUsingGET_1",
"produces": [
"*/*"
],
"parameters": [
{
"name": "order_id",
"in": "path",
"description": "order_id",
"required": true,
"type": "integer",
"format": "int32"
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/OrderModel"
}
},
"401": {
"description": "Unauthorized"
},
"403": {
"description": "Forbidden"
},
"404": {
"description": "Not Found"
}
}
},
"delete": {
"tags": [
"order-controller"
],
"summary": "deleteProduct",
"operationId": "deleteProductUsingDELETE_1",
"produces": [
"*/*"
],
"parameters": [
{
"name": "order_id",
"in": "path",
"description": "order_id",
"required": true,
"type": "integer",
"format": "int32"
}
],
"responses": {
"200": {
"description": "OK"
},
"204": {
"description": "No Content"
},
"401": {
"description": "Unauthorized"
},
"403": {
"description": "Forbidden"
}
}
}
},
"/products/add": {
"post": {
"tags": [
"product-controller"
],
"summary": "addCountry",
"operationId": "addCountryUsingPOST_1",
"consumes": [
"application/json"
],
"produces": [
"*/*"
],
"parameters": [
{
"in": "body",
"name": "product",
"description": "product",
"required": true,
"schema": {
"$ref": "#/definitions/ProductModel"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/ProductModel"
}
},
"201": {
"description": "Created"
},
"401": {
"description": "Unauthorized"
},
"403": {
"description": "Forbidden"
},
"404": {
"description": "Not Found"
}
}
}
},
"/products/all": {
"get": {
"tags": [
"product-controller"
],
"summary": "Fetch products by product_id",
"description": "Fetching product_id",
"operationId": "allProductUsingGET_2",
"produces": [
"*/*"
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/Iterable«ProductModel»"
}
},
"401": {
"description": "Unauthorized"
},
"403": {
"description": "Forbidden"
},
"404": {
"description": "Not Found"
}
}
}
},
"/products/update": {
"put": {
"tags": [
"product-controller"
],
"summary": "updateProduct",
"operationId": "updateProductUsingPUT",
"consumes": [
"application/json"
],
"produces": [
"*/*"
],
"parameters": [
{
"in": "body",
"name": "product",
"description": "product",
"required": true,
"schema": {
"$ref": "#/definitions/ProductModel"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/ProductModel"
}
},
"201": {
"description": "Created"
},
"401": {
"description": "Unauthorized"
},
"403": {
"description": "Forbidden"
},
"404": {
"description": "Not Found"
}
}
}
},
"/products/{product_id}": {
"get": {
"tags": [
"product-controller"
],
"summary": "Fetch products by product_id",
"description": "Fetching product_id",
"operationId": "productByIdUsingGET_2",
"produces": [
"*/*"
],
"parameters": [
{
"name": "product_id",
"in": "path",
"description": "product_id",
"required": true,
"type": "integer",
"format": "int32"
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/ProductModel"
}
},
"401": {
"description": "Unauthorized"
},
"403": {
"description": "Forbidden"
},
"404": {
"description": "Not Found"
}
}
},
"delete": {
"tags": [
"product-controller"
],
"summary": "deleteProduct",
"operationId": "deleteProductUsingDELETE_2",
"produces": [
"*/*"
],
"parameters": [
{
"name": "product_id",
"in": "path",
"description": "product_id",
"required": true,
"type": "integer",
"format": "int32"
}
],
"responses": {
"200": {
"description": "OK"
},
"204": {
"description": "No Content"
},
"401": {
"description": "Unauthorized"
},
"403": {
"description": "Forbidden"
}
}
}
},
"/users/add": {
"post": {
"tags": [
"user-controller"
],
"summary": "addCountry",
"operationId": "addCountryUsingPOST_2",
"consumes": [
"application/json"
],
"produces": [
"*/*"
],
"parameters": [
{
"in": "body",
"name": "user",
"description": "user",
"required": true,
"schema": {
"$ref": "#/definitions/UserModel"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/UserModel"
}
},
"201": {
"description": "Created"
},
"401": {
"description": "Unauthorized"
},
"403": {
"description": "Forbidden"
},
"404": {
"description": "Not Found"
}
}
}
},
"/users/all": {
"get": {
"tags": [
"user-controller"
],
"summary": "Fetch users by user_id",
"description": "Fetching user_id",
"operationId": "allProductUsingGET_3",
"produces": [
"*/*"
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/Iterable«UserModel»"
}
},
"401": {
"description": "Unauthorized"
},
"403": {
"description": "Forbidden"
},
"404": {
"description": "Not Found"
}
}
}
},
"/users/update": {
"put": {
"tags": [
"user-controller"
],
"summary": "updateUser",
"operationId": "updateUserUsingPUT",
"consumes": [
"application/json"
],
"produces": [
"*/*"
],
"parameters": [
{
"in": "body",
"name": "user",
"description": "user",
"required": true,
"schema": {
"$ref": "#/definitions/UserModel"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/UserModel"
}
},
"201": {
"description": "Created"
},
"401": {
"description": "Unauthorized"
},
"403": {
"description": "Forbidden"
},
"404": {
"description": "Not Found"
}
}
}
},
"/users/{user_id}": {
"get": {
"tags": [
"user-controller"
],
"summary": "Fetch users by user_id",
"description": "Fetching user_id",
"operationId": "productByIdUsingGET_3",
"produces": [
"*/*"
],
"parameters": [
{
"name": "user_id",
"in": "path",
"description": "user_id",
"required": true,
"type": "integer",
"format": "int32"
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/UserModel"
}
},
"401": {
"description": "Unauthorized"
},
"403": {
"description": "Forbidden"
},
"404": {
"description": "Not Found"
}
}
},
"delete": {
"tags": [
"user-controller"
],
"summary": "deleteProduct",
"operationId": "deleteProductUsingDELETE_3",
"produces": [
"*/*"
],
"parameters": [
{
"name": "user_id",
"in": "path",
"description": "user_id",
"required": true,
"type": "integer",
"format": "int32"
}
],
"responses": {
"200": {
"description": "OK"
},
"204": {
"description": "No Content"
},
"401": {
"description": "Unauthorized"
},
"403": {
"description": "Forbidden"
}
}
}
}
},
"definitions": {
"AdminModel": {
"type": "object",
"properties": {
"admin_ID": {
"type": "integer",
"format": "int32"
},
"admin_NAME": {
"type": "string"
},
"admin_PASSWORD": {
"type": "string"
}
},
"title": "AdminModel",
"description": "Details about Admin"
},
"Iterable«AdminModel»": {
"type": "object",
"title": "Iterable«AdminModel»"
},
"Iterable«OrderModel»": {
"type": "object",
"title": "Iterable«OrderModel»"
},
"Iterable«ProductModel»": {
"type": "object",
"title": "Iterable«ProductModel»"
},
"Iterable«UserModel»": {
"type": "object",
"title": "Iterable«UserModel»"
},
"OrderModel": {
"type": "object",
"properties": {
"order_date": {
"type": "integer",
"format": "int32",
"description": "order_date"
},
"order_id": {
"type": "integer",
"format": "int64",
"description": "order_id"
},
"order_quntity": {
"type": "integer",
"format": "int32",
"description": "order_quntity"
},
"user_id": {
"type": "integer",
"format": "int32",
"description": "user_id"
}
},
"title": "OrderModel",
"description": "About Order Details"
},
"ProductModel": {
"type": "object",
"properties": {
"brand": {
"type": "string"
},
"id": {
"type": "integer",
"format": "int32"
},
"name": {
"type": "string"
},
"price": {
"type": "number",
"format": "float"
},
"stock": {
"type": "integer",
"format": "int32"
}
},
"title": "ProductModel",
"description": "Details about Products"
},
"UserModel": {
"type": "object",
"properties": {
"user_email": {
"type": "string",
"description": "user_email"
},
"user_id": {
"type": "integer",
"format": "int64",
"description": "user_id"
},
"user_name": {
"type": "string",
"description": "user_name"
},
"user_password": {
"type": "string",
"description": "user_password"
}
},
"title": "UserModel",
"description": "Details about Users"
}
}
}Screenshots |
0 replies
Swagger Api doc{
"swagger": "2.0",
"info": {
"description": "Spring Boot sportyshoes application with Swagger",
"version": "1.0",
"title": "Sportyshoes with Swagger Demo API",
"termsOfService": "Free to use",
"contact": {
"name": "Thiru",
"url": "https://github.com/Thiripurasundari25/",
"email": "thiripurasundari.k@tvsnext.io"
},
"license": {
"name": "API License",
"url": "https://github.com/Thiripurasundari25/"
}
},
"host": "localhost:8081",
"basePath": "/",
"tags": [
{
"name": "admin-controller",
"description": "Admin Controller"
},
{
"name": "user-controller",
"description": "User Controller"
}
],
"paths": {
"/api/admin/{adminId}/update/password": {
"patch": {
"tags": [
"admin-controller"
],
"summary": "update an admin password by id",
"description": "Provide an user id",
"operationId": "changeAdminPasswordUsingPATCH",
"consumes": [
"application/json"
],
"produces": [
"*/*"
],
"parameters": [
{
"name": "adminId",
"in": "path",
"description": "adminId",
"required": true,
"type": "string"
},
{
"in": "body",
"name": "password",
"description": "password",
"required": true,
"schema": {
"type": "string"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "string"
}
},
"204": {
"description": "No Content"
},
"401": {
"description": "Unauthorized"
},
"403": {
"description": "Forbidden"
}
}
}
},
"/api/order/all/sorted": {
"get": {
"tags": [
"admin-controller"
],
"summary": "sort an orders by key and ordering",
"description": "Provide a key and ordering",
"operationId": "getOrdersBySortingFieldUsingGET",
"produces": [
"*/*"
],
"parameters": [
{
"name": "key",
"in": "query",
"description": "key",
"required": true,
"type": "string"
},
{
"name": "ordering",
"in": "query",
"description": "ordering",
"required": true,
"type": "string"
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "array",
"items": {
"$ref": "#/definitions/details of the order"
}
}
},
"401": {
"description": "Unauthorized"
},
"403": {
"description": "Forbidden"
},
"404": {
"description": "Not Found"
}
}
}
},
"/api/product/add": {
"post": {
"tags": [
"admin-controller"
],
"summary": "createProduct",
"operationId": "createProductUsingPOST",
"consumes": [
"application/json"
],
"produces": [
"*/*"
],
"parameters": [
{
"in": "body",
"name": "product",
"description": "product",
"required": true,
"schema": {
"$ref": "#/definitions/Details of the product"
}
}
],
"responses": {
"201": {
"description": "Created",
"schema": {
"type": "string"
}
},
"401": {
"description": "Unauthorized"
},
"403": {
"description": "Forbidden"
},
"404": {
"description": "Not Found"
}
}
}
},
"/api/product/search": {
"get": {
"tags": [
"user-controller"
],
"summary": "Find a specific product by name",
"description": "Provide a product name",
"operationId": "getProductsByNameUsingGET",
"produces": [
"*/*"
],
"parameters": [
{
"name": "prodName",
"in": "query",
"description": "prodName",
"required": true,
"type": "string"
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "array",
"items": {
"$ref": "#/definitions/Details of the product"
}
}
},
"401": {
"description": "Unauthorized"
},
"403": {
"description": "Forbidden"
},
"404": {
"description": "Not Found"
}
}
}
},
"/api/product/{prodId}": {
"get": {
"tags": [
"user-controller"
],
"summary": "Find a specific product by id",
"description": "Provide an product id",
"operationId": "getProductByIdUsingGET",
"produces": [
"*/*"
],
"parameters": [
{
"name": "prodId",
"in": "path",
"description": "prodId",
"required": true,
"type": "integer",
"format": "int32"
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/Details of the product"
}
},
"401": {
"description": "Unauthorized"
},
"403": {
"description": "Forbidden"
},
"404": {
"description": "Not Found"
}
}
}
},
"/api/product/{prodId}/delete": {
"delete": {
"tags": [
"admin-controller"
],
"summary": "deleteProduct",
"operationId": "deleteProductUsingDELETE",
"produces": [
"*/*"
],
"parameters": [
{
"name": "prodId",
"in": "path",
"description": "prodId",
"required": true,
"type": "integer",
"format": "int32"
}
],
"responses": {
"202": {
"description": "Accepted",
"schema": {
"type": "string"
}
},
"204": {
"description": "No Content"
},
"401": {
"description": "Unauthorized"
},
"403": {
"description": "Forbidden"
}
}
}
},
"/api/product/{prodId}/update/msrp": {
"patch": {
"tags": [
"admin-controller"
],
"summary": "Update a product prize by id",
"description": "Provide an product id",
"operationId": "changeProductMsrpUsingPATCH",
"consumes": [
"application/json"
],
"produces": [
"*/*"
],
"parameters": [
{
"in": "body",
"name": "msrp",
"description": "msrp",
"required": true,
"schema": {
"type": "number",
"format": "double"
}
},
{
"name": "prodId",
"in": "path",
"description": "prodId",
"required": true,
"type": "integer",
"format": "int32"
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "string"
}
},
"204": {
"description": "No Content"
},
"401": {
"description": "Unauthorized"
},
"403": {
"description": "Forbidden"
}
}
}
},
"/api/products/all": {
"get": {
"tags": [
"user-controller"
],
"summary": "Find all products",
"operationId": "getProductListUsingGET",
"produces": [
"*/*"
],
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "array",
"items": {
"$ref": "#/definitions/Details of the product"
}
}
},
"401": {
"description": "Unauthorized"
},
"403": {
"description": "Forbidden"
},
"404": {
"description": "Not Found"
}
}
}
},
"/api/user/all": {
"get": {
"tags": [
"admin-controller"
],
"summary": "Find all users",
"operationId": "getAllUsersUsingGET",
"produces": [
"*/*"
],
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "array",
"items": {
"$ref": "#/definitions/User"
}
}
},
"401": {
"description": "Unauthorized"
},
"403": {
"description": "Forbidden"
},
"404": {
"description": "Not Found"
}
}
}
},
"/api/user/search": {
"get": {
"tags": [
"admin-controller"
],
"summary": "Find a specific user by name",
"description": "Provide a user name",
"operationId": "getUsersByNameUsingGET",
"produces": [
"*/*"
],
"parameters": [
{
"name": "userName",
"in": "query",
"description": "userName",
"required": true,
"type": "string"
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/User"
}
},
"401": {
"description": "Unauthorized"
},
"403": {
"description": "Forbidden"
},
"404": {
"description": "Not Found"
}
}
}
},
"/api/user/signin": {
"get": {
"tags": [
"user-controller"
],
"summary": "User Signin",
"description": "Provide an username & password",
"operationId": "userSiginUsingGET",
"produces": [
"*/*"
],
"parameters": [
{
"in": "body",
"name": "userData",
"description": "userData",
"required": true,
"schema": {
"$ref": "#/definitions/User"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "string"
}
},
"401": {
"description": "Unauthorized"
},
"403": {
"description": "Forbidden"
},
"404": {
"description": "Not Found"
}
}
}
},
"/api/user/signup": {
"post": {
"tags": [
"user-controller"
],
"summary": "userSignup",
"operationId": "userSignupUsingPOST",
"consumes": [
"application/json"
],
"produces": [
"*/*"
],
"parameters": [
{
"in": "body",
"name": "user",
"description": "user",
"required": true,
"schema": {
"$ref": "#/definitions/User"
}
}
],
"responses": {
"201": {
"description": "Created",
"schema": {
"type": "string"
}
},
"401": {
"description": "Unauthorized"
},
"403": {
"description": "Forbidden"
},
"404": {
"description": "Not Found"
}
}
}
},
"/api/user/{userId}": {
"get": {
"tags": [
"user-controller"
],
"summary": "Find a specific user by id",
"description": "Provide an user id",
"operationId": "getUserUsingGET",
"produces": [
"*/*"
],
"parameters": [
{
"name": "userId",
"in": "path",
"description": "userId",
"required": true,
"type": "integer",
"format": "int32"
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/User"
}
},
"401": {
"description": "Unauthorized"
},
"403": {
"description": "Forbidden"
},
"404": {
"description": "Not Found"
}
}
}
},
"/api/user/{userId}/order/all": {
"get": {
"tags": [
"user-controller"
],
"summary": "Find all orders of the User",
"description": "Provide a user id",
"operationId": "getUserOrdersUsingGET",
"produces": [
"*/*"
],
"parameters": [
{
"name": "userId",
"in": "path",
"description": "userId",
"required": true,
"type": "integer",
"format": "int32"
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "array",
"items": {
"$ref": "#/definitions/details of the order"
}
}
},
"401": {
"description": "Unauthorized"
},
"403": {
"description": "Forbidden"
},
"404": {
"description": "Not Found"
}
}
}
},
"/api/user/{userId}/product/{prodId}/order": {
"post": {
"tags": [
"user-controller"
],
"summary": "purchaseOrder",
"operationId": "purchaseOrderUsingPOST",
"consumes": [
"application/json"
],
"produces": [
"*/*"
],
"parameters": [
{
"in": "body",
"name": "order",
"description": "order",
"required": true,
"schema": {
"$ref": "#/definitions/details of the order"
}
},
{
"name": "prodId",
"in": "path",
"description": "prodId",
"required": true,
"type": "integer",
"format": "int32"
},
{
"name": "userId",
"in": "path",
"description": "userId",
"required": true,
"type": "integer",
"format": "int32"
}
],
"responses": {
"201": {
"description": "Created",
"schema": {
"$ref": "#/definitions/details of the order"
}
},
"401": {
"description": "Unauthorized"
},
"403": {
"description": "Forbidden"
},
"404": {
"description": "Not Found"
}
}
}
},
"/api/user/{userId}/update/password": {
"patch": {
"tags": [
"user-controller"
],
"summary": "update a specific user password by id",
"description": "Provide an user id",
"operationId": "changeUserPasswordUsingPATCH",
"consumes": [
"application/json"
],
"produces": [
"*/*"
],
"parameters": [
{
"in": "body",
"name": "password",
"description": "password",
"required": true,
"schema": {
"type": "string"
}
},
{
"name": "userId",
"in": "path",
"description": "userId",
"required": true,
"type": "integer",
"format": "int32"
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "string"
}
},
"204": {
"description": "No Content"
},
"401": {
"description": "Unauthorized"
},
"403": {
"description": "Forbidden"
}
}
}
},
"/api/user/{userId}/update/username": {
"patch": {
"tags": [
"user-controller"
],
"summary": "update a specific user name by id",
"description": "Provide an user id",
"operationId": "changeUserNameUsingPATCH",
"consumes": [
"application/json"
],
"produces": [
"*/*"
],
"parameters": [
{
"name": "userId",
"in": "path",
"description": "userId",
"required": true,
"type": "integer",
"format": "int32"
},
{
"in": "body",
"name": "userName",
"description": "userName",
"required": true,
"schema": {
"type": "string"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "string"
}
},
"204": {
"description": "No Content"
},
"401": {
"description": "Unauthorized"
},
"403": {
"description": "Forbidden"
}
}
}
}
},
"definitions": {
"Details of the product": {
"type": "object",
"properties": {
"prodId": {
"type": "integer",
"format": "int32",
"description": "unique id of the product"
},
"prodMsrp": {
"type": "number",
"format": "double",
"description": "prize of the product"
},
"prodName": {
"type": "string",
"description": "name of the product"
},
"prodQuantityInStock": {
"type": "integer",
"format": "int32",
"description": "quantity of the product"
},
"vendor": {
"type": "string",
"description": "vendor of the product"
}
},
"title": "Details of the product"
},
"User": {
"type": "object",
"properties": {
"password": {
"type": "string",
"description": "password of the user"
},
"userId": {
"type": "integer",
"format": "int32",
"description": "unique id of the user"
},
"userName": {
"type": "string",
"description": "name of the user"
}
},
"title": "User",
"description": "details of the user"
},
"details of the order": {
"type": "object",
"properties": {
"orderDate": {
"type": "string",
"format": "date",
"description": "order date of the order"
},
"orderId": {
"type": "integer",
"format": "int32",
"description": "unique id of the order"
},
"prodId": {
"type": "integer",
"format": "int32",
"description": "product id of the order"
},
"status": {
"type": "string",
"description": "status of the order"
},
"userId": {
"type": "integer",
"format": "int32",
"description": "user id of the order"
}
},
"title": "details of the order"
}
}
} |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment











Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Create a Spring Boot application analogous to
spring-jdbc-n-tier-app.Incorporate Swagger2 in the application and enable API and UI documentation.
Add a few details about the application, author, endpoints, and models using Swagger annotations.
You can refer to this demo project for the Swagger2 setup and configuration.
You can use this template to submit your solution.
All reactions