검색
검색
공개 노트 검색
회원가입로그인

[GPT Actions] 11. GitHub API 문서화 | 'Issues'와 'Projects', 웹훅(Webhooks)

GitHub API 문서화를 더 확장하고 개선해 보겠습니다. 이번에는 'Issues'와 'Projects' 관련 엔드포인트를 추가하고, 웹훅(Webhooks)에 대한 정보도 포함시켜 보겠습니다.

Step 9: 새로운 태그와 경로 추가

tags:
  # ... (이전 태그들 유지)
  - name: issues
    description: Operations about issues
  - name: projects
    description: Operations about projects
  - name: webhooks
    description: Information about repository webhooks

paths:
  # ... (이전 경로들 유지)

  /repos/{owner}/{repo}/issues:
    post:
      summary: Create an issue
      tags:
        - issues
      parameters:
        - name: owner
          in: path
          required: true
          schema:
            type: string
        - name: repo
          in: path
          required: true
          schema:
            type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/IssueCreate'
      responses:
        '201':
          description: Created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Issue'
  
  /repos/{owner}/{repo}/projects:
    get:
      summary: List repository projects
      tags:
        - projects
      parameters:
        - name: owner
          in: path
          required: true
          schema:
            type: string
        - name: repo
          in: path
          required: true
          schema:
            type: string
        - name: state
          in: query
          schema:
            type: string
            enum: [open, closed, all]
            default: open
      responses:
        '200':
          description: Successful response
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/Project'
  
  /repos/{owner}/{repo}/hooks:
    get:
      summary: List repository webhooks
      tags:
        - webhooks
      parameters:
        - name: owner
          in: path
          required: true
          schema:
            type: string
        - name: repo
          in: path
          required: true
          schema:
            type: string
      responses:
        '200':
          description: Successful response
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/Webhook'

Step 10: 새로운 스키마 정의 추가

components:
  schemas:
    # ... (이전 스키마들 유지)

    IssueCreate:
      type: object
      required:
        - title
      properties:
        title:
          type: string
        body:
          type: string
        assignees:
          type: array
          items:
            type: string
        milestone:
          type: integer
        labels:
          type: array
          items:
            type: string

    Project:
      type: object
      properties:
        id:
          type: integer
        node_id:
          type: string
        name:
          type: string
        number:
          type: integer
        state:
          type: string
        body:
          type: string
        creator:
          $ref: '#/components/schemas/User'
        created_at:
          type: string
          format: date-time
        updated_at:
          type: string
          format: date-time
        html_url:
          type: string
          format: uri

    Webhook:
      type: object
      properties:
        id:
          type: integer
        url:
          type: string
          format: uri
        test_url:
          type: string
          format: uri
        ping_url:
          type: string
          format: uri
        name:
          type: string
        events:
          type: array
          items:
            type: string
        active:
          type: boolean
        config:
          type: object
          properties:
            url:
              type: string
              format: uri
            content_type:
              type: string
            secret:
              type: string
            insecure_ssl:
              type: string
        updated_at:
          type: string
          format: date-time
        created_at:
          type: string
          format: date-time

Step 11: 응답 예제 추가

components:
  schemas:
    Project:
      # ... (이전 속성들 유지)
      example:
        id: 1002604
        node_id: "MDc6UHJvamVjdDEwMDI2MDQ="
        name: "Weekly Planning"
        number: 1
        state: "open"
        body: "This project is used for weekly planning of our team."
        creator:
          login: "octocat"
          id: 1
          node_id: "MDQ6VXNlcjE="
          avatar_url: "https://github.com/images/error/octocat_happy.gif"
          gravatar_id: ""
          url: "https://api.github.com/users/octocat"
          html_url: "https://github.com/octocat"
          type: "User"
          site_admin: false
        created_at: "2011-04-10T20:09:31Z"
        updated_at: "2014-03-03T18:58:10Z"
        html_url: "https://github.com/octocat/Hello-World/projects/1"

    Webhook:
      # ... (이전 속성들 유지)
      example:
        id: 1
        url: "https://api.github.com/repos/octocat/Hello-World/hooks/1"
        test_url: "https://api.github.com/repos/octocat/Hello-World/hooks/1/test"
        ping_url: "https://api.github.com/repos/octocat/Hello-World/hooks/1/pings"
        name: "web"
        events: ["push", "pull_request"]
        active: true
        config:
          url: "http://example.com/webhook"
          content_type: "json"
          insecure_ssl: "0"
        updated_at: "2011-09-06T20:39:23Z"
        created_at: "2011-09-06T17:26:27Z"

Step 12: 에러 응답 정의 추가

components:
  responses:
    NotFound:
      description: Resource not found
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    Unauthorized:
      description: Authentication failed
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    
  schemas:
    Error:
      type: object
      required:
        - message
      properties:
        message:
          type: string
        documentation_url:
          type: string
      example:
        message: "Not Found"
        documentation_url: "https://docs.github.com/rest"

이제 각 경로에 에러 응답을 추가할 수 있습니다. 예를 들어:

paths:
  /repos/{owner}/{repo}/issues:
    post:
      # ... (이전 내용 유지)
      responses:
        '201':
          description: Created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Issue'
        '404':
          $ref: '#/components/responses/NotFound'
        '401':
          $ref: '#/components/responses/Unauthorized'

이렇게 확장된 OpenAPI 스키마는 GitHub API의 더 많은 기능을 포함하고 있습니다. Issues, Projects, Webhooks 관련 엔드포인트가 추가되었고, 각각에 대한 상세한 스키마와 예제가 포함되어 있습니다.

또한 공통 에러 응답을 정의하고 재사용함으로써 문서의 일관성을 높이고 중복을 줄였습니다.

이런 방식으로 API 문서를 작성하면 다음과 같은 추가적인 이점이 있습니다:

  1. 완전성: API의 더 많은 기능이 문서화되어 있어, 사용자가 전체 API를 이해하는 데 도움이 됩니다.

  2. 에러 처리: 공통 에러 응답을 정의함으로써, API 사용자가 에러 상황을 더 잘 처리할 수 있게 됩니다.

  3. 웹훅 정보: 웹훅 관련 정보를 포함함으로써, API 사용자가 이벤트 기반 통합을 구현하는 데 도움이 됩니다.

실제 API 문서화 작업에서는 이 외에도 다음과 같은 사항들을 고려해야 합니다:

  1. 각 엔드포인트에 대한 상세한 설명 추가

  2. 요청 제한(Rate Limiting) 정보 포함

  3. 버전 관리 정책 설명

  4. 변경 로그(Changelog) 제공

  5. SDK나 라이브러리 정보 제공

  6. 인증 및 권한 관리에 대한 상세 가이드

이러한 종합적인 접근 방식을 통해, API 사용자들이 GitHub API를 효과적으로 이해하고 활용할 수 있도록 도울 수 있습니다.

공유하기
카카오로 공유하기
페이스북 공유하기
트위터로 공유하기
url 복사하기
조회수 : 92
heart
T
페이지 기반 대답
AI Chat