TypeMappings is all the custom types for codersdk
(gen *guts.GoParser)
| 98 | |
| 99 | // TypeMappings is all the custom types for codersdk |
| 100 | func TypeMappings(gen *guts.GoParser) error { |
| 101 | gen.IncludeCustomDeclaration(config.StandardMappings()) |
| 102 | |
| 103 | gen.IncludeCustomDeclaration(map[string]guts.TypeOverride{ |
| 104 | "github.com/coder/coder/v2/codersdk.NullTime": config.OverrideNullable(config.OverrideLiteral(bindings.KeywordString)), |
| 105 | // opt.Bool can return 'null' if unset |
| 106 | "tailscale.com/types/opt.Bool": config.OverrideNullable(config.OverrideLiteral(bindings.KeywordBoolean)), |
| 107 | // hcl diagnostics should be cast to `preview.FriendlyDiagnostic` |
| 108 | "github.com/hashicorp/hcl/v2.Diagnostic": func() bindings.ExpressionType { |
| 109 | return bindings.Reference(bindings.Identifier{ |
| 110 | Name: "FriendlyDiagnostic", |
| 111 | Package: nil, |
| 112 | Prefix: "", |
| 113 | }) |
| 114 | }, |
| 115 | "github.com/coder/preview/types.HCLString": func() bindings.ExpressionType { |
| 116 | return bindings.Reference(bindings.Identifier{ |
| 117 | Name: "NullHCLString", |
| 118 | Package: nil, |
| 119 | Prefix: "", |
| 120 | }) |
| 121 | }, |
| 122 | }) |
| 123 | |
| 124 | err := gen.IncludeCustom(map[string]string{ |
| 125 | // Serpent fields should be converted to their primitive types |
| 126 | "github.com/coder/serpent.Regexp": "string", |
| 127 | "github.com/coder/serpent.StringArray": "string", |
| 128 | "github.com/coder/serpent.String": "string", |
| 129 | "github.com/coder/serpent.YAMLConfigPath": "string", |
| 130 | "github.com/coder/serpent.Strings": "[]string", |
| 131 | "github.com/coder/serpent.Int64": "int64", |
| 132 | "github.com/coder/serpent.Bool": "bool", |
| 133 | "github.com/coder/serpent.Duration": "int64", |
| 134 | "github.com/coder/serpent.URL": "string", |
| 135 | "github.com/coder/serpent.HostPort": "string", |
| 136 | "encoding/json.RawMessage": "map[string]string", |
| 137 | // decimal.Decimal preserves exact pricing precision (e.g. $3.50 per |
| 138 | // million tokens) and serializes as a JSON string to avoid |
| 139 | // floating-point loss in transit. |
| 140 | "github.com/shopspring/decimal.Decimal": "string", |
| 141 | }) |
| 142 | if err != nil { |
| 143 | return xerrors.Errorf("include custom: %w", err) |
| 144 | } |
| 145 | |
| 146 | return nil |
| 147 | } |
| 148 | |
| 149 | // DiscriminatedChatMessagePart splits the flat ChatMessagePart |
| 150 | // interface into a discriminated union of per-type sub-interfaces. |