-
Notifications
You must be signed in to change notification settings - Fork 214
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
openapiv2 experimental json unmarshaler #319
Conversation
2394259
to
94f2c15
Compare
Since the wrapper has quite an impact on the performance, can we just provide a |
5952e45
to
283749e
Compare
That seems to be what keeps failing for some reason: AdditionalProperties: &spec.SchemaOrBool{
- Allows: true,
+ Allows: false,
Schema: &{},
}, |
Went through it, looks good to me. Except for the bug I don't understand. |
OK feel free to rebase now that #320 has merged. |
6987bd4
to
52157ce
Compare
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.
/lgtm
I don't have approval on pkg/validation
, but I would appreciate someone else's look at it. @dsnet?
limitations under the License. | ||
*/ | ||
|
||
package internal |
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.
Note for other reviewers, this package is at the right level because we'll probably use the same variable for OpenAPI v3 that lives in pkg/spec3
. Thanks!
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.
Should this be protected by a build tag rather than a variable?
I've generally recommended against open source projects using go-json-experiment
due to the following effect:
- Let module M depend on modules A and B.
- Module A depends on
go-json-experiment/[email protected]
. - Module B depends on
go-json-experiment/[email protected]
. - Let’s suppose a breaking change occurs between
v0.5.0
andv0.8.0
. - MVS dictates that
v0.8.0
be selected to build module M. - However, the use of
v0.8.0
can break package A since it is using the API forv0.5.0
, which is not compatible.
I don't know enough about the kubernetes/kube-openapi
whether this is a module that is only used to build a binary, or whether it is a module intended to be depended upon by many other modules. If the former, then guarding it with a variable sounds fine. If the latter, then we probably want to guard it with a build tag.
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.
Thanks for the explanation. One quick (and ugly, but we're used to it here) solution would be to just fork the go-json-experiment
into this repo so that we only depend internally on it, no more problem with MVS?
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.
@liggitt Do you have an opinion about the suggestion above? Thanks.
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.
Forking SGTM.
The license is BSD and the listed authors are the Go authors since I had originally started the project when I was a Google employee. It is currently developed by all non-Googlers, but every contributor is also a regular contributor to the Go toolchain, so have each signed the Google CLA.
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.
forking into an internal
third_party
package with correct attribution as an internal implementation detail until the go-json-experiment stabilizes sgtm
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.
I've forked it into pkg/internal/third_party/go-json-experiment/json
. I added a readme with the commit hash and a note about when it should be removed.
To fork I executed git clone
and removed .git
, .github
, go.mod
, go.sum
, and all .png
files. I am unsure if there is a more standard way to "fork" the package into our tree. Please let me know if the current way I've done it is 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.
Implementation generally LGTM.
limitations under the License. | ||
*/ | ||
|
||
package internal |
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.
Should this be protected by a build tag rather than a variable?
I've generally recommended against open source projects using go-json-experiment
due to the following effect:
- Let module M depend on modules A and B.
- Module A depends on
go-json-experiment/[email protected]
. - Module B depends on
go-json-experiment/[email protected]
. - Let’s suppose a breaking change occurs between
v0.5.0
andv0.8.0
. - MVS dictates that
v0.8.0
be selected to build module M. - However, the use of
v0.8.0
can break package A since it is using the API forv0.5.0
, which is not compatible.
I don't know enough about the kubernetes/kube-openapi
whether this is a module that is only used to build a binary, or whether it is a module intended to be depended upon by many other modules. If the former, then guarding it with a variable sounds fine. If the latter, then we probably want to guard it with a build tag.
I'm good on this, just waiting for Jordan to confirm if he's alright with the fork. |
func (s *StringOrArray) UnmarshalNextJSON(opts jsonv2.UnmarshalOptions, dec *jsonv2.Decoder) error { | ||
switch k := dec.PeekKind(); k { | ||
case '[': | ||
return opts.UnmarshalNext(dec, (*[]string)(s)) |
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.
does this switch StringOrArray from overwriting on multiple unmarshals to appending?
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.
no, but ive added a line to reset s
so it is explicit
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.
Question since I'm curious, what does the spec requires when it comes to multiple unmarshaling? I was experimenting the other day and it felt inconsistent to me.
limitations under the License. | ||
*/ | ||
|
||
package internal |
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.
forking into an internal
third_party
package with correct attribution as an internal implementation detail until the go-json-experiment stabilizes sgtm
func (s *StringOrArray) UnmarshalNextJSON(opts jsonv2.UnmarshalOptions, dec *jsonv2.Decoder) error { | ||
switch k := dec.PeekKind(); k { | ||
case '[': | ||
return opts.UnmarshalNext(dec, (*[]string)(s)) |
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.
Question since I'm curious, what does the spec requires when it comes to multiple unmarshaling? I was experimenting the other day and it felt inconsistent to me.
@dsnet The internal/third_party test is failing, is this something expected?! |
The minimum support version of It seems that we should either run tests on Go1.19 or patching a revert for go-json-experiment/json@ef074b6. |
c02624d
to
e07a798
Compare
/approve /hold for green CI on WIP PR in k/k |
tests are looking good, https://prow.k8s.io/pr-history/?org=kubernetes&repo=kubernetes&pr=112988 /hold cancel |
/lgtm |
looks like the testdata and tests get dropped when importing into kube, which is nice, but the png images referenced from the readme get kept, which is less nice... can we drop those from our import of the dependency? |
revert json experiment to 4987ed27d44794668c752d227a2d3a7be54570bc correct commit hash correct package path remove pngs
refactor name
refactor name
…ype which needs it adds subtest `UnmarshalEmbedded` that positively shows that there is at least one property per embedded field also does not use field labels, so compiler errors are thrown in event any are missing whoops
e07a798
to
8d49439
Compare
So did you just delete the files from the repo and that's it? |
/approve Thanks! |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: alexzielenski, apelisse, dsnet, liggitt The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
What's next?
|
Continuing work from #315
This PR adds integrates the work done by @dsnet in the above issue.
Adds fuzz tests and also tests for roundtripping.
Adds benchmark
jsonv2_via_jsonv1
uses the new experimental decoder but is triggered viajson.Unmarshal
rather than invokingjsonv2
directly. The legacy json wrapper does have a cost./cc @apelisse