Skip to content

Commit

Permalink
add swagger doc
Browse files Browse the repository at this point in the history
  • Loading branch information
AnuchitO committed Mar 21, 2024
1 parent 6ec5711 commit c8b0b18
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 1 deletion.
3 changes: 3 additions & 0 deletions kbazaar/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ sonar:
health:
curl -X GET http://localhost:8080/api/v1/health

swagger:
open http://localhost:8080/swagger-ui/index.html

docker-build:
docker build -t kbazaar .

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.kampus.kbazaar.health;

import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
Expand All @@ -8,6 +11,13 @@
@RequestMapping("/api/v1")
public class HealthController {

@ApiResponse(
description = "Health check",
responseCode = "200",
content =
@Content(
mediaType = "application/json",
schema = @Schema(implementation = String.class)))
@GetMapping("/health")
public String health() {
return "{ \"status\": \"alive\" }";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.kampus.kbazaar.product;

import com.kampus.kbazaar.exceptions.NotFoundException;
import io.swagger.v3.oas.annotations.media.ArraySchema;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
Expand Down Expand Up @@ -41,13 +42,30 @@ public ProductController(ProductService productService) {
content =
@Content(
mediaType = "application/json",
schema = @Schema(implementation = Error.class)))
schema = @Schema(implementation = NotFoundException.class)))
})
@GetMapping("/products")
public List<ProductResponse> getProducts() {
return productService.getAll();
}

@ApiResponses({
@ApiResponse(
responseCode = "200",
description = "get product by sku",
content = {
@Content(
mediaType = "application/json",
schema = @Schema(implementation = ProductResponse.class))
}),
@ApiResponse(
responseCode = "404",
description = "product not found",
content =
@Content(
mediaType = "application/json",
schema = @Schema(implementation = NotFoundException.class)))
})
@GetMapping("/products/{sku}")
public ProductResponse getProductById(@PathVariable String sku) {
return productService.getBySku(sku);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
package com.kampus.kbazaar.shopper;

import com.kampus.kbazaar.exceptions.NotFoundException;
import io.swagger.v3.oas.annotations.media.ArraySchema;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import java.util.List;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
Expand All @@ -16,11 +22,50 @@ public ShopperController(ShopperService shopperService) {
this.shopperService = shopperService;
}

@ApiResponses({
@ApiResponse(
responseCode = "200",
description = "list all shoppers",
content = {
@Content(
mediaType = "application/json",
array =
@ArraySchema(
schema =
@Schema(
implementation =
ShopperResponse.class)))
}),
@ApiResponse(
responseCode = "500",
description = "internal server error",
content =
@Content(
mediaType = "application/json",
schema = @Schema(implementation = NotFoundException.class)))
})
@GetMapping("/shopper")
public List<ShopperResponse> getAllUsers() {
return shopperService.getAll();
}

@ApiResponses({
@ApiResponse(
responseCode = "200",
description = "get shopper by id",
content = {
@Content(
mediaType = "application/json",
schema = @Schema(implementation = ShopperResponse.class))
}),
@ApiResponse(
responseCode = "500",
description = "internal server error",
content =
@Content(
mediaType = "application/json",
schema = @Schema(implementation = NotFoundException.class)))
})
@GetMapping("/shopper/{id}")
public ShopperResponse getUserById(@PathVariable String id) {
return shopperService.getById(id);
Expand Down

0 comments on commit c8b0b18

Please sign in to comment.