-
Notifications
You must be signed in to change notification settings - Fork 17
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
Unable to set default values for custom typed strings #194
Comments
Thank you for raising this issue, please try latest version
With a new version you should be able to define default on a type using |
Hi @vearutop ! thanks for the quick fix. In my project, I'm still having a bit of issues with this. The problem lies in the jsonschema-go. Specifically, it seems like there is an issue when the custom type appears as a part of more than one variable definition in the request payload. What I'm seeing (I apologies I snippet for this yet, I'll try and construct one, but for now I'll describe):
I think the solution is to change the code reference above to pull the cached object from |
^ PR open with updated test and code change |
Describe the bug
I'm trying to build an enum type that can be used for input. As a part of this, I'd like to be able to set a default value for the enum field as well. I'd like to be able to define this in code (for reuse) rather than as a struct tag (i.e make our actual inputs/outputs match the documentation).
However, when I try to use a custom type with the default struct tags, it seems as though the parser expects a json string/object rather than a string value. You can use a json string to get past this, but then default does something weird. Concrete example below.
To Reproduce
Observed behavior
Expected behavior
The API returns
all
.Side note: you can change this so it reads
default:"\"all\""
-- then the input validation passes, but your default ends up as the quoted json string"all"
, notall
(i.e. it is not possible to produce the valid enum option).--
I'm happy to make a contribution here if you can point me in the right direction. I did step through the code a bit. I tried Implementing a TextUn/Marshaller so that maybe the type would properly get set as a string in
jsonschema-go/reflect.go
, but that didn't seem to make anything better on the version I was using. I believe it's because string is added as "a" type, rather than "the" SimpleType, which causes thecheckInlineValue
to fall into thedefault
rather thanString
case (where it does ajson.Unmarshal
)The text was updated successfully, but these errors were encountered: