Skip to content

Commit ac2a1b7

Browse files
authored
Merge pull request kubernetes#85381 from sttts/sttts-apiextensions-fix-openapi-formats
apiextensions: freeze and document supported v1.16 OpenAPI formats
2 parents f0b1915 + 7f44afa commit ac2a1b7

File tree

11 files changed

+224
-10
lines changed

11 files changed

+224
-10
lines changed

api/openapi-spec/swagger.json

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

staging/src/k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1/generated.proto

Lines changed: 26 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

staging/src/k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1/types_jsonschema.go

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,36 @@ type JSONSchemaProps struct {
2323
Ref *string `json:"$ref,omitempty" protobuf:"bytes,3,opt,name=ref"`
2424
Description string `json:"description,omitempty" protobuf:"bytes,4,opt,name=description"`
2525
Type string `json:"type,omitempty" protobuf:"bytes,5,opt,name=type"`
26-
Format string `json:"format,omitempty" protobuf:"bytes,6,opt,name=format"`
27-
Title string `json:"title,omitempty" protobuf:"bytes,7,opt,name=title"`
26+
27+
// format is an OpenAPI v3 format string. Unknown formats are ignored. The following formats are validated:
28+
//
29+
// - bsonobjectid: a bson object ID, i.e. a 24 characters hex string
30+
// - uri: an URI as parsed by Golang net/url.ParseRequestURI
31+
// - email: an email address as parsed by Golang net/mail.ParseAddress
32+
// - hostname: a valid representation for an Internet host name, as defined by RFC 1034, section 3.1 [RFC1034].
33+
// - ipv4: an IPv4 IP as parsed by Golang net.ParseIP
34+
// - ipv6: an IPv6 IP as parsed by Golang net.ParseIP
35+
// - cidr: a CIDR as parsed by Golang net.ParseCIDR
36+
// - mac: a MAC address as parsed by Golang net.ParseMAC
37+
// - uuid: an UUID that allows uppercase defined by the regex (?i)^[0-9a-f]{8}-?[0-9a-f]{4}-?[0-9a-f]{4}-?[0-9a-f]{4}-?[0-9a-f]{12}$
38+
// - uuid3: an UUID3 that allows uppercase defined by the regex (?i)^[0-9a-f]{8}-?[0-9a-f]{4}-?3[0-9a-f]{3}-?[0-9a-f]{4}-?[0-9a-f]{12}$
39+
// - uuid4: an UUID4 that allows uppercase defined by the regex (?i)^[0-9a-f]{8}-?[0-9a-f]{4}-?4[0-9a-f]{3}-?[89ab][0-9a-f]{3}-?[0-9a-f]{12}$
40+
// - uuid5: an UUID5 that allows uppercase defined by the regex (?i)^[0-9a-f]{8}-?[0-9a-f]{4}-?5[0-9a-f]{3}-?[89ab][0-9a-f]{3}-?[0-9a-f]{12}$
41+
// - isbn: an ISBN10 or ISBN13 number string like "0321751043" or "978-0321751041"
42+
// - isbn10: an ISBN10 number string like "0321751043"
43+
// - isbn13: an ISBN13 number string like "978-0321751041"
44+
// - creditcard: a credit card number defined by the regex ^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|6(?:011|5[0-9][0-9])[0-9]{12}|3[47][0-9]{13}|3(?:0[0-5]|[68][0-9])[0-9]{11}|(?:2131|1800|35\\d{3})\\d{11})$ with any non digit characters mixed in
45+
// - ssn: a U.S. social security number following the regex ^\\d{3}[- ]?\\d{2}[- ]?\\d{4}$
46+
// - hexcolor: an hexadecimal color code like "#FFFFFF: following the regex ^#?([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$
47+
// - rgbcolor: an RGB color code like rgb like "rgb(255,255,2559"
48+
// - byte: base64 encoded binary data
49+
// - password: any kind of string
50+
// - date: a date string like "2006-01-02" as defined by full-date in RFC3339
51+
// - duration: a duration string like "22 ns" as parsed by Golang time.ParseDuration or compatible with Scala duration format
52+
// - datetime: a date time string like "2014-12-15T19:30:20.000Z" as defined by date-time in RFC3339.
53+
Format string `json:"format,omitempty" protobuf:"bytes,6,opt,name=format"`
54+
55+
Title string `json:"title,omitempty" protobuf:"bytes,7,opt,name=title"`
2856
// default is a default value for undefined object fields.
2957
// Defaulting is a beta feature under the CustomResourceDefaulting feature gate.
3058
// Defaulting requires spec.preserveUnknownFields to be false.

staging/src/k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1/generated.proto

Lines changed: 26 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

staging/src/k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1/types_jsonschema.go

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,36 @@ type JSONSchemaProps struct {
2323
Ref *string `json:"$ref,omitempty" protobuf:"bytes,3,opt,name=ref"`
2424
Description string `json:"description,omitempty" protobuf:"bytes,4,opt,name=description"`
2525
Type string `json:"type,omitempty" protobuf:"bytes,5,opt,name=type"`
26-
Format string `json:"format,omitempty" protobuf:"bytes,6,opt,name=format"`
27-
Title string `json:"title,omitempty" protobuf:"bytes,7,opt,name=title"`
26+
27+
// format is an OpenAPI v3 format string. Unknown formats are ignored. The following formats are validated:
28+
//
29+
// - bsonobjectid: a bson object ID, i.e. a 24 characters hex string
30+
// - uri: an URI as parsed by Golang net/url.ParseRequestURI
31+
// - email: an email address as parsed by Golang net/mail.ParseAddress
32+
// - hostname: a valid representation for an Internet host name, as defined by RFC 1034, section 3.1 [RFC1034].
33+
// - ipv4: an IPv4 IP as parsed by Golang net.ParseIP
34+
// - ipv6: an IPv6 IP as parsed by Golang net.ParseIP
35+
// - cidr: a CIDR as parsed by Golang net.ParseCIDR
36+
// - mac: a MAC address as parsed by Golang net.ParseMAC
37+
// - uuid: an UUID that allows uppercase defined by the regex (?i)^[0-9a-f]{8}-?[0-9a-f]{4}-?[0-9a-f]{4}-?[0-9a-f]{4}-?[0-9a-f]{12}$
38+
// - uuid3: an UUID3 that allows uppercase defined by the regex (?i)^[0-9a-f]{8}-?[0-9a-f]{4}-?3[0-9a-f]{3}-?[0-9a-f]{4}-?[0-9a-f]{12}$
39+
// - uuid4: an UUID4 that allows uppercase defined by the regex (?i)^[0-9a-f]{8}-?[0-9a-f]{4}-?4[0-9a-f]{3}-?[89ab][0-9a-f]{3}-?[0-9a-f]{12}$
40+
// - uuid5: an UUID5 that allows uppercase defined by the regex (?i)^[0-9a-f]{8}-?[0-9a-f]{4}-?5[0-9a-f]{3}-?[89ab][0-9a-f]{3}-?[0-9a-f]{12}$
41+
// - isbn: an ISBN10 or ISBN13 number string like "0321751043" or "978-0321751041"
42+
// - isbn10: an ISBN10 number string like "0321751043"
43+
// - isbn13: an ISBN13 number string like "978-0321751041"
44+
// - creditcard: a credit card number defined by the regex ^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|6(?:011|5[0-9][0-9])[0-9]{12}|3[47][0-9]{13}|3(?:0[0-5]|[68][0-9])[0-9]{11}|(?:2131|1800|35\\d{3})\\d{11})$ with any non digit characters mixed in
45+
// - ssn: a U.S. social security number following the regex ^\\d{3}[- ]?\\d{2}[- ]?\\d{4}$
46+
// - hexcolor: an hexadecimal color code like "#FFFFFF: following the regex ^#?([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$
47+
// - rgbcolor: an RGB color code like rgb like "rgb(255,255,2559"
48+
// - byte: base64 encoded binary data
49+
// - password: any kind of string
50+
// - date: a date string like "2006-01-02" as defined by full-date in RFC3339
51+
// - duration: a duration string like "22 ns" as parsed by Golang time.ParseDuration or compatible with Scala duration format
52+
// - datetime: a date time string like "2014-12-15T19:30:20.000Z" as defined by date-time in RFC3339.
53+
Format string `json:"format,omitempty" protobuf:"bytes,6,opt,name=format"`
54+
55+
Title string `json:"title,omitempty" protobuf:"bytes,7,opt,name=title"`
2856
// default is a default value for undefined object fields.
2957
// Defaulting is a beta feature under the CustomResourceDefaulting feature gate.
3058
// CustomResourceDefinitions with defaults must be created using the v1 (or newer) CustomResourceDefinition API.

staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/customresource_handler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -710,7 +710,7 @@ func (r *crdHandler) getOrCreateServingInfoFor(uid types.UID, name string) (*crd
710710
if validationSchema != nil && validationSchema.OpenAPIV3Schema != nil && validationSchema.OpenAPIV3Schema.Properties != nil {
711711
if statusSchema, ok := validationSchema.OpenAPIV3Schema.Properties["status"]; ok {
712712
openapiSchema := &spec.Schema{}
713-
if err := apiservervalidation.ConvertJSONSchemaProps(&statusSchema, openapiSchema); err != nil {
713+
if err := apiservervalidation.ConvertJSONSchemaPropsWithPostProcess(&statusSchema, openapiSchema, apiservervalidation.StripUnsupportedFormatsPostProcess); err != nil {
714714
return nil, err
715715
}
716716
statusValidator = validate.NewSchemaValidator(openapiSchema, nil, "", strfmt.Default, validate.DisableObjectArrayTypeCheck(true))

staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/validation/BUILD

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,15 @@ load(
88

99
go_library(
1010
name = "go_default_library",
11-
srcs = ["validation.go"],
11+
srcs = [
12+
"formats.go",
13+
"validation.go",
14+
],
1215
importmap = "k8s.io/kubernetes/vendor/k8s.io/apiextensions-apiserver/pkg/apiserver/validation",
1316
importpath = "k8s.io/apiextensions-apiserver/pkg/apiserver/validation",
1417
deps = [
1518
"//staging/src/k8s.io/apiextensions-apiserver/pkg/apis/apiextensions:go_default_library",
19+
"//staging/src/k8s.io/apimachinery/pkg/util/sets:go_default_library",
1620
"//staging/src/k8s.io/apimachinery/pkg/util/validation/field:go_default_library",
1721
"//vendor/github.com/go-openapi/errors:go_default_library",
1822
"//vendor/github.com/go-openapi/spec:go_default_library",
@@ -36,7 +40,10 @@ filegroup(
3640

3741
go_test(
3842
name = "go_default_test",
39-
srcs = ["validation_test.go"],
43+
srcs = [
44+
"formats_test.go",
45+
"validation_test.go",
46+
],
4047
embed = [":go_default_library"],
4148
deps = [
4249
"//staging/src/k8s.io/apiextensions-apiserver/pkg/apis/apiextensions:go_default_library",
@@ -49,5 +56,6 @@ go_test(
4956
"//staging/src/k8s.io/apimachinery/pkg/util/json:go_default_library",
5057
"//staging/src/k8s.io/apimachinery/pkg/util/sets:go_default_library",
5158
"//vendor/github.com/go-openapi/spec:go_default_library",
59+
"//vendor/github.com/go-openapi/strfmt:go_default_library",
5260
],
5361
)

0 commit comments

Comments
 (0)