Repository: amp-labs/connectors
Pull request #1567 (2025-04-16 22:16:32)

fix(marketo): Metadata from schema.json

Cobalt0s: * **#1567** <a href="https://app.graphite.dev/github/pr/amp-labs/connectors/1567?utm_source=stack-comment-icon" target="_blank"><img src="https://static.graphite.dev/graphite-32x32-black.png" alt="Graphite" width="10px" height="10px"/></a> 👈 <a href="https://app.graphite.dev/github/pr/amp-labs/connectors/1567?utm_source=stack-comment-view-in-graphite" target="_blank">(View in Graphite)</a>
* `main`


<h2></h2>

This stack of pull requests is managed by <a href="https://graphite.dev?utm-source=stack-comment"><b>Graphite</b></a>. Learn more about <a href="https://stacking.dev/?utm_source=stack-comment">stacking</a>.
<!-- Current dependencies on/for this PR: -->
Jkarage: Great catch @Cobalt0s , I added 1 commit that updates the script to separates the Leads & assets objects in the static schema file. I have run the script and regenerated the schemas. With the current changes(in this PR) we are treating all objects being in the Leads Module. We can chat more on this in slack.  

Patch:
diff --git a/providers/aha/connector.go b/providers/aha/connector.go
index 28e6336f..f21bbf4a 100644
--- a/providers/aha/connector.go
+++ b/providers/aha/connector.go
@@ -17,6 +17,7 @@ type Connector struct {
 
 	// Require authenticated client
 	common.RequireAuthenticatedClient
+	common.RequireWorkspace
 
 	// supported operations
 	components.SchemaProvider
diff --git a/providers/marketo/metadata/schemas.json b/providers/marketo/metadata/schemas.json
index 1819e909..0206c196 100644
--- a/providers/marketo/metadata/schemas.json
+++ b/providers/marketo/metadata/schemas.json
@@ -1,42 +1,9 @@
 {
   "modules": {
-    "root": {
+    "assets": {
       "id": "",
       "path": "",
       "objects": {
-        "activities": {
-          "displayName": "activities",
-          "path": "/activities",
-          "responseKey": "",
-          "fields": {
-            "activityDate": "activityDate",
-            "activityTypeId": "activityTypeId",
-            "attributes": "attributes",
-            "campaignId": "campaignId",
-            "id": "id",
-            "leadId": "leadId",
-            "marketoGUID": "marketoGUID",
-            "primaryAttributeValue": "primaryAttributeValue",
-            "primaryAttributeValueId": "primaryAttributeValueId"
-          }
-        },
-        "campaigns": {
-          "displayName": "campaigns",
-          "path": "/campaigns",
-          "responseKey": "",
-          "fields": {
-            "active": "active",
-            "createdAt": "createdAt",
-            "description": "description",
-            "id": "id",
-            "name": "name",
-            "programId": "programId",
-            "programName": "programName",
-            "type": "type",
-            "updatedAt": "updatedAt",
-            "workspaceName": "workspaceName"
-          }
-        },
         "channels": {
           "displayName": "channels",
           "path": "/channels",
@@ -50,37 +17,6 @@
             "updatedAt": "updatedAt"
           }
         },
-        "companies": {
-          "displayName": "companies",
-          "path": "/companies",
-          "responseKey": "",
-          "fields": {
-            "id": "id",
-            "reasons": "reasons",
-            "seq": "seq",
-            "status": "status"
-          }
-        },
-        "customobjects": {
-          "displayName": "customobjects",
-          "path": "/customobjects",
-          "responseKey": "",
-          "fields": {
-            "apiName": "apiName",
-            "createdAt": "createdAt",
-            "dedupeFields": "dedupeFields",
-            "description": "description",
-            "displayName": "displayName",
-            "fields": "fields",
-            "idField": "idField",
-            "pluralName": "pluralName",
-            "relationships": "relationships",
-            "searchableFields": "searchableFields",
-            "state": "state",
-            "updatedAt": "updatedAt",
-            "version": "version"
-          }
-        },
         "emailTemplates": {
           "displayName": "emailTemplates",
           "path": "/emailTemplates",
@@ -243,68 +179,6 @@
             "workspace": "workspace"
           }
         },
-        "leads": {
-          "displayName": "leads",
-          "path": "/leads",
-          "responseKey": "",
-          "fields": {
-            "id": "id",
-            "membership": "membership",
-            "reason": "reason",
-            "status": "status"
-          }
-        },
-        "lists": {
-          "displayName": "lists",
-          "path": "/lists",
-          "responseKey": "",
-          "fields": {
-            "createdAt": "createdAt",
-            "description": "description",
-            "id": "id",
-            "name": "name",
-            "programName": "programName",
-            "updatedAt": "updatedAt",
-            "workspaceName": "workspaceName"
-          }
-        },
-        "namedAccountLists": {
-          "displayName": "namedAccountLists",
-          "path": "/namedAccountLists",
-          "responseKey": "",
-          "fields": {
-            "createdAt": "createdAt",
-            "marketoGUID": "marketoGUID",
-            "name": "name",
-            "reasons": "reasons",
-            "seq": "seq",
-            "status": "status",
-            "type": "type",
-            "updateable": "updateable",
-            "updatedAt": "updatedAt"
-          }
-        },
-        "namedaccounts": {
-          "displayName": "namedaccounts",
-          "path": "/namedaccounts",
-          "responseKey": "",
-          "fields": {
-            "marketoGUID": "marketoGUID",
-            "reasons": "reasons",
-            "seq": "seq",
-            "status": "status"
-          }
-        },
-        "opportunities": {
-          "displayName": "opportunities",
-          "path": "/opportunities",
-          "responseKey": "",
-          "fields": {
-            "marketoGUID": "marketoGUID",
-            "reasons": "reasons",
-            "seq": "seq"
-          }
-        },
         "programs": {
           "displayName": "programs",
           "path": "/programs",
@@ -340,17 +214,6 @@
             "updatedAt": "updatedAt"
           }
         },
-        "salespersons": {
-          "displayName": "salespersons",
-          "path": "/salespersons",
-          "responseKey": "",
-          "fields": {
-            "id": "id",
-            "reasons": "reasons",
-            "seq": "seq",
-            "status": "status"
-          }
-        },
         "segmentation": {
           "displayName": "segmentation",
           "path": "/segmentation",
@@ -454,6 +317,149 @@
           }
         }
       }
+    },
+    "leads": {
+      "id": "",
+      "path": "",
+      "objects": {
+        "activities": {
+          "displayName": "activities",
+          "path": "/activities",
+          "responseKey": "",
+          "fields": {
+            "activityDate": "activityDate",
+            "activityTypeId": "activityTypeId",
+            "attributes": "attributes",
+            "campaignId": "campaignId",
+            "id": "id",
+            "leadId": "leadId",
+            "marketoGUID": "marketoGUID",
+            "primaryAttributeValue": "primaryAttributeValue",
+            "primaryAttributeValueId": "primaryAttributeValueId"
+          }
+        },
+        "campaigns": {
+          "displayName": "campaigns",
+          "path": "/campaigns",
+          "responseKey": "",
+          "fields": {
+            "active": "active",
+            "createdAt": "createdAt",
+            "description": "description",
+            "id": "id",
+            "name": "name",
+            "programId": "programId",
+            "programName": "programName",
+            "type": "type",
+            "updatedAt": "updatedAt",
+            "workspaceName": "workspaceName"
+          }
+        },
+        "companies": {
+          "displayName": "companies",
+          "path": "/companies",
+          "responseKey": "",
+          "fields": {
+            "id": "id",
+            "reasons": "reasons",
+            "seq": "seq",
+            "status": "status"
+          }
+        },
+        "customobjects": {
+          "displayName": "customobjects",
+          "path": "/customobjects",
+          "responseKey": "",
+          "fields": {
+            "apiName": "apiName",
+            "createdAt": "createdAt",
+            "dedupeFields": "dedupeFields",
+            "description": "description",
+            "displayName": "displayName",
+            "fields": "fields",
+            "idField": "idField",
+            "pluralName": "pluralName",
+            "relationships": "relationships",
+            "searchableFields": "searchableFields",
+            "state": "state",
+            "updatedAt": "updatedAt",
+            "version": "version"
+          }
+        },
+        "leads": {
+          "displayName": "leads",
+          "path": "/leads",
+          "responseKey": "",
+          "fields": {
+            "id": "id",
+            "membership": "membership",
+            "reason": "reason",
+            "status": "status"
+          }
+        },
+        "lists": {
+          "displayName": "lists",
+          "path": "/lists",
+          "responseKey": "",
+          "fields": {
+            "createdAt": "createdAt",
+            "description": "description",
+            "id": "id",
+            "name": "name",
+            "programName": "programName",
+            "updatedAt": "updatedAt",
+            "workspaceName": "workspaceName"
+          }
+        },
+        "namedAccountLists": {
+          "displayName": "namedAccountLists",
+          "path": "/namedAccountLists",
+          "responseKey": "",
+          "fields": {
+            "createdAt": "createdAt",
+            "marketoGUID": "marketoGUID",
+            "name": "name",
+            "reasons": "reasons",
+            "seq": "seq",
+            "status": "status",
+            "type": "type",
+            "updateable": "updateable",
+            "updatedAt": "updatedAt"
+          }
+        },
+        "namedaccounts": {
+          "displayName": "namedaccounts",
+          "path": "/namedaccounts",
+          "responseKey": "",
+          "fields": {
+            "marketoGUID": "marketoGUID",
+            "reasons": "reasons",
+            "seq": "seq",
+            "status": "status"
+          }
+        },
+        "opportunities": {
+          "displayName": "opportunities",
+          "path": "/opportunities",
+          "responseKey": "",
+          "fields": {
+            "marketoGUID": "marketoGUID",
+            "reasons": "reasons",
+            "seq": "seq"
+          }
+        },
+        "salespersons": {
+          "displayName": "salespersons",
+          "path": "/salespersons",
+          "responseKey": "",
+          "fields": {
+            "id": "id",
+            "reasons": "reasons",
+            "seq": "seq",
+            "status": "status"
+          }
+        }
+      }
     }
   }
-}
\ No newline at end of file
+}
diff --git a/scripts/openapi/marketo/metadata/metadata.go b/scripts/openapi/marketo/metadata/metadata.go
index b40aa9d5..c7077718 100644
--- a/scripts/openapi/marketo/metadata/metadata.go
+++ b/scripts/openapi/marketo/metadata/metadata.go
@@ -9,6 +9,7 @@ import (
 	"github.com/amp-labs/connectors/common"
 	"github.com/amp-labs/connectors/internal/goutils"
 	"github.com/amp-labs/connectors/internal/staticschema"
+	"github.com/amp-labs/connectors/providers"
 	"github.com/amp-labs/connectors/providers/marketo/metadata"
 	"github.com/getkin/kin-openapi/openapi2"
 )
@@ -32,19 +33,25 @@ func main() {
 	ldef, docL, err := constructDefinitions(leads, 4) //nolint:gomnd,mnd
 	goutils.MustBeNil(err)
 
-	// Initializes an empty ObjectMetadata variable
-	objectMetadata := make(map[string]staticschema.Object[staticschema.FieldMetadataMapV1, any])
+	// Initializes an empty map of leads ObjectMetadata
+	leadsMetadata := make(map[string]staticschema.Object[staticschema.FieldMetadataMapV1, any])
 
-	// Add Lead metadata details
-	objectMetadata = generateMetadata(ldef, docL, objectMetadata)
+	// Initializes an empty map of assets ObjectMetadata
+	assetsMetadata := make(map[string]staticschema.Object[staticschema.FieldMetadataMapV1, any])
 
-	// Adds Assets Metadata details to the same variable declared above.
-	objectMetadata = generateMetadata(def, docA, objectMetadata)
+	// Adds Leads metadata details
+	leadsMetadata = generateMetadata(ldef, docL, leadsMetadata)
+
+	// Adds Assets Metadata details
+	assetsMetadata = generateMetadata(def, docA, assetsMetadata)
 
 	goutils.MustBeNil(metadata.FileManager.SaveSchemas(&staticschema.Metadata[staticschema.FieldMetadataMapV1, any]{
 		Modules: map[common.ModuleID]staticschema.Module[staticschema.FieldMetadataMapV1, any]{
-			common.ModuleRoot: {
-				Objects: objectMetadata,
+			providers.ModuleMarketoLeads: {
+				Objects: leadsMetadata,
+			},
+			providers.ModuleMarketoAssets: {
+				Objects: assetsMetadata,
 			},
 		},
 	}))


Test patch:
diff --git a/providers/marketo/metadata_test.go b/providers/marketo/metadata_test.go
index ee9400f0..fc58a293 100644
--- a/providers/marketo/metadata_test.go
+++ b/providers/marketo/metadata_test.go
@@ -24,6 +24,31 @@ func TestListObjectMetadata(t *testing.T) { // nolint:funlen,gocognit,cyclop
 			Server:       mockserver.Dummy(),
 			ExpectedErrs: []error{common.ErrMissingObjects},
 		},
+		{
+			Name:   "Metadata from static file",
+			Input:  []string{"activities"},
+			Server: mockserver.Dummy(),
+			Expected: &common.ListObjectMetadataResult{
+				Result: map[string]common.ObjectMetadata{
+					"activities": {
+						DisplayName: "activities",
+						FieldsMap: map[string]string{
+							"activityDate":            "activityDate",
+							"activityTypeId":          "activityTypeId",
+							"attributes":              "attributes",
+							"campaignId":              "campaignId",
+							"id":                      "id",
+							"leadId":                  "leadId",
+							"marketoGUID":             "marketoGUID",
+							"primaryAttributeValue":   "primaryAttributeValue",
+							"primaryAttributeValueId": "primaryAttributeValueId",
+						},
+					},
+				},
+				Errors: make(map[string]error),
+			},
+			ExpectedErrs: nil,
+		},
 		{
 			Name:  "Successfully describe supported object",
 			Input: []string{"channels"},