IncludeCustom takes in a remapping of golang types. Both the key and value of the map should be valid golang types. The key is the type to override, and the value is the new type. Typescript will be generated with the new type. Only named types can be overridden. Examples: "github.com/your/repo/pkg
(mappings map[GolangType]GolangType)
| 108 | // "github.com/your/repo/pkg.ExampleType": "string" |
| 109 | // "time.Time": "string" |
| 110 | func (p *GoParser) IncludeCustom(mappings map[GolangType]GolangType) error { |
| 111 | for k, v := range mappings { |
| 112 | // Make sure it parses |
| 113 | _, err := parseExpression(v) |
| 114 | if err != nil { |
| 115 | return fmt.Errorf("failed to parse expression %s: %w", v, err) |
| 116 | } |
| 117 | |
| 118 | v := v |
| 119 | p.typeOverrides[k] = func() bindings.ExpressionType { |
| 120 | exp, err := parseExpression(v) |
| 121 | if err != nil { |
| 122 | return ptr(bindings.KeywordUnknown) |
| 123 | } |
| 124 | return exp |
| 125 | } |
| 126 | } |
| 127 | |
| 128 | return nil |
| 129 | } |
| 130 | |
| 131 | // ExcludeCustom flags golang types to not be generated in the Typescript output. |
| 132 | func (p *GoParser) ExcludeCustom(fqnames ...string) error { |