Skip to content

Commit

Permalink
Merge pull request #24 from RHoKAustralia/swagger-implementation
Browse files Browse the repository at this point in the history
Added swagger documentation for all the existing API endpoints
  • Loading branch information
amitkashyap01 authored Jan 29, 2019
2 parents 1bb9691 + 25220a6 commit ea7fe48
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 2 deletions.
20 changes: 20 additions & 0 deletions backend/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,26 @@
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
<version>2.1.2.RELEASE</version>
</dependency>

<!-- Swagger Dependency -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>

<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>25.0-jre</version>
</dependency>

<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version>
</dependency>
</dependencies>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.onemda.onemdabackend.configuration;

import java.util.Collections;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
@EnableSwagger2
public class SpringFoxConfiguration {

@Bean
public Docket apiDocket() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.basePackage("com.onemda.onemdabackend")) //it will generate documentation for controllers as well as models
.paths(PathSelectors.any())
.build()
.apiInfo(getApiInfo()); // - This is to override default API infomation provided by Swagger
}

private ApiInfo getApiInfo() {
return new ApiInfo(
"Onemda API Details", //Title
"This is the API specification page of OneMda", //Description
"VERSION 1.0",
"TERMS OF SERVICE URL",
new Contact("OneMda","https://www.onemda.com.au/","[email protected]"),
"Reg No A0025065T",
"LICENSE URL",
Collections.emptyList()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,22 @@
import com.onemda.onemdabackend.model.ServiceCategory;
import com.onemda.onemdabackend.service.CategoryService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;


@CrossOrigin
@RestController
@RequestMapping("/api/onemda")
@Api(description = "Set of endpoints for dealing with service categories")
public class CategoryServiceController {

@Autowired
private CategoryService categoryService;

@CrossOrigin
@GetMapping("/categories")
@ApiOperation("Returns list of all the available service categories")
public List<ServiceCategory> getAllServiceCategories(){
return categoryService.getAllTheServiceCategory();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,30 @@
import com.onemda.onemdabackend.model.InstructorFeedback;
import com.onemda.onemdabackend.service.InstructorFeedbackService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;


@CrossOrigin
@RestController
@RequestMapping("/api/onemda")
@Api(description = "Set of endpoints for getting and posting instructor feedbacks")
public class InstructorFeedbackController {

@Autowired
private InstructorFeedbackService instructorFeedbackService;

@CrossOrigin
@PostMapping("/instructorfeedback")
public void postInstructorFeedback(@RequestBody InstructorFeedback instructorFeedback){
@ApiOperation("Add instructor feedback into database")
public void postInstructorFeedback(@ApiParam("Instructor feedback to be added") @RequestBody InstructorFeedback instructorFeedback){
instructorFeedback.setSubmittedAt(new Date());
instructorFeedbackService.addInstructorFeedback(instructorFeedback);
}

@GetMapping("/instructorfeedback")
@ApiOperation("Returns all the instructor feedbacks available")
public List<InstructorFeedback> getInstructorFeedback(){
return instructorFeedbackService.getInstructorFeedback();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,30 @@

import java.util.List;

import com.onemda.onemdabackend.service.ParticipantService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.onemda.onemdabackend.model.Participant;
import com.onemda.onemdabackend.service.ParticipantService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@CrossOrigin
@RestController
@RequestMapping("/api/onemda")
@Api(description = "Set of endpoints for dealing with participants")
public class ParticipantController {

@Autowired
private ParticipantService participantService;

@CrossOrigin
@GetMapping("/participants")
@ApiOperation("Returns list of all the participants")
public List<Participant> getAllTheParticipants(){
return participantService.getAllTheParticipants();
}
Expand Down

0 comments on commit ea7fe48

Please sign in to comment.