Skip to content

Commit

Permalink
Add 'nullablestring' field type
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
cmurphy committed May 1, 2021
1 parent 8e6ffc7 commit 30f8d18
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
2 changes: 2 additions & 0 deletions generator/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions parse/builder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 30f8d18

Please sign in to comment.