Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 35 additions & 14 deletions generate.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash
set -e
cd "$(dirname "${BASH_SOURCE[0]}")"
version=v777
versions=(v710 v777)
apis=(
"CarrierFreightDetails.json|CarrierFreightDetail"
"CarrierLoadTenderResponses.json|CarrierLoadTenderResponse"
Expand All @@ -17,19 +17,40 @@ apis=(
"PlanningSchedules.json|PlanningSchedule"
"ProductActivities.json|ProductActivity"
"Shipments.json|Shipment"
"WarehouseInventoryAdjustmentAdvices.json|WarehouseInventoryAdjustmentAdvice"
"WarehouseTransferReceiptAdvices.json|WarehouseTransferReceiptAdvice"
)
for api in "${apis[@]}"; do
file=${api%%|*}
class=${api##*|}
name=${file%.json}
echo "Generating $class classes for $file schema"
mkdir -p src/RSX/$version/$name
docker run --rm -v $PWD:/app --workdir /app \
swaggest/json-cli \
json-cli gen-php "json-schema/$version/$file" \
--ptr-in-schema "#/definitions/$class" \
--def-ptr "#/definitions" \
--ns ShipStream\\SpsCommerce\\RSX\\$version\\$name \
--ns-path src/RSX/$version/$name/
for version in "${versions[@]}"; do
for api in "${apis[@]}"; do
file=${api%%|*}
class=${api##*|}
name=${file%.json}
[ ! -f "json-schema/$version/$file" ] && continue
echo "Generating $class classes for $version/$file schema"
mkdir -p src/RSX/$version/$name
if [[ "$version" == "v710" ]]; then
# Older schema format without definitions block — use a patch to wrap it
patch=$(mktemp -p .)
cat > "$patch" <<PATCH
[{"op":"add","path":"/definitions","value":{"$class":{"type":"object"}}},{"op":"copy","from":"/properties","path":"/definitions/$class/properties"},{"op":"copy","from":"/required","path":"/definitions/$class/required"}]
Comment on lines +31 to +35
Copy link

Copilot AI Mar 31, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The temp patch file is created via mktemp -p . and then deleted only after the docker run completes. On systems with BSD mktemp (e.g., macOS), mktemp -p . without a template can fail, and with set -e the rm -f will be skipped if generation errors, leaving stray temp files. Use a portable mktemp invocation (with an explicit template) and register an EXIT trap to ensure the temp file is always cleaned up.

Copilot uses AI. Check for mistakes.
PATCH
docker run --rm -v $PWD:/app --workdir /app \
swaggest/json-cli \
json-cli gen-php "json-schema/$version/$file" \
--patches "$patch" \
--ptr-in-schema "#/definitions/$class" \
--def-ptr "#/definitions" \
--ns ShipStream\\SpsCommerce\\RSX\\$version\\$name \
--ns-path src/RSX/$version/$name/
rm -f "$patch"
else
docker run --rm -v $PWD:/app --workdir /app \
swaggest/json-cli \
json-cli gen-php "json-schema/$version/$file" \
--ptr-in-schema "#/definitions/$class" \
--def-ptr "#/definitions" \
--ns ShipStream\\SpsCommerce\\RSX\\$version\\$name \
--ns-path src/RSX/$version/$name/
fi
done
done
Loading
Loading