[UTILS] Fix and resolve remote references in standard defined domain
[oom/utils.git] / external-schema-repo-generator / generator / utils.sh
index de32515..fad8616 100644 (file)
@@ -24,6 +24,7 @@ EXPECTED_1_ARG=1
 EXPECTED_2_ARGS=2
 EXPECTED_4_ARGS=4
 EXPECTED_9_ARGS=9
+EXPECTED_10_ARGS=10
 
 
 # Checks whether number of arguments is valid
@@ -41,3 +42,25 @@ move_to_starting_directory() {
   echo "Moving back to: $starting_directory"
   cd $starting_directory
 }
+
+fix_schema_references(){
+  schemas=$(grep -Eo "http.*[^\/]+(.yaml)" $1/$2-*/$3/* | sort -u)
+  for schema in $schemas; do
+    schemaFilePath=$(echo "$schema" | awk  -F ":https:" '{print $1}')
+    remotePath=$(echo "$schema" | awk  -F ".yaml:" '{print $2}')
+    fileName=$(echo "$remotePath" |  grep -Eo "([^/]\w*.yaml)")
+    sed -i "s%${remotePath}%${fileName}%g" $schemaFilePath
+  done
+  schemas=$(grep -Eo "(\w*.yaml)" $1/$2-*/$3/* | sort -u)
+  for schema in $schemas; do
+    schemaFilePath=$(echo "$schema" | awk  -F ":" '{print $1}')
+    wrongPath=$(echo "$schema" | awk  -F ".yaml:" '{print $2}')
+    fileName="../..$(ls -d $1/$2-*/$3/* | grep $wrongPath | awk  -F "$1" '{print $2}')"
+    sed -i "s%${wrongPath}%${fileName}%g" $schemaFilePath
+  done
+}
+
+
+check5GApiBranchExistenceInRefs () {
+  echo $(sed -n '/5G_APIs/p' $1/*.yaml | awk  -F "raw/|blob/" '{print $2}' | awk -F "/"  '{print $1}' | uniq)
+}