mirror of
https://github.com/rancher/norman.git
synced 2026-05-05 12:02:36 +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:
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user