Skip to content

Commit b5a1e8b

Browse files
author
lkawka
committed
Use generate_types script
1 parent f206b66 commit b5a1e8b

File tree

2 files changed

+33
-32
lines changed

2 files changed

+33
-32
lines changed

scripts/checkout_experimental_types.sh

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -82,31 +82,9 @@ cd spec_repo
8282
echo "Checking out the \"$A2A_SPEC_BRANCH\" branch..."
8383
git checkout $A2A_SPEC_BRANCH
8484

85-
echo "Running datamodel-codegen..."
85+
echo "Invoking the generate_types.sh script..."
8686
GENERATED_FILE="$ROOT_DIR/src/a2a/types.py"
87-
uv run datamodel-codegen \
88-
--input "$TMP_WORK_DIR/spec_repo/specification/json/a2a.json" \
89-
--input-file-type jsonschema \
90-
--output "$GENERATED_FILE" \
91-
--target-python-version 3.10 \
92-
--output-model-type pydantic_v2.BaseModel \
93-
--disable-timestamp \
94-
--use-schema-description \
95-
--use-union-operator \
96-
--use-field-description \
97-
--use-default \
98-
--use-default-kwarg \
99-
--use-one-literal-as-default \
100-
--class-name A2A \
101-
--use-standard-collections \
102-
--use-subclass-enum \
103-
--base-class a2a._base.A2ABaseModel \
104-
--field-constraints \
105-
--snake-case-field \
106-
--no-alias
107-
108-
echo "Formatting generated types file with ruff..."
109-
uv run ruff format "$GENERATED_FILE"
87+
$ROOT_DIR/scripts/generate_types.sh "$GENERATED_FILE" --input-file "$TMP_WORK_DIR/spec_repo/specification/json/a2a.json"
11088

11189
echo "Committing generated types file to the \"$FEATURE_BRANCH\" branch..."
11290
cd $ROOT_DIR

scripts/generate_types.sh

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,44 @@
44
# Treat unset variables as an error.
55
set -euo pipefail
66

7-
# Check if an output file path was provided as an argument.
8-
if [ -z "$1" ]; then
9-
echo "Error: Output file path must be provided as the first argument." >&2
7+
REMOTE_URL="https://raw.githubusercontent.com/a2aproject/A2A/refs/heads/main/specification/json/a2a.json"
8+
9+
GENERATED_FILE=""
10+
INPUT_FILE=""
11+
12+
# Parse command-line arguments
13+
while [[ $# -gt 0 ]]; do
14+
case "$1" in
15+
--input-file)
16+
INPUT_FILE="$2"
17+
shift 2
18+
;;
19+
*)
20+
GENERATED_FILE="$1"
21+
shift 1
22+
;;
23+
esac
24+
done
25+
26+
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>"
1029
exit 1
1130
fi
1231

13-
REMOTE_URL="https://raw.githubusercontent.com/a2aproject/A2A/refs/heads/main/specification/json/a2a.json"
14-
GENERATED_FILE="$1"
15-
1632
echo "Running datamodel-codegen..."
17-
echo " - Source URL: $REMOTE_URL"
33+
declare -a source_args
34+
if [ -n "$INPUT_FILE" ]; then
35+
echo " - Source File: $INPUT_FILE"
36+
source_args=("--input" "$INPUT_FILE")
37+
else
38+
echo " - Source URL: $REMOTE_URL"
39+
source_args=("--url" "$REMOTE_URL")
40+
fi
1841
echo " - Output File: $GENERATED_FILE"
1942

2043
uv run datamodel-codegen \
21-
--url "$REMOTE_URL" \
44+
"${source_args[@]}" \
2245
--input-file-type jsonschema \
2346
--output "$GENERATED_FILE" \
2447
--target-python-version 3.10 \

0 commit comments

Comments
 (0)