-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathgenerate_models.sh
More file actions
executable file
·47 lines (39 loc) · 1.32 KB
/
generate_models.sh
File metadata and controls
executable file
·47 lines (39 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/bin/bash
# Generate Pydantic models from UCP JSON Schemas
# Ensure we are in the script's directory
cd "$(dirname "$0")" || exit
# Output directory
OUTPUT_DIR="src/ucp_sdk/models"
# Schema directory (relative to this script)
SCHEMA_DIR="../../spec/"
echo "Generating Pydantic models from $SCHEMA_DIR..."
# Check if uv is installed
if ! command -v uv &> /dev/null; then
echo "Error: uv not found."
echo "Please install uv: curl -LsSf https://astral.sh/uv/install.sh | sh"
exit 1
fi
# Ensure output directory is clean
rm -r -f "$OUTPUT_DIR"
mkdir -p "$OUTPUT_DIR"
# Run generation using uv
# We use --use-schema-description to use descriptions from JSON schema as docstrings
# We use --field-constraints to include validation constraints (regex, min/max, etc.)
uv run \
--link-mode=copy \
--extra-index-url https://pypi.org/simple python \
-m datamodel_code_generator \
--input "$SCHEMA_DIR" \
--input-file-type jsonschema \
--output "$OUTPUT_DIR" \
--output-model-type pydantic_v2.BaseModel \
--use-schema-description \
--field-constraints \
--use-field-description \
--enum-field-as-literal all \
--disable-timestamp \
--use-double-quotes \
--no-use-annotated \
--allow-extra-fields \
--formatters ruff-format ruff-check
echo "Done. Models generated in $OUTPUT_DIR"