diff --git a/pkg/codegen/customresourcegenerator.go b/pkg/codegen/customresourcegenerator.go index c4ff526..1634b33 100644 --- a/pkg/codegen/customresourcegenerator.go +++ b/pkg/codegen/customresourcegenerator.go @@ -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) @@ -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) }