|
4 | 4 | # Treat unset variables as an error. |
5 | 5 | set -euo pipefail |
6 | 6 |
|
7 | | -REMOTE_URL="https://raw.githubusercontent.com/a2aproject/A2A/refs/heads/main/specification/json/a2a.json" |
| 7 | +# A2A specification version to use |
| 8 | +# Can be overridden via environment variable: A2A_SPEC_VERSION=v1.2.0 ./generate_types.sh |
| 9 | +# Or via command-line flag: ./generate_types.sh --version v1.2.0 output.py |
| 10 | +# Use a specific git tag, branch name, or commit SHA |
| 11 | +# Examples: "v1.0.0", "v1.2.0", "main", "abc123def" |
| 12 | +A2A_SPEC_VERSION="${A2A_SPEC_VERSION:-v0.3.0}" |
| 13 | + |
| 14 | +# Build URL based on version format |
| 15 | +# Tags use /refs/tags/, branches use /refs/heads/, commits use direct ref |
| 16 | +build_remote_url() { |
| 17 | + local version="$1" |
| 18 | + local base_url="https://raw.githubusercontent.com/a2aproject/A2A" |
| 19 | + local spec_path="specification/json/a2a.json" |
| 20 | + local url_part |
| 21 | + |
| 22 | + if [[ "$version" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then |
| 23 | + # Looks like a version tag (v1.0.0, v1.2.3) |
| 24 | + url_part="refs/tags/${version}" |
| 25 | + elif [[ "$version" =~ ^[0-9a-f]{7,40}$ ]]; then |
| 26 | + # Looks like a commit SHA (7+ hex chars) |
| 27 | + url_part="${version}" |
| 28 | + else |
| 29 | + # Assume it's a branch name (main, develop, etc.) |
| 30 | + url_part="refs/heads/${version}" |
| 31 | + fi |
| 32 | + echo "${base_url}/${url_part}/${spec_path}" |
| 33 | +} |
| 34 | + |
| 35 | +REMOTE_URL=$(build_remote_url "$A2A_SPEC_VERSION") |
8 | 36 |
|
9 | 37 | GENERATED_FILE="" |
10 | 38 | INPUT_FILE="" |
11 | 39 |
|
12 | 40 | # Parse command-line arguments |
13 | 41 | while [[ $# -gt 0 ]]; do |
14 | 42 | case "$1" in |
15 | | - --input-file) |
16 | | - INPUT_FILE="$2" |
17 | | - shift 2 |
18 | | - ;; |
19 | | - *) |
20 | | - GENERATED_FILE="$1" |
21 | | - shift 1 |
22 | | - ;; |
| 43 | + --input-file) |
| 44 | + INPUT_FILE="$2" |
| 45 | + shift 2 |
| 46 | + ;; |
| 47 | + --version) |
| 48 | + A2A_SPEC_VERSION="$2" |
| 49 | + REMOTE_URL=$(build_remote_url "$A2A_SPEC_VERSION") |
| 50 | + shift 2 |
| 51 | + ;; |
| 52 | + *) |
| 53 | + GENERATED_FILE="$1" |
| 54 | + shift 1 |
| 55 | + ;; |
23 | 56 | esac |
24 | 57 | done |
25 | 58 |
|
26 | 59 | if [ -z "$GENERATED_FILE" ]; then |
27 | | - echo "Error: Output file path must be provided." >&2 |
28 | | - echo "Usage: $0 [--input-file <path>] <output-file-path>" |
| 60 | + cat >&2 <<EOF |
| 61 | +Error: Output file path must be provided. |
| 62 | +Usage: $0 [--input-file <path>] [--version <version>] <output-file-path> |
| 63 | +Options: |
| 64 | + --input-file <path> Use a local JSON schema file instead of fetching from remote |
| 65 | + --version <version> Specify A2A spec version (default: v0.3.0) |
| 66 | + Can be a git tag (v1.0.0), branch (main), or commit SHA |
| 67 | +Environment variables: |
| 68 | + A2A_SPEC_VERSION Override default spec version |
| 69 | +Examples: |
| 70 | + $0 src/a2a/types.py |
| 71 | + $0 --version v1.2.0 src/a2a/types.py |
| 72 | + $0 --input-file local/a2a.json src/a2a/types.py |
| 73 | + A2A_SPEC_VERSION=main $0 src/a2a/types.py |
| 74 | +EOF |
29 | 75 | exit 1 |
30 | 76 | fi |
31 | 77 |
|
32 | 78 | echo "Running datamodel-codegen..." |
33 | 79 | declare -a source_args |
34 | 80 | if [ -n "$INPUT_FILE" ]; then |
35 | 81 | echo " - Source File: $INPUT_FILE" |
| 82 | + if [ ! -f "$INPUT_FILE" ]; then |
| 83 | + echo "Error: Input file does not exist: $INPUT_FILE" >&2 |
| 84 | + exit 1 |
| 85 | + fi |
36 | 86 | source_args=("--input" "$INPUT_FILE") |
37 | 87 | else |
| 88 | + echo " - A2A Spec Version: $A2A_SPEC_VERSION" |
38 | 89 | echo " - Source URL: $REMOTE_URL" |
| 90 | + |
| 91 | + # Validate that the remote URL is accessible |
| 92 | + echo " - Validating remote URL..." |
| 93 | + if ! curl --fail --silent --head "$REMOTE_URL" >/dev/null 2>&1; then |
| 94 | + cat >&2 <<EOF |
| 95 | +
|
| 96 | +Error: Unable to access A2A specification at version '$A2A_SPEC_VERSION' |
| 97 | +URL: $REMOTE_URL |
| 98 | +
|
| 99 | +The version may not exist. Available versions can be found at: |
| 100 | + https://github.com/a2aproject/A2A/tags |
| 101 | +
|
| 102 | +EOF |
| 103 | + exit 1 |
| 104 | + fi |
| 105 | + |
39 | 106 | source_args=("--url" "$REMOTE_URL") |
40 | 107 | fi |
41 | 108 | echo " - Output File: $GENERATED_FILE" |
|
0 commit comments