1
0
mirror of https://github.com/rancher/norman.git synced 2025-05-14 19:19:31 +00:00

Add 'nullablestring' field type

Currently, `*string` fields in Go structs are converted to `{type:
string, nullable: true}` in the API schema, which is right, but then
converted down to just `string` when converted to generated client
structs. Without this patch, there is no way to express that `*string`s
should stay as `*string`s when run through the generator, because the
'nullable' flag is ignored. Compare this to `*bool`s, which become
`boolean` in the schema and then correctly converted back to *bool in
the generator. This patch adds a backwards-compatible way to opt in to
converting `*string`s in the original struct to *strings in the
generated struct.
This commit is contained in:
Colleen Murphy 2021-05-01 15:46:03 -07:00
parent 8e6ffc77a8
commit 30f8d1802b
2 changed files with 4 additions and 0 deletions

View File

@ -81,6 +81,8 @@ func getTypeString(nullable bool, typeName string, schema *types.Schema, schemas
return "string"
case "hostname":
return "string"
case "nullablestring":
return "*string"
default:
if schema != nil && schemas != nil {
otherSchema := schemas.Schema(&schema.Version, typeName)

View File

@ -382,6 +382,8 @@ func ConvertSimple(fieldType string, value interface{}, op Operation) (interface
return convert.ToString(value), nil
case "reference":
return convert.ToString(value), nil
case "nullablestring":
return convert.ToString(value), nil
}
return nil, ErrComplexType