Commit 5c50abb1 authored by Miguel Angel Reina Ortega's avatar Miguel Angel Reina Ortega
Browse files

Improving logs

parent fc0567fe
Loading
Loading
Loading
Loading
+28 −21
Original line number Diff line number Diff line
@@ -37,7 +37,7 @@ function validate {
           bname=$(basename "$1")
       #docker run -v "$(pwd)":"/specs" $DOCKER_IMAGE swagger-cli validate "/specs/$bname"
           #docker run -v "$(pwd)":"/specs" $DOCKER_IMAGE_LINT lint "/specs/$bname"
       docker run -v "$(pwd)":"/specs" $DOCKER_IMAGE_REDOC lint "/specs/$bname"
       docker run -v "$(pwd)":"/specs" -t $DOCKER_IMAGE_REDOC lint "/specs/$bname"

    else
        swagger-cli validate "$1"
@@ -53,6 +53,8 @@ if [ ! $found_yaml ] ; then
    exit 0
fi

TMP_FULL_LOG=$(mktemp)
TMP_ERR_LOG=$(mktemp)
fres=0
LOG=""
ERR=""
@@ -62,29 +64,34 @@ ERR=""
# for i in $specfiles ; do

for i in ./*.json ./*.yaml ;  do
    MSG=$(validate "$i" 2>&1)
    res=$?
    if [ ! $res == 0 ] ; then 
        ERR="$ERR$MSG\n"
    echo -e "\n--- Validating $i ---" | tee -a "$LOGFILE"
    TMP_OUTPUT=$(mktemp)
    validate "$i" 2>&1 | tee $TMP_OUTPUT
    res=${PIPESTATUS[0]}
    cat "$TMP_OUTPUT" >> "$TMP_FULL_LOG"
    if [ $res -ne 0 ] ; then
      cat "$TMP_OUTPUT" >> "$TMP_ERR_LOG"
    fi
    LOG="$LOG$MSG\n"

    fres=$(($fres||$res))
    rm -f "$TMP_LOG"
done
echo -e $FULL_LOG | tee -a $LOGFILE

echo -e "\n-- Final validator returns $fres." | tee -a $LOGFILE
if [ $fres == 0 ] ; then
   echo "No errors found, all files validate the OpenAPI definition. Below the complete log." | tee -a $LOGFILE
else
   echo "Some errors found, see below the details." | tee -a $LOGFILE
   echo "Some errors found, see details in log file" | tee -a $LOGFILE
fi

if [ ! "$ERR" == "" ] ; then 
    echo -e "\n---- Errors detected ----" | tee -a $LOGFILE
    echo -e $ERR  | tee -a $LOGFILE
fi
#if [ -s "$TMP_ERR_LOG" ] ; then
#    echo -e "\n---- Errors detected ----" | tee -a $LOGFILE
#    cat "$TMP_ERR_LOG" | tee -a $LOGFILE
#fi

echo -e "\n---- Complete log of validation ----" | tee -a $LOGFILE
echo -e $LOG | tee -a $LOGFILE
#echo -e "\n---- Complete log of validation ----" | tee -a $LOGFILE
#cat "$TMP_FULL_LOG" | tee -a $LOGFILE

echo -e "\n------ Content of the folder ------" | tee -a $LOGFILE
ls | tee -a $LOGFILE