@@ -53,17 +53,44 @@ func remapFieldName(name string) string {
5353 re := regexp .MustCompile (`[^a-zA-Z0-9_]` )
5454 clean := re .ReplaceAllString (name , "_" )
5555
56+ // Collapse multiple consecutive underscores
57+ clean = regexp .MustCompile (`_+` ).ReplaceAllString (clean , "_" )
58+
59+ // Trim leading underscores only (keep trailing to detect them)
60+ clean = strings .TrimLeft (clean , "_" )
61+
5662 // Split on underscores and camelCase
5763 parts := strings .Split (clean , "_" )
5864 result := ""
65+ hasContent := false
5966 for i , part := range parts {
6067 if part == "" {
68+ // If we have an empty part after having content, it means there was a trailing separator
69+ // Add a capitalized version of the last word
70+ if hasContent && i == len (parts )- 1 {
71+ // Get the base word (first non-empty part)
72+ for _ , p := range parts {
73+ if p != "" {
74+ result += strings .ToUpper (string (p [0 ])) + strings .ToLower (p [1 :])
75+ break
76+ }
77+ }
78+ }
6179 continue
6280 }
63- if i == 0 {
64- result = strings .ToLower (part )
81+ hasContent = true
82+ if i == 0 || result == "" {
83+ // For the first part, check if it's all uppercase
84+ if strings .ToUpper (part ) == part {
85+ // If all uppercase, convert entirely to lowercase
86+ result = strings .ToLower (part )
87+ } else {
88+ // Otherwise, make only the first character lowercase
89+ result = strings .ToLower (string (part [0 ])) + part [1 :]
90+ }
6591 } else {
66- result += strings .Title (strings .ToLower (part ))
92+ // For subsequent parts, capitalize first letter, lowercase rest
93+ result += strings .ToUpper (string (part [0 ])) + strings .ToLower (part [1 :])
6794 }
6895 }
6996
@@ -330,7 +357,7 @@ func buildGraphQLObjectType(schemaName string, info *SchemaInfo) *graphql.Object
330357 }
331358
332359 return graphql .NewObject (graphql.ObjectConfig {
333- Name : strings . Title ( strings . ToLower ( schemaName ) ),
360+ Name : sanitizeTypeName ( schemaName ),
334361 Fields : fields ,
335362 })
336363}
@@ -414,12 +441,16 @@ func sanitizeTypeName(propType string) string {
414441 // Remove dots and other invalid characters, capitalize words
415442 re := regexp .MustCompile (`[^a-zA-Z0-9]` )
416443 clean := re .ReplaceAllString (propType , "_" )
444+
445+ // Strip leading digits
446+ clean = regexp .MustCompile (`^[0-9]+` ).ReplaceAllString (clean , "" )
447+
417448 parts := strings .Split (clean , "_" )
418449
419450 result := ""
420451 for _ , part := range parts {
421452 if part != "" {
422- result += strings .Title ( strings .ToLower (part ) )
453+ result += strings .ToUpper ( string ( part [ 0 ])) + strings .ToLower (part [ 1 :] )
423454 }
424455 }
425456
@@ -443,7 +474,9 @@ func BuildDynamicGraphQLSchema(catalogSchema *CatalogSchema, metasBySchema map[s
443474 queryFields := graphql.Fields {}
444475
445476 for schemaName , objectType := range objectTypes {
446- fieldName := strings .ToLower (schemaName ) + "s" // e.g., "bundles", "packages"
477+ // Sanitize schema name by removing dots and special characters for GraphQL field name
478+ sanitized := regexp .MustCompile (`[^a-zA-Z0-9]` ).ReplaceAllString (schemaName , "" )
479+ fieldName := strings .ToLower (sanitized ) + "s" // e.g., "olmbundles", "olmpackages"
447480
448481 queryFields [fieldName ] = & graphql.Field {
449482 Type : graphql .NewList (objectType ),
@@ -463,7 +496,8 @@ func BuildDynamicGraphQLSchema(catalogSchema *CatalogSchema, metasBySchema map[s
463496 // Get the schema name from the field name
464497 currentSchemaName := ""
465498 for sn := range catalogSchema .Schemas {
466- if strings .ToLower (sn )+ "s" == p .Info .FieldName {
499+ sanitized := regexp .MustCompile (`[^a-zA-Z0-9]` ).ReplaceAllString (sn , "" )
500+ if strings .ToLower (sanitized )+ "s" == p .Info .FieldName {
467501 currentSchemaName = sn
468502 break
469503 }
0 commit comments