spring

TIL API 명세

HJHStudy 2025. 3. 26. 23:06
728x90

오늘은 간편하게 프로젝트에서 API 구성한 것을 전체적으로 확인할 수 있는 스크립트를 확인하고 결과를 보도록 하자!

프로젝트 구조 최상위에 스크립트를 구성하도록 하자.

 

#!/bin/bash

total_get_count=0
total_post_count=0
total_patch_count=0
total_put_count=0
total_delete_count=0

echo "API Count Summary"
echo "=========================="

for module_path in $(find ./ -type d -mindepth 1 -maxdepth 1); do
  module_name=$(basename "$module_path")
  controller_path="$module_path/src/main/java/takeoff/logistics_service/msa"

  if [ -d "$controller_path" ]; then
    controllers=$(find "$controller_path" -type f -name "*Controller*.java" 2>/dev/null)

    if [ -n "$controllers" ]; then
      module_has_api=false

      for controller_file in $controllers; do

        controller_name=$(basename "$controller_file")
        get_count=$(grep "@GetMapping" "$controller_file" | wc -l)
        post_count=$(grep "@PostMapping" "$controller_file" | wc -l)
        patch_count=$(grep "@PatchMapping" "$controller_file" | wc -l)
        put_count=$(grep "@PutMapping" "$controller_file" | wc -l)
        delete_count=$(grep "@DeleteMapping" "$controller_file" | wc -l)

        if (( get_count > 0 || post_count > 0 || patch_count > 0 || put_count > 0 || delete_count > 0 )); then
          module_has_api=true
          echo "  - $controller_name"
          ((get_count > 0)) && echo "    ├── GET APIs: $get_count"
          ((post_count > 0)) && echo "    ├── POST APIs: $post_count"
          ((patch_count > 0)) && echo "    ├── PATCH APIs: $patch_count"
          ((put_count > 0)) && echo "    ├── PUT APIs: $put_count"
          ((delete_count > 0)) && echo "    └── DELETE APIs: $delete_count"
        fi

        # 전체 합산
        total_get_count=$((total_get_count + get_count))
        total_post_count=$((total_post_count + post_count))
        total_patch_count=$((total_patch_count + patch_count))
        total_put_count=$((total_put_count + put_count))
        total_delete_count=$((total_delete_count + delete_count))
      done

      $module_has_api && echo "=========================="
    fi
  fi
done

total_api_count=$((total_get_count + total_post_count + total_patch_count + total_put_count + total_delete_count))

echo "API Statistics"
echo "=========================="
((total_get_count > 0)) && echo "- GET APIs: $total_get_count"
((total_post_count > 0)) && echo "- POST APIs: $total_post_count"
((total_patch_count > 0)) && echo "- PATCH APIs: $total_patch_count"
((total_put_count > 0)) && echo "- PUT APIs: $total_put_count"
((total_delete_count > 0)) && echo "- DELETE APIs: $total_delete_count"
((total_api_count > 0)) && echo "- Total APIs: $total_api_count"
echo "=========================="

 

스크립트에 대해서는 잘 모르지만 직관적으로 확인할 수 있는 부분들이 있다. 어디로 루프를 돌고 어느 폴더에서 어떤 값을 가진 것에 대한 것을 가져오는지에 대해서는 조금만 유심히 확인하면 알 수 있을 것이다. 위 스크립트의 실행을 확인해보자!

==========================
📌 Order
--------------------------
  - OrderController.java
    ├── GET APIs:    1
    ├── POST APIs:   1
    ├── PATCH APIs:  1
    └── DELETE APIs: 1

==========================
📌 Authentication
--------------------------
  - AuthController.java
    ├── POST APIs:   2

==========================
📌 Delivery Manager
--------------------------
  - DeliveryManagerInternalController.java
    ├── GET APIs:    3
  - DeliveryManagerExternalController.java
    ├── GET APIs:    2
    ├── POST APIs:   1
    ├── PATCH APIs:  1
    └── DELETE APIs: 1

==========================
📌 User
--------------------------
  - UserInternalController.java
    ├── GET APIs:    2
    ├── POST APIs:   1
  - UserExternalController.java
    ├── GET APIs:    2
    ├── POST APIs:   1
    ├── PATCH APIs:  1
    └── DELETE APIs: 1

==========================
📌 Product & Stock
--------------------------
  - ProductExternalController.java
    ├── GET APIs:    2
    ├── POST APIs:   1
    ├── PATCH APIs:  1
    └── DELETE APIs: 1
  - StockInternalController.java
    ├── GET APIs:    1
    ├── POST APIs:   3
    └── DELETE APIs: 2
  - StockExternalController.java
    ├── GET APIs:    2
    ├── PATCH APIs:  2
    └── DELETE APIs: 1

==========================
📌 Slack
--------------------------
  - SlackInternalController.java
    ├── POST APIs:   2
  - SlackExternalController.java
    ├── GET APIs:    2
    ├── PATCH APIs:  1
    └── DELETE APIs: 1

==========================
📌 Hub & Routing
--------------------------
  - HubRouteInternalController.java
    ├── POST APIs:   2
  - HubRouteExternalController.java
    ├── GET APIs:    1
    ├── PUT APIs:    1
    └── DELETE APIs: 1
  - HubInternalController.java
    ├── GET APIs:    2
    ├── POST APIs:   1
  - HubExternalController.java
    ├── GET APIs:    1
    ├── POST APIs:   1
    ├── PATCH APIs:  1
    └── DELETE APIs: 1

==========================
📌 Company
--------------------------
  - CompanyInternalController.java
    ├── GET APIs:    1
  - CompanyExternalController.java
    ├── GET APIs:    2
    ├── POST APIs:   1
    ├── PUT APIs:    1
    └── DELETE APIs: 1
==========================
==========================
- GET APIs:    24
- POST APIs:   17
- PATCH APIs:   8
- PUT APIs:     2
- DELETE APIs: 11
--------------------------
- Total APIs:  62
==========================

 

위와 같은 전체적인 API들과 각 http 메서드별로 얼마나 구현 했는지 알 수 있다.

코드의 출처는 너무나 잘 챙겨 주시던 이전 튜터님이 주셨다!

728x90

'spring' 카테고리의 다른 글

TIL Saga 패턴 사전 공부  (0) 2025.03.29
TIL git conflict  (1) 2025.03.27
TIL 의존관계 역방향 제거  (0) 2025.03.25
TIL 트러블 슈팅 Redis Cache  (0) 2025.03.24
Spring Circuit Breaker 적용  (0) 2025.03.23