package rules
import "k8s.io/kube-openapi/pkg/generators/rules"
Package rules contains API rules that are enforced in OpenAPI spec generation as part of the machinery. Files under this package implement APIRule interface which evaluates Go type and produces list of API rule violations.
Implementations of APIRule should be added to API linter under openAPIGen code- generator to get integrated in the generation process.
Index ¶
- Constants
- type ListTypeMissing
- func (l *ListTypeMissing) Name() string
- func (l *ListTypeMissing) Validate(t *types.Type) ([]string, error)
- type NamesMatch
- type OmitEmptyMatchCase
- func (n *OmitEmptyMatchCase) Name() string
- func (n *OmitEmptyMatchCase) Validate(t *types.Type) ([]string, error)
- type StreamingListTypeFieldOrder
- func (l *StreamingListTypeFieldOrder) Name() string
- func (l *StreamingListTypeFieldOrder) Validate(t *types.Type) ([]string, error)
- type StreamingListTypeJSONTags
- func (l *StreamingListTypeJSONTags) Name() string
- func (l *StreamingListTypeJSONTags) Validate(t *types.Type) ([]string, error)
- type StreamingListTypeProtoTags
Constants ¶
const ListTypeIDLTag = "listType"
Types ¶
type ListTypeMissing ¶
type ListTypeMissing struct{}
ListTypeMissing implements APIRule interface. A list type is required for inlined list.
func (*ListTypeMissing) Name ¶
func (l *ListTypeMissing) Name() string
Name returns the name of APIRule
func (*ListTypeMissing) Validate ¶
func (l *ListTypeMissing) Validate(t *types.Type) ([]string, error)
Validate evaluates API rule on type t and returns a list of field names in the type that violate the rule. Empty field name [""] implies the entire type violates the rule.
type NamesMatch ¶
type NamesMatch struct{}
NamesMatch implements APIRule interface. Go field names must be CamelCase. JSON field names must be camelCase. Other than capitalization of the initial letter, the two should almost always match. No underscores nor dashes in either. This rule verifies the convention "Other than capitalization of the initial letter, the two should almost always match." Examples (also in unit test):
Go name | JSON name | match podSpec false PodSpec podSpec true PodSpec PodSpec false podSpec podSpec false PodSpec spec false Spec podSpec false JSONSpec jsonSpec true JSONSpec jsonspec false HTTPJSONSpec httpJSONSpec true
NOTE: this validator cannot tell two sequential all-capital words from one word, therefore the case below is also considered matched.
HTTPJSONSpec httpjsonSpec true
NOTE: an empty JSON name is valid only for inlined structs or pointer to structs. It cannot be empty for anything else because capitalization must be set explicitly.
NOTE: metav1.ListMeta and metav1.ObjectMeta by convention must have "metadata" as name. Other fields may have that JSON name if the field name matches.
func (*NamesMatch) Name ¶
func (n *NamesMatch) Name() string
Name returns the name of APIRule
func (*NamesMatch) Validate ¶
func (n *NamesMatch) Validate(t *types.Type) ([]string, error)
Validate evaluates API rule on type t and returns a list of field names in the type that violate the rule. Empty field name [""] implies the entire type violates the rule.
type OmitEmptyMatchCase ¶
type OmitEmptyMatchCase struct{}
OmitEmptyMatchCase implements APIRule interface. "omitempty" must appear verbatim (no case variants).
func (*OmitEmptyMatchCase) Name ¶
func (n *OmitEmptyMatchCase) Name() string
func (*OmitEmptyMatchCase) Validate ¶
func (n *OmitEmptyMatchCase) Validate(t *types.Type) ([]string, error)
type StreamingListTypeFieldOrder ¶
type StreamingListTypeFieldOrder struct{}
StreamingListTypeFieldOrder implements APIRule interface. Fields must be ordered TypeMeta, ListMeta, Items
func (*StreamingListTypeFieldOrder) Name ¶
func (l *StreamingListTypeFieldOrder) Name() string
func (*StreamingListTypeFieldOrder) Validate ¶
func (l *StreamingListTypeFieldOrder) Validate(t *types.Type) ([]string, error)
type StreamingListTypeJSONTags ¶
type StreamingListTypeJSONTags struct{}
StreamingListTypeJSONTags implements APIRule interface. Fields must be JSON-tagged
func (*StreamingListTypeJSONTags) Name ¶
func (l *StreamingListTypeJSONTags) Name() string
func (*StreamingListTypeJSONTags) Validate ¶
func (l *StreamingListTypeJSONTags) Validate(t *types.Type) ([]string, error)
type StreamingListTypeProtoTags ¶
type StreamingListTypeProtoTags struct{}
StreamingListTypeProtoTags implements APIRule interface. Fields must be Proto-tagged with specific tags for streaming to work.
func (*StreamingListTypeProtoTags) Name ¶
func (l *StreamingListTypeProtoTags) Name() string
func (*StreamingListTypeProtoTags) Validate ¶
func (l *StreamingListTypeProtoTags) Validate(t *types.Type) ([]string, error)
Source Files ¶
doc.go idl_tag.go list_type_streaming_tags.go names_match.go omitempty_match_case.go
- Version
- v0.0.0-20250318190949-c8a335a9a2ff (latest)
- Published
- Mar 18, 2025
- Platform
- linux/amd64
- Imports
- 5 packages
- Last checked
- 4 weeks ago –
Tools for package owners.