OpenAPIの設定におけるフルエンドポイント

フルエンドポイント(full endpoint)とは、APIリクエストを送るための完全なURLのことです。これにはベースURLと特定のエンドポイントパスの両方が含まれます。

フルエンドポイントの構成要素

  1. ベースURL (Base URL):
  • APIサーバーの共通部分です。例えば、https://api.example.comなど。
  1. エンドポイントパス (Endpoint Path):
  • 特定のAPI機能やリソースにアクセスするためのURLの部分です。例えば、/users/data/{id}など。

  • ベースURL: https://script.google.com
  • エンドポイントパス: /macros/s/AKfycbzO4gx7uQyRrEgS0d-JzgwzZzrlueQmxFmGj6dxG1UGi_hqRGxv2QGrF6mRl6WGvMLd/exec

これらを組み合わせると、フルエンドポイントは次のようになります:

https://script.google.com/macros/s/AKfycbzO4gx7uQyRrEgS0d-JzgwzZzrlueQmxFmGj6dxG1UGi_hqRGxv2QGrF6DmRl6WGvML/exec

OpenAPIの設定におけるフルエンドポイント

OpenAPIの設定で、ベースURLとエンドポイントパスはそれぞれserverspathsで定義します。例えば、以下のように設定します:

servers:
  - url: https://script.google.com
    description: Google Apps Script deployment URL

paths:
  /macros/s/AKfycbzO4gx7uQy-JzgwzZzrlueQmDxFmGj6dxG1UGi_hqRGxv2QGrF6mRl6WGvMLdEA/exec:
    get:
      operationId: lookupData
      summary: Look up data in a Google Sheet by a 4-digit number.
      parameters:
        - name: id
          in: query
          required: true
          description: 4-digit number used to search the Google Sheet.
          schema:
            type: string
            pattern: '^\d{4}$'
      responses:
        '200':
          description: Successful response with user data
          content:
            application/json:
              schema:
                type: object
                properties:
                  lastname:
                    type: string
                  firstname:
                    type: string
        '400':
          description: Invalid request with an error message
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
        '404':
          description: No data found for the provided number
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string

このように、ベースURLとエンドポイントパスを適切に分けて設定することで、フルエンドポイントが正しく構成され、APIリクエストが正しく送信されるようになります。