-
Notifications
You must be signed in to change notification settings - Fork 98
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
[bug]default value of number will get int #38
Comments
Hi! Not sure I understand your problem here. Could you give an example of what is not working as expected? Thanks. |
for example: package main
import (
"encoding/json"
"fmt"
"github.com/invopop/jsonschema"
)
type SampleUser struct {
FloatExp float64 `json:"floatexp" jsonschema:"default=12.3"`
}
func main() {
s := jsonschema.Reflect(&SampleUser{})
data, err := json.MarshalIndent(s, "", " ")
if err != nil {
panic(err.Error())
}
fmt.Println(string(data))
} will get: {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$ref": "#/$defs/SampleUser",
"$defs": {
"SampleUser": {
"properties": {
"floatexp": {
"type": "number",
"default": 0
}
},
"additionalProperties": false,
"type": "object",
"required": [
"floatexp"
]
}
}
} |
The default values set in struct tags get overwritten and are always 0 for float types. |
send a pull request #55 to fix |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
so if using the default value,it can not set into the struct .


The text was updated successfully, but these errors were encountered: