-
Notifications
You must be signed in to change notification settings - Fork 96
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a "duration" string format #257
base: main
Are you sure you want to change the base?
Conversation
hey @ptodev the idea looks promising, are you still interested in pushing this one further? |
5f4c018
to
b385088
Compare
Hi, @omissis! I'd be very happy to address any feedback you have. I believe the code mostly generates what it needs to, but it's still WIP due to the TODOs. |
nothing against this one, so feel free to finish it and set it to "Ready for review" once all the todos and required fixes are done! thank you! 💪 |
_, ok := v.defaultValueType.(codegen.DurationType) | ||
if v.defaultValueType != nil && ok { | ||
defaultDurationISO8601, ok := v.defaultValue.(string) | ||
if !ok { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@omissis Do you think it is ok to leave these panic
statements here for now? It looks like the current code doesn't really have a way to guard aganst such invalid defaults, and so I'm not sure how to propagate the errors. For example, this schema:
"myNumber": {
"type": "number",
"default": "asdf"
},
... produces code like this:
type Primitives struct {
...
MyNumber float64 `json:"myNumber,omitempty" yaml:"myNumber,omitempty" mapstructure:"myNumber,omitempty"`
...
}
func (j *Primitives) UnmarshalJSON(b []byte) error {
...
if v, ok := raw["myNumber"]; !ok || v == nil {
plain.MyNumber = "asdf"
}
}
I've been trying to schematise the config of an application which uses
time.Duration
. Ideally, I'd like the generated Go code to use time.Duration.This PR is still at a very early stage. Please feel free to let me know if you approve the overall direction in which the work is going. Any help would be much appreciated! 😊