My previous fix forced generated Go code to add time imports for []time.Time types, however, the change was missing an additional update included in this fix which will ensure that the import takes place at the top of the file (otherwise it would encounter a syntax error)
// This file was generated from JSON Schema using quicktype, do not modify it directly.
// To parse and unparse this JSON data, add this code to your project and do:
//
// models, err := UnmarshalModels(bytes)
// bytes, err = models.Marshal()
package generated
import "time"
import "encoding/json"
func UnmarshalModels(data []byte) (Models, error) {
var r Models
err := json.Unmarshal(data, &r)
return r, err
}
func (r *Models) Marshal() ([]byte, error) {
return json.Marshal(r)
}
type Models struct {
TimeRange []time.Time `json:"timeRange,omitempty"`
}
Notice: time import is where it should be, fixing #2530
fixes: #2530
My previous fix forced generated Go code to add time imports for []time.Time types, however, the change was missing an additional update included in this fix which will ensure that the import takes place at the top of the file (otherwise it would encounter a syntax error)
Changes:
Reproduction to fix bug:
Schema:
Generated Code:
Notice: time import is where it should be, fixing #2530