Skip to content

Commit

Permalink
remove hyphens and underscores in references
Browse files Browse the repository at this point in the history
  • Loading branch information
rquitales committed Sep 12, 2024
1 parent c84d84d commit d11786b
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions pkg/codegen/customresourcegenerator.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func flattenRecursively(sw *spec.Swagger, parentName string, currSpec spec.Schem
}
// Create a new definition for the nested object by joining the parent definition name and the property name.
// This is to ensure that the nested object is unique and does not conflict with other definitions.
nestedDefinitionName := parentName + sanitizeFieldName(nestedPropertyName)
nestedDefinitionName := parentName + sanitizeReferenceName(nestedPropertyName)

// if nestedPropertyName == "bearerTokenSecret" {
// log.Println("bearerTokenSecret found: ", nestedDefinitionName)
Expand Down Expand Up @@ -176,11 +176,16 @@ func flattenRecursively(sw *spec.Swagger, parentName string, currSpec spec.Schem
return currSpec, nil
}

func sanitizeFieldName(fieldName string) string {
func sanitizeReferenceName(fieldName string) string {
// If the field name is "arg" or "args", we need to change it to "Arguments" to avoid conflicts with Go reserved words.
if s := strings.ToLower(fieldName); s == "arg" || s == "args" {
return "Arguments"
}

//We need to strip out any hyphens and underscores in the reference.
fieldName = cgstrings.Unhyphenate(fieldName)
fieldName = cgstrings.ModifyStringAroundDelimeter(fieldName, "_", cgstrings.UppercaseFirst)

return cgstrings.UppercaseFirst(fieldName)
}

Expand Down

0 comments on commit d11786b

Please sign in to comment.