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:
parent
8e6ffc77a8
commit
30f8d1802b
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user