Loading common-openapi/cli-validate-openapis-mec.sh +28 −23 Original line number Diff line number Diff line Loading @@ -52,32 +52,37 @@ if ! ls | grep -Eq '\.ya?ml$|\.json$'; then exit 0 fi function get_ref { echo -e "---- Getting refs for $1: " # Parse any ref not starting with #/in the yaml files and put it in a variable # Examples (simple quotes are part of the reference lines): # $ref: '#/components/schemas/FeatureDependency' -> no reference to get # $ref: 'TS29122_CpProvisioning.yaml#/components/schemas/ScheduledCommunicationTime' -> reference to get TS29122_CpProvisioning.yaml # Extract only external YAML file names from $ref entries (strip quotes and fragments) refs=$(grep -oP '\$ref:\s*\K.*' "$1" | grep -v '^\s*#/' | grep -oP "[^'\"#/]+\.ya?ml" | sort -u) echo "Refs: $refs" #Check if externals directory exists and contains yaml files if [ -d "externals" ] && [ -n "$(find externals -name '*.yaml')" ]; then echo "Processing external YAML files..." for external_file in externals/*.yaml; do base_name=$(basename "$external_file") if [ -f "./$base_name" ]; then # Get last commit timestamps for both files external_timestamp=$(cd externals && git log -1 --format=%ct "$(basename $external_file)") current_timestamp=$(git log -1 --format=%ct "$base_name" 2>/dev/null || echo "0") if [ "$external_timestamp" -gt "$current_timestamp" ]; then echo "Updating $base_name from externals (newer version found in Git history)" cp "$external_file" "./$base_name" # Copy only necessary files, those present in the refs variable that exists in the externals directory for ref in $refs; do if [ -f "externals/$ref" ]; then echo "Copying $ref from externals" cp "externals/$ref" "./$ref" #get_ref "$ref" else echo "Keeping existing $base_name (newer or same age in Git history)" fi else # File doesn't exist in current directory, copy it echo "Copying new file $base_name from externals" cp "$external_file" "./" echo "File $ref not found in externals" exit 1 fi done else echo "No external YAML files to process" fi } for i in ./*.yaml ; do get_ref "$i" done TMP_FULL_LOG=$(mktemp) TMP_ERR_LOG=$(mktemp) Loading Loading
common-openapi/cli-validate-openapis-mec.sh +28 −23 Original line number Diff line number Diff line Loading @@ -52,32 +52,37 @@ if ! ls | grep -Eq '\.ya?ml$|\.json$'; then exit 0 fi function get_ref { echo -e "---- Getting refs for $1: " # Parse any ref not starting with #/in the yaml files and put it in a variable # Examples (simple quotes are part of the reference lines): # $ref: '#/components/schemas/FeatureDependency' -> no reference to get # $ref: 'TS29122_CpProvisioning.yaml#/components/schemas/ScheduledCommunicationTime' -> reference to get TS29122_CpProvisioning.yaml # Extract only external YAML file names from $ref entries (strip quotes and fragments) refs=$(grep -oP '\$ref:\s*\K.*' "$1" | grep -v '^\s*#/' | grep -oP "[^'\"#/]+\.ya?ml" | sort -u) echo "Refs: $refs" #Check if externals directory exists and contains yaml files if [ -d "externals" ] && [ -n "$(find externals -name '*.yaml')" ]; then echo "Processing external YAML files..." for external_file in externals/*.yaml; do base_name=$(basename "$external_file") if [ -f "./$base_name" ]; then # Get last commit timestamps for both files external_timestamp=$(cd externals && git log -1 --format=%ct "$(basename $external_file)") current_timestamp=$(git log -1 --format=%ct "$base_name" 2>/dev/null || echo "0") if [ "$external_timestamp" -gt "$current_timestamp" ]; then echo "Updating $base_name from externals (newer version found in Git history)" cp "$external_file" "./$base_name" # Copy only necessary files, those present in the refs variable that exists in the externals directory for ref in $refs; do if [ -f "externals/$ref" ]; then echo "Copying $ref from externals" cp "externals/$ref" "./$ref" #get_ref "$ref" else echo "Keeping existing $base_name (newer or same age in Git history)" fi else # File doesn't exist in current directory, copy it echo "Copying new file $base_name from externals" cp "$external_file" "./" echo "File $ref not found in externals" exit 1 fi done else echo "No external YAML files to process" fi } for i in ./*.yaml ; do get_ref "$i" done TMP_FULL_LOG=$(mktemp) TMP_ERR_LOG=$(mktemp) Loading