Actor特徴Input Schema

入力スキーマ

ScrapelessはプロジェクトのルートディレクトリにあるINPUT_SCHEMA.jsonファイルを読み取り、このファイルに基づいてActorに必要なパラメータを入力するためのユーザーインターフェースを自動的に生成します。これにより、開発者にとって設定が簡素化され、非開発者にとっても入力オプションがよりアクセスしやすくなります。

主な目的:

  1. 入力検証 Actorに渡されるデータが事前に定義された構造と検証ルールに準拠していることを確認し、実行時の安定性と信頼性を向上させます。
  2. UI生成 プラットフォームは入力スキーマに基づいてグラフィカルな設定インターフェースを自動的に生成するため、ユーザーは入力パラメータの入力と管理を容易に行うことができます。
  3. 統合サポート Scrapelessは入力スキーマに基づいて呼び出しコードとコネクタを自動的に生成できるため、外部システムがActorを呼び出して統合する方法が簡素化されます。

入力スキーマは、Actorの入力パラメータを定義します。これは、Scrapelessプラットフォームでサポートされているさまざまなフィールドタイプで構成されるJSONオブジェクトです。入力スキーマに基づいて、Scrapelessはパラメータを自動的に解析し、対応するユーザーインターフェースを生成します。

以下は、入力スキーマから生成されたUIです。

入力スキーマの定義は以下のとおりです。

{
  "title": "Google Trends Input",
  "type": "object",
  "required": [
    "q",
    "data_type"
  ],
  "properties": {
    "q": {
      "title": "Search Query",
      "description": "Parameter defines the query or queries you want to search. You can use anything that you would use in a regular Google Trends search. The maximum number of queries per search is 5 (this only applies to `interest_over_time` and `compared_breakdown_by_region` data_type, other types of data will only accept 1 query per search).",
      "type": "string",
      "default": "Mercedes-Benz,BMW X5"
    },
    "data_type": {
      "title": "Data Type",
      "description": "The supported types are: `autocomplete`,`interest_over_time`,`compared_breakdown_by_region`,`interest_by_subregion`,`related_queries`,`related_topics`.",
      "type": "string",
      "default": "interest_over_time",
      "enum": [
        {
          "label": "Auto complete",
          "value": "autocomplete"
        },
        {
          "label": "Interest over time",
          "value": "interest_over_time"
        },
        {
          "label": "Compared breakdown by region",
          "value": "compared_breakdown_by_region"
        },
        {
          "label": "Interest by region",
          "value": "interest_by_subregion"
        },
        {
          "label": "Related queries",
          "value": "related_queries"
        },
        {
          "label": "Related topics",
          "value": "related_topics"
        }
      ]
    },
    "date": {
      "title": "Date",
      "description": "The supported dates are: `now 1-H`, `now 4-H`, `now 1-d`, `now 7-d`, `today 1-m`, `today 3-m`, `today 12-m`, `today 5-y`, `all`.\n\nYou can also pass custom values:\n\nDates from 2004 to present: `yyyy-mm-dd yyyy-mm-dd` (e.g. `2021-10-15 2022-05-25`)\nDates with hours within a week range: `yyyy-mm-ddThh yyyy-mm-ddThh` (e.g. `2022-05-19T10 2022-05-24T22`). Hours will be calculated depending on the tz (time zone) parameter.",
      "type": "string",
      "default": "today 1-m"
    },
    "hl": {
      "title": "Language",
      "description": "Parameter defines the language to use for the Google Trends search. It's a two-letter language code. (e.g., `en` for English, `es` for Spanish, or `fr` for French).",
      "type": "string",
      "default": "en"
    },
    "tz": {
      "title": "Time Zone",
      "description": "time zone offset. default is `420`.",
      "type": "string",
      "default": "420"
    }
// ...
 
  }
}
 

UIインターフェースで送信される入力オブジェクトデータは以下のとおりです。

{
    "q": "Mercedes-Benz,BMW X5",
    "data_type": "interest_over_time",
    "date": "today 1-m",
    "hl": "en",
    "tz": "420",
    "geo": "",
    "cat": "",
    "property": "",
    "is_return_raw_html": "1"
}
 

次に、入力スキーマの関連仕様について詳しく見ていきましょう。

仕様

構造

{
  "title": "Title",
  "type": "object",
  "required": [], // 必須フィールド
  "properties": {} // 入力フィールドの定義
}
 
プロパティ必須説明
title文字列はい入力スキーマの説明テキスト
type文字列はい固定値で、常に “object”
required配列はい各要素が必須プロパティの名前である文字列の配列
propertiesオブジェクトはいキーがプロパティ名、値がプロパティ定義であるオブジェクト

フィールド

入力される各フィールドはプロパティとして定義する必要があります。フィールドには、整数、文字列、配列、ブール値、オブジェクトなどの型があります。詳細は以下のとおりです。

プロパティ必須説明
typeinteger, string, array, boolean, object のいずれかはいフィールド型の制約は混在できません
title文字列はいフィールドのタイトル
description文字列はいフィールドの説明はUIのヘルプテキストとして表示されます。Markdown形式で記述できます。
defaulttype と一致いいえフィールドのデフォルト値
unit文字列いいえフィールドの表示単位
minimum数値いいえフィールドの最小値
maximum数値いいえフィールドの最大値
enum配列いいえフィールドの列挙値(enumオプション)

表示例

文字列

入力例:以下のプロパティを持つ標準的な入力フィールドを定義しました。型はstring、タイトルはUsername、説明はUsername is the username of the user、デフォルト値はI'm a default value、最大長は20です。

{
  "title": "Test Input",
  "type": "object",
  "required": [
    "username"
  ],
  "properties": {
    "username": {
      "title": "Username",
      "description": "Username is the username of the user",
      "type": "string",
      "default": "I'm a default value",
       "maximum": 20
    }
  }
}
 

レンダリング結果:

国選択例: この例では、国選択入力フィールドを定義します。型はstring、デフォルト値はchina、可能な値の列挙が提供されています。

{
  "title": "Test Input Select",
  "type": "object",
  "required": [
    "country"
  ],
  "properties": {
    "country": {
      "title": "Country",
      "type": "string",
      "description": "Country selection",
      "default": "china",
      "enum": [
        {
          "label": "China",
          "value": "china"
        },
        {
          "label": "United States",
          "value": "usa"
        },
        {
          "label": "United Kingdom",
          "value": "uk"
        }
      ]
    }
  }
}
 

レンダリング結果:

整数

例: 以下のスキーマでは、入力型はintegerに制約されており、最大値と最小値が定義されています。

{
  "title": "Test Input Number",
  "type": "object",
  "required": [
    "age"
  ],
  "properties": {
    "age": {
      "title": "Age",
      "type": "integer",
      "description": "Age is the age of the user",
      "default": 18,
      "minimum": 12,
      "maximum": 100
    }
  }
}
 

レンダリング結果:

ブール値

例: 以下の例では、入力型はbooleanに制約されており、デフォルト値はtrueに設定されています。

{
  "title": "Test Input Boolean",
  "type": "boolean",
  "required": [
    "print_log"
  ],
  "properties": {
    "print_log": {
      "title": "Print Log",
      "type": "boolean",
      "description": "Print Log is the print log of the user",
      "default": true
    }
  }
}
 

レンダリング結果:

配列

例: 以下の例では、入力型はarrayに制約されており、デフォルト値が提供されています。

{
  "title": "Test Input Array",
  "type": "array",
  "required": [
    "user_tags"
  ],
  "properties": {
    "user_tags": {
      "title": "User Tags",
      "type": "array",
      "description": "User Tags is the tags of the user",
      "default": [
        "user",
        "admin"
      ]
    }
  }
}
 

レンダリング結果:

オブジェクト

例: 以下の例では、入力型はobjectに制約されており、デフォルト値が提供されています。

{
  "title": "Test Input Object",
  "type": "object",
  "required": [
    "user_info"
  ],
  "properties": {
    "user_info": {
      "title": "User Info",
      "type": "object",
      "description": "User Info is the info of the user",
      "default": {
        "name": "John Doe",
        "age": 20,
        "email": "john.doe@example.com"
      }
    }
  }
}
 

レンダリング結果: