104 lines
3.3 KiB
Bash
Executable File
104 lines
3.3 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
set -euo pipefail
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
PHONE_ROOT="$(cd "${SCRIPT_DIR}/.." && pwd)"
|
|
REPO_ROOT="$(cd "${PHONE_ROOT}/.." && pwd)"
|
|
OPENAPI_JSON="${OPENAPI_JSON:-${REPO_ROOT}/ljwx-boot/api/openapi.json}"
|
|
OUT_FILE="${OUT_FILE:-${PHONE_ROOT}/lib/services/openapi_endpoints.dart}"
|
|
|
|
if ! command -v jq >/dev/null 2>&1; then
|
|
echo "[ERROR] jq is required"
|
|
exit 1
|
|
fi
|
|
|
|
if [[ ! -f "${OPENAPI_JSON}" ]]; then
|
|
echo "[ERROR] OpenAPI contract not found: ${OPENAPI_JSON}"
|
|
exit 1
|
|
fi
|
|
|
|
has_path() {
|
|
local p="$1"
|
|
jq -e --arg p "${p}" '.paths[$p] != null' "${OPENAPI_JSON}" >/dev/null 2>&1
|
|
}
|
|
|
|
resolve_path() {
|
|
local canonical="$1"
|
|
if has_path "${canonical}"; then
|
|
echo "${canonical}"
|
|
return 0
|
|
fi
|
|
if has_path "/api${canonical}"; then
|
|
echo "/api${canonical}"
|
|
return 0
|
|
fi
|
|
return 1
|
|
}
|
|
|
|
declare -A resolved
|
|
declare -A required_map=(
|
|
[mobileUserInfo]="/mobile/user/info"
|
|
[mobileHealthData]="/mobile/health/data"
|
|
[mobileMessages]="/mobile/messages"
|
|
[mobileAlerts]="/mobile/alerts"
|
|
[mobileAlertsUnprocessedCount]="/mobile/alerts/unprocessed/count"
|
|
[mobileHealthStatusGlobal]="/mobile/health/status/global"
|
|
[mobileHealthMetricsKey]="/mobile/health/metrics/key"
|
|
[mobileHealthAlertsSummary]="/mobile/health/alerts/summary"
|
|
[mobileHealthAiSuggestions]="/mobile/health/ai/suggestions"
|
|
[mobileAlertsProcess]="/mobile/alerts/process"
|
|
[mobileResetPassword]="/mobile/reset_password"
|
|
[authUserInfo]="/auth/user_info"
|
|
[uploadHealthData]="/upload_health_data"
|
|
[uploadDeviceInfo]="/upload_device_info"
|
|
)
|
|
|
|
missing=0
|
|
for key in "${!required_map[@]}"; do
|
|
canonical="${required_map[$key]}"
|
|
if ! resolved_value="$(resolve_path "${canonical}")"; then
|
|
echo "[ERROR] missing endpoint in OpenAPI: ${canonical} (or /api${canonical})"
|
|
missing=$((missing + 1))
|
|
continue
|
|
fi
|
|
resolved["$key"]="${resolved_value}"
|
|
done
|
|
|
|
if [[ "${missing}" -gt 0 ]]; then
|
|
echo "[ERROR] OpenAPI is incomplete for ljwx-phone, missing=${missing}"
|
|
exit 1
|
|
fi
|
|
|
|
mkdir -p "$(dirname "${OUT_FILE}")"
|
|
|
|
cat > "${OUT_FILE}" <<EOF
|
|
// GENERATED FILE - DO NOT EDIT MANUALLY
|
|
// Generated by: ljwx-phone/tool/generate_openapi_endpoints.sh
|
|
// Source: ljwx-boot/api/openapi.json
|
|
|
|
class OpenApiEndpoints {
|
|
OpenApiEndpoints._();
|
|
|
|
static const mobileUserInfo = '${resolved[mobileUserInfo]}';
|
|
static const mobileHealthData = '${resolved[mobileHealthData]}';
|
|
static const mobileMessages = '${resolved[mobileMessages]}';
|
|
static const mobileAlerts = '${resolved[mobileAlerts]}';
|
|
static const mobileAlertsUnprocessedCount = '${resolved[mobileAlertsUnprocessedCount]}';
|
|
static const mobileHealthStatusGlobal = '${resolved[mobileHealthStatusGlobal]}';
|
|
static const mobileHealthMetricsKey = '${resolved[mobileHealthMetricsKey]}';
|
|
static const mobileHealthAlertsSummary = '${resolved[mobileHealthAlertsSummary]}';
|
|
static const mobileHealthAiSuggestions = '${resolved[mobileHealthAiSuggestions]}';
|
|
static const mobileAlertsProcess = '${resolved[mobileAlertsProcess]}';
|
|
static const mobileResetPassword = '${resolved[mobileResetPassword]}';
|
|
|
|
static const authUserInfo = '${resolved[authUserInfo]}';
|
|
|
|
// Compatibility upload endpoints retained for device-side integration.
|
|
static const uploadHealthData = '${resolved[uploadHealthData]}';
|
|
static const uploadDeviceInfo = '${resolved[uploadDeviceInfo]}';
|
|
}
|
|
EOF
|
|
|
|
echo "[SUCCESS] generated: ${OUT_FILE}"
|