kubernetes / kube-openapi

Kubernetes OpenAPI spec generation & serving
Apache License 2.0
317 stars 205 forks source link

tighten validation of inlining and metadata #504

Closed pohly closed 4 weeks ago

pohly commented 1 month ago

This catches the following mistake:

type ResourceSliceList struct {
   metav1.ListMeta `json:"listMeta" protobuf:"bytes,1,opt,name=listMeta"`
   ...
}

The "listMeta" name matches the Go field name, but the convention is to call that JSON field "metadata".

The same applies to ObjectMeta.

While at it, usage of the empty JSON name also gets checked more thoroughly. This is a mistake which was not detected earlier:

type SomeStruct struct {
    SomeInt int `json:",inline"`
}
liggitt commented 1 month ago

/lgtm /approve

pohly commented 1 month ago

Using this in Kubernetes might be tricky, updating the dependency wasn't straight-forward - see https://github.com/kubernetes/kubernetes/pull/126917 (not including this PR yet).

liggitt commented 1 month ago

~try rebasing, some other fixups went in last week (https://github.com/kubernetes/kube-openapi/pull/507, https://github.com/kubernetes/kube-openapi/pull/508)~

I'd recommend waiting until https://github.com/kubernetes/kubernetes/pull/126787 gets in and handles the regen cleanup

liggitt commented 1 month ago

/lgtm

Jefftree commented 4 weeks ago

/lgtm /approve

k8s-ci-robot commented 4 weeks ago

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: Jefftree, liggitt, pohly

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: - ~~[pkg/generators/rules/OWNERS](https://github.com/kubernetes/kube-openapi/blob/master/pkg/generators/rules/OWNERS)~~ [Jefftree] Approvers can indicate their approval by writing `/approve` in a comment Approvers can cancel approval by writing `/approve cancel` in a comment