Fix update_schemas.py to add Oem JsonSchemas

GET on redfish/v1/JsonSchema does not show OEM schemas but shows only
DMTF redfish schemas.

It is because Oem schemas are not included into `schemas.hpp`.

In addition, the explicit OEM JsonSchema gives the content of the file
rather than the valid Json output.

Tested:

- Query JsonSchemas

```
curl -k -H "X-Auth-Token: $token" -X GET "https://$bmc/redfish/v1/JsonSchemas"

curl -k -H "X-Auth-Token: $token" -X GET "https://$bmc/redfish/v1/JsonSchemas/<OemSchema>"
e.g.
curl -k -H "X-Auth-Token: $token" -X GET "https://$bmc/redfish/v1/JsonSchemas/OemManager"
```

- Redfish Service Validator passed

Change-Id: I0fc9c3d4a48fb9c6ddec9591af12fd2c849331e3
Signed-off-by: Myung Bae <myungbae@us.ibm.com>
diff --git a/redfish-core/include/schemas.hpp b/redfish-core/include/schemas.hpp
index fa3143d..0d47c6f 100644
--- a/redfish-core/include/schemas.hpp
+++ b/redfish-core/include/schemas.hpp
@@ -126,5 +126,9 @@
         "UpdateService",
         "VirtualMedia",
         "VirtualMediaCollection",
+        "OemManager",
+        "OemComputerSystem",
+        "OemVirtualMedia",
+        "OpenBMCAccountService",
     };
 }
diff --git a/scripts/update_schemas.py b/scripts/update_schemas.py
index 92d446f..cbdcf0a 100755
--- a/scripts/update_schemas.py
+++ b/scripts/update_schemas.py
@@ -140,6 +140,14 @@
     "redfish-schema-v1",
 ]
 
+# OEM schemas
+oem_schema_names = [
+    "OemManager",
+    "OemComputerSystem",
+    "OemVirtualMedia",
+    "OpenBMCAccountService",
+]
+
 SCRIPT_DIR = os.path.dirname(os.path.realpath(__file__))
 
 proxies = {"https": os.environ.get("https_proxy", None)}
@@ -259,6 +267,15 @@
 )
 
 csdl_filenames.sort(key=SchemaVersion)
+
+# Create oem filenames - from oem json names
+oem_csdl_filenames = []
+for filename in oem_schema_names:
+    oem_csdl_filenames.append(filename + "_v1.xml")
+
+# Append Oem csdl files
+csdl_filenames += oem_csdl_filenames
+
 with open(metadata_index_path, "w") as metadata_index:
     metadata_index.write('<?xml version="1.0" encoding="UTF-8"?>\n')
     metadata_index.write(
@@ -269,43 +286,47 @@
 
     for filename in csdl_filenames:
         # filename looks like Zone_v1.xml
-        with open(os.path.join(schema_path, filename), "wb") as schema_out:
-            content = zip_ref.read(os.path.join("csdl", filename))
-            content = content.replace(b"\r\n", b"\n")
+        if filename in oem_csdl_filenames:
+            with open(
+                os.path.join(schema_path, filename), "rb"
+            ) as oem_csdl_in:
+                content = oem_csdl_in.read()
+                content = content.replace(b"\r\n", b"\n")
+        else:
+            with open(os.path.join(schema_path, filename), "wb") as schema_out:
+                content = zip_ref.read(os.path.join("csdl", filename))
+                content = content.replace(b"\r\n", b"\n")
+                schema_out.write(content)
+                filenamesplit = filename.split("_")
+                if filenamesplit[0] not in include_list:
+                    continue
 
-            schema_out.write(content)
+        metadata_index.write(
+            '    <edmx:Reference Uri="/redfish/v1/schema/' + filename + '">\n'
+        )
 
-            filenamesplit = filename.split("_")
-            if filenamesplit[0] not in include_list:
-                continue
-            metadata_index.write(
-                '    <edmx:Reference Uri="/redfish/v1/schema/'
-                + filename
-                + '">\n'
-            )
+        xml_root = ET.fromstring(content)
+        edmx = "{http://docs.oasis-open.org/odata/ns/edmx}"
+        edm = "{http://docs.oasis-open.org/odata/ns/edm}"
+        for edmx_child in xml_root:
+            if edmx_child.tag == edmx + "DataServices":
+                for data_child in edmx_child:
+                    if data_child.tag == edm + "Schema":
+                        namespace = data_child.attrib["Namespace"]
+                        if namespace.startswith("RedfishExtensions"):
+                            metadata_index.write(
+                                '        <edmx:Include Namespace="'
+                                + namespace
+                                + '"  Alias="Redfish"/>\n'
+                            )
 
-            xml_root = ET.fromstring(content)
-            edmx = "{http://docs.oasis-open.org/odata/ns/edmx}"
-            edm = "{http://docs.oasis-open.org/odata/ns/edm}"
-            for edmx_child in xml_root:
-                if edmx_child.tag == edmx + "DataServices":
-                    for data_child in edmx_child:
-                        if data_child.tag == edm + "Schema":
-                            namespace = data_child.attrib["Namespace"]
-                            if namespace.startswith("RedfishExtensions"):
-                                metadata_index.write(
-                                    '        <edmx:Include Namespace="'
-                                    + namespace
-                                    + '"  Alias="Redfish"/>\n'
-                                )
-
-                            else:
-                                metadata_index.write(
-                                    '        <edmx:Include Namespace="'
-                                    + namespace
-                                    + '"/>\n'
-                                )
-            metadata_index.write("    </edmx:Reference>\n")
+                        else:
+                            metadata_index.write(
+                                '        <edmx:Include Namespace="'
+                                + namespace
+                                + '"/>\n'
+                            )
+        metadata_index.write("    </edmx:Reference>\n")
 
     metadata_index.write(
         "    <edmx:DataServices>\n"
@@ -317,49 +338,6 @@
         "        </Schema>\n"
         "    </edmx:DataServices>\n"
     )
-    # TODO:Issue#32 There's a bug in the script that currently deletes this
-    # schema (because it's an OEM schema). Because it's the only six, and we
-    # don't update schemas very often, we just manually fix it. Need a
-    # permanent fix to the script.
-    metadata_index.write(
-        '    <edmx:Reference Uri="/redfish/v1/schema/OemManager_v1.xml">\n'
-    )
-    metadata_index.write('        <edmx:Include Namespace="OemManager"/>\n')
-    metadata_index.write("    </edmx:Reference>\n")
-
-    metadata_index.write(
-        '    <edmx:Reference Uri="'
-        '/redfish/v1/schema/OemComputerSystem_v1.xml">\n'
-    )
-    metadata_index.write(
-        '        <edmx:Include Namespace="OemComputerSystem"/>\n'
-    )
-    metadata_index.write("    </edmx:Reference>\n")
-
-    metadata_index.write(
-        '    <edmx:Reference Uri="'
-        '/redfish/v1/schema/OemVirtualMedia_v1.xml">\n'
-    )
-    metadata_index.write(
-        '        <edmx:Include Namespace="OemVirtualMedia"/>\n'
-    )
-    metadata_index.write(
-        '        <edmx:Include Namespace="OemVirtualMedia.v1_0_0"/>\n'
-    )
-    metadata_index.write("    </edmx:Reference>\n")
-
-    metadata_index.write(
-        '    <edmx:Reference Uri="'
-        '/redfish/v1/schema/OpenBMCAccountService_v1.xml">\n'
-    )
-    metadata_index.write(
-        '        <edmx:Include Namespace="OpenBMCAccountService"/>\n'
-    )
-    metadata_index.write(
-        '        <edmx:Include Namespace="OpenBMCAccountService.v1_0_0"/>\n'
-    )
-    metadata_index.write("    </edmx:Reference>\n")
-
     metadata_index.write("</edmx:Edmx>\n")
 
 
@@ -385,6 +363,9 @@
     for schema_file in json_schema_files:
         hpp_file.write('        "{}",\n'.format(schema_file))
 
+    for schema_file in oem_schema_names:
+        hpp_file.write('        "{}",\n'.format(schema_file))
+
     hpp_file.write("    };\n}\n")
 
 zip_ref.close()
diff --git a/static/redfish/v1/$metadata/index.xml b/static/redfish/v1/$metadata/index.xml
index b514422..b90b518 100644
--- a/static/redfish/v1/$metadata/index.xml
+++ b/static/redfish/v1/$metadata/index.xml
@@ -3300,11 +3300,6 @@
     <edmx:Reference Uri="/redfish/v1/schema/VirtualMediaCollection_v1.xml">
         <edmx:Include Namespace="VirtualMediaCollection"/>
     </edmx:Reference>
-    <edmx:DataServices>
-        <Schema xmlns="http://docs.oasis-open.org/odata/ns/edm" Namespace="Service">
-            <EntityContainer Name="Service" Extends="ServiceRoot.v1_0_0.ServiceContainer"/>
-        </Schema>
-    </edmx:DataServices>
     <edmx:Reference Uri="/redfish/v1/schema/OemManager_v1.xml">
         <edmx:Include Namespace="OemManager"/>
     </edmx:Reference>
@@ -3319,4 +3314,9 @@
         <edmx:Include Namespace="OpenBMCAccountService"/>
         <edmx:Include Namespace="OpenBMCAccountService.v1_0_0"/>
     </edmx:Reference>
+    <edmx:DataServices>
+        <Schema xmlns="http://docs.oasis-open.org/odata/ns/edm" Namespace="Service">
+            <EntityContainer Name="Service" Extends="ServiceRoot.v1_0_0.ServiceContainer"/>
+        </Schema>
+    </edmx:DataServices>
 </edmx:Edmx>
diff --git a/static/redfish/v1/JsonSchemas/OemAccountService/index.json b/static/redfish/v1/JsonSchemas/OemAccountService/OemAccountService.json
similarity index 100%
rename from static/redfish/v1/JsonSchemas/OemAccountService/index.json
rename to static/redfish/v1/JsonSchemas/OemAccountService/OemAccountService.json
diff --git a/static/redfish/v1/JsonSchemas/OemComputerSystem/index.json b/static/redfish/v1/JsonSchemas/OemComputerSystem/OemComputerSystem.json
similarity index 100%
rename from static/redfish/v1/JsonSchemas/OemComputerSystem/index.json
rename to static/redfish/v1/JsonSchemas/OemComputerSystem/OemComputerSystem.json
diff --git a/static/redfish/v1/JsonSchemas/OemManager/index.json b/static/redfish/v1/JsonSchemas/OemManager/OemManager.json
similarity index 100%
rename from static/redfish/v1/JsonSchemas/OemManager/index.json
rename to static/redfish/v1/JsonSchemas/OemManager/OemManager.json
diff --git a/static/redfish/v1/JsonSchemas/OemVirtualMedia/index.json b/static/redfish/v1/JsonSchemas/OemVirtualMedia/OemVirtualMedia.json
similarity index 100%
rename from static/redfish/v1/JsonSchemas/OemVirtualMedia/index.json
rename to static/redfish/v1/JsonSchemas/OemVirtualMedia/OemVirtualMedia.json