Skip to content
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

Fields with omitempty tag should still be considered as optional #37174

Merged
merged 2 commits into from
Nov 21, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 2 additions & 24 deletions api/openapi-spec/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -35745,11 +35745,7 @@
"description": "DeploymentCondition describes the state of a deployment at a certain point.",
"required": [
"type",
"status",
"lastUpdateTime",
"lastTransitionTime",
"reason",
"message"
"status"
],
"properties": {
"lastTransitionTime": {
Expand Down Expand Up @@ -35824,8 +35820,7 @@
"v1beta1.DeploymentSpec": {
"description": "DeploymentSpec is the specification of the desired behavior of the Deployment.",
"required": [
"template",
"progressDeadlineSeconds"
"template"
],
"properties": {
"minReadySeconds": {
Expand Down Expand Up @@ -35872,9 +35867,6 @@
},
"v1beta1.DeploymentStatus": {
"description": "DeploymentStatus is the most recently observed status of the Deployment.",
"required": [
"conditions"
],
"properties": {
"availableReplicas": {
"description": "Total number of available pods (ready for at least minReadySeconds) targeted by this deployment.",
Expand Down Expand Up @@ -35925,10 +35917,6 @@
},
"v1beta1.Eviction": {
"description": "Eviction evicts a pod from its node subject to certain policies and safety constraints. This is a subresource of Pod. A request to cause such an eviction is created by POSTing to .../pods/\u003cpod name\u003e/evictions.",
"required": [
"metadata",
"deleteOptions"
],
"properties": {
"deleteOptions": {
"description": "DeleteOptions may be provided",
Expand Down Expand Up @@ -36411,11 +36399,6 @@
},
"v1beta1.PodDisruptionBudget": {
"description": "PodDisruptionBudget is an object to define the max disruption that can be caused to a collection of pods",
"required": [
"metadata",
"spec",
"status"
],
"properties": {
"metadata": {
"$ref": "#/definitions/v1.ObjectMeta"
Expand All @@ -36433,7 +36416,6 @@
"v1beta1.PodDisruptionBudgetList": {
"description": "PodDisruptionBudgetList is a collection of PodDisruptionBudgets.",
"required": [
"metadata",
"items"
],
"properties": {
Expand All @@ -36450,10 +36432,6 @@
},
"v1beta1.PodDisruptionBudgetSpec": {
"description": "PodDisruptionBudgetSpec is a description of a PodDisruptionBudget.",
"required": [
"minAvailable",
"selector"
],
"properties": {
"minAvailable": {
"description": "An eviction is allowed if at least \"minAvailable\" pods selected by \"selector\" will still be available after the eviction, i.e. even in the absence of the evicted pod. So for example you can prevent all voluntary evictions by specifying \"100%\".",
Expand Down
13 changes: 9 additions & 4 deletions cmd/libs/go2idl/openapi-gen/generators/openapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,14 @@ func hasOpenAPITagValue(comments []string, value string) bool {
return false
}

func hasOptionalTag(comments []string) bool {
tagValues := types.ExtractCommentTags("+", comments)[tagOptional]
return tagValues != nil
// hasOptionalTag returns true if the member has +optional in its comments or
// omitempty in its json tags.
func hasOptionalTag(m *types.Member) bool {
hasOptionalCommentTag := types.ExtractCommentTags(
"+", m.CommentLines)[tagOptional] != nil
hasOptionalJsonTag := strings.Contains(
reflect.StructTag(m.Tags).Get("json"), "omitempty")
return hasOptionalCommentTag || hasOptionalJsonTag
}

// NameSystems returns the name system used by the generators in this package.
Expand Down Expand Up @@ -288,7 +293,7 @@ func (g openAPITypeWriter) generate(t *types.Type) error {
if name == "" {
continue
}
if !hasOptionalTag(m.CommentLines) {
if !hasOptionalTag(&m) {
required = append(required, name)
}
if err := g.generateProperty(&m); err != nil {
Expand Down
12 changes: 2 additions & 10 deletions federation/apis/openapi-spec/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -9757,11 +9757,7 @@
"description": "DeploymentCondition describes the state of a deployment at a certain point.",
"required": [
"type",
"status",
"lastUpdateTime",
"lastTransitionTime",
"reason",
"message"
"status"
],
"properties": {
"lastTransitionTime": {
Expand Down Expand Up @@ -9836,8 +9832,7 @@
"v1beta1.DeploymentSpec": {
"description": "DeploymentSpec is the specification of the desired behavior of the Deployment.",
"required": [
"template",
"progressDeadlineSeconds"
"template"
],
"properties": {
"minReadySeconds": {
Expand Down Expand Up @@ -9884,9 +9879,6 @@
},
"v1beta1.DeploymentStatus": {
"description": "DeploymentStatus is the most recently observed status of the Deployment.",
"required": [
"conditions"
],
"properties": {
"availableReplicas": {
"description": "Total number of available pods (ready for at least minReadySeconds) targeted by this deployment.",
Expand Down
25 changes: 8 additions & 17 deletions pkg/generated/openapi/zz_generated.openapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -3011,7 +3011,7 @@ var OpenAPIDefinitions *common.OpenAPIDefinitions = &common.OpenAPIDefinitions{
},
},
},
Required: []string{"TypeMeta", "podManifestPath", "syncFrequency", "fileCheckFrequency", "httpCheckFrequency", "manifestURL", "manifestURLHeader", "enableServer", "address", "port", "readOnlyPort", "tlsCertFile", "tlsPrivateKeyFile", "certDirectory", "authentication", "authorization", "hostnameOverride", "podInfraContainerImage", "dockerEndpoint", "rootDirectory", "seccompProfileRoot", "allowPrivileged", "hostNetworkSources", "hostPIDSources", "hostIPCSources", "registryPullQPS", "registryBurst", "eventRecordQPS", "eventBurst", "enableDebuggingHandlers", "minimumGCAge", "maxPerPodContainerCount", "maxContainerCount", "cAdvisorPort", "healthzPort", "healthzBindAddress", "oomScoreAdj", "registerNode", "clusterDomain", "masterServiceNamespace", "clusterDNS", "streamingConnectionIdleTimeout", "nodeStatusUpdateFrequency", "imageMinimumGCAge", "imageGCHighThresholdPercent", "imageGCLowThresholdPercent", "lowDiskSpaceThresholdMB", "volumeStatsAggPeriod", "networkPluginName", "networkPluginMTU", "networkPluginDir", "cniConfDir", "cniBinDir", "volumePluginDir", "containerRuntime", "remoteRuntimeEndpoint", "remoteImageEndpoint", "experimentalMounterPath", "lockFilePath", "exitOnLockContention", "hairpinMode", "babysitDaemons", "maxPods", "nvidiaGPUs", "dockerExecHandlerName", "podCIDR", "resolvConf", "cpuCFSQuota", "containerized", "maxOpenFiles", "reconcileCIDR", "registerSchedulable", "contentType", "kubeAPIQPS", "kubeAPIBurst", "serializeImagePulls", "nodeLabels", "nonMasqueradeCIDR", "enableCustomMetrics", "podsPerCore", "enableControllerAttachDetach", "systemReserved", "kubeReserved", "protectKernelDefaults", "makeIPTablesUtilChains", "iptablesMasqueradeBit", "iptablesDropBit", "featureGates", "experimentalFailSwapOn", "ExperimentalCheckNodeCapabilitiesBeforeMount"},
Required: []string{"TypeMeta", "podManifestPath", "syncFrequency", "fileCheckFrequency", "httpCheckFrequency", "manifestURL", "manifestURLHeader", "enableServer", "address", "port", "readOnlyPort", "tlsCertFile", "tlsPrivateKeyFile", "certDirectory", "authentication", "authorization", "hostnameOverride", "podInfraContainerImage", "dockerEndpoint", "rootDirectory", "seccompProfileRoot", "allowPrivileged", "hostNetworkSources", "hostPIDSources", "hostIPCSources", "registryPullQPS", "registryBurst", "eventRecordQPS", "eventBurst", "enableDebuggingHandlers", "minimumGCAge", "maxPerPodContainerCount", "maxContainerCount", "cAdvisorPort", "healthzPort", "healthzBindAddress", "oomScoreAdj", "registerNode", "clusterDomain", "masterServiceNamespace", "clusterDNS", "streamingConnectionIdleTimeout", "nodeStatusUpdateFrequency", "imageMinimumGCAge", "imageGCHighThresholdPercent", "imageGCLowThresholdPercent", "lowDiskSpaceThresholdMB", "volumeStatsAggPeriod", "networkPluginName", "networkPluginMTU", "networkPluginDir", "cniConfDir", "cniBinDir", "volumePluginDir", "containerRuntime", "remoteRuntimeEndpoint", "remoteImageEndpoint", "lockFilePath", "exitOnLockContention", "hairpinMode", "babysitDaemons", "maxPods", "nvidiaGPUs", "dockerExecHandlerName", "podCIDR", "resolvConf", "cpuCFSQuota", "containerized", "maxOpenFiles", "reconcileCIDR", "registerSchedulable", "contentType", "kubeAPIQPS", "kubeAPIBurst", "serializeImagePulls", "nodeLabels", "nonMasqueradeCIDR", "enableCustomMetrics", "podsPerCore", "enableControllerAttachDetach", "systemReserved", "kubeReserved", "protectKernelDefaults", "makeIPTablesUtilChains", "iptablesMasqueradeBit", "iptablesDropBit", "featureGates"},
},
},
Dependencies: []string{
Expand Down Expand Up @@ -3245,7 +3245,6 @@ var OpenAPIDefinitions *common.OpenAPIDefinitions = &common.OpenAPIDefinitions{
},
},
},
Required: []string{"name"},
},
},
Dependencies: []string{},
Expand Down Expand Up @@ -3541,7 +3540,7 @@ var OpenAPIDefinitions *common.OpenAPIDefinitions = &common.OpenAPIDefinitions{
},
},
},
Required: []string{"type", "status", "lastUpdateTime", "lastTransitionTime", "reason", "message"},
Required: []string{"type", "status"},
},
},
Dependencies: []string{
Expand Down Expand Up @@ -3679,7 +3678,7 @@ var OpenAPIDefinitions *common.OpenAPIDefinitions = &common.OpenAPIDefinitions{
},
},
},
Required: []string{"template", "progressDeadlineSeconds"},
Required: []string{"template"},
},
},
Dependencies: []string{
Expand Down Expand Up @@ -3738,7 +3737,6 @@ var OpenAPIDefinitions *common.OpenAPIDefinitions = &common.OpenAPIDefinitions{
},
},
},
Required: []string{"conditions"},
},
},
Dependencies: []string{
Expand Down Expand Up @@ -4900,7 +4898,6 @@ var OpenAPIDefinitions *common.OpenAPIDefinitions = &common.OpenAPIDefinitions{
},
},
},
Required: []string{"versions"},
},
},
Dependencies: []string{
Expand Down Expand Up @@ -10579,7 +10576,6 @@ var OpenAPIDefinitions *common.OpenAPIDefinitions = &common.OpenAPIDefinitions{
},
},
},
Required: []string{"photonPersistentDisk"},
},
},
Dependencies: []string{
Expand Down Expand Up @@ -10687,7 +10683,7 @@ var OpenAPIDefinitions *common.OpenAPIDefinitions = &common.OpenAPIDefinitions{
},
},
},
Required: []string{"pdID", "fsType"},
Required: []string{"pdID"},
},
},
Dependencies: []string{},
Expand Down Expand Up @@ -13193,7 +13189,6 @@ var OpenAPIDefinitions *common.OpenAPIDefinitions = &common.OpenAPIDefinitions{
},
},
},
Required: []string{"photonPersistentDisk"},
},
},
Dependencies: []string{
Expand Down Expand Up @@ -14813,7 +14808,7 @@ var OpenAPIDefinitions *common.OpenAPIDefinitions = &common.OpenAPIDefinitions{
},
},
},
Required: []string{"TypeMeta", "podManifestPath", "syncFrequency", "fileCheckFrequency", "httpCheckFrequency", "manifestURL", "manifestURLHeader", "enableServer", "address", "port", "readOnlyPort", "tlsCertFile", "tlsPrivateKeyFile", "certDirectory", "authentication", "authorization", "hostnameOverride", "podInfraContainerImage", "dockerEndpoint", "rootDirectory", "seccompProfileRoot", "allowPrivileged", "hostNetworkSources", "hostPIDSources", "hostIPCSources", "registryPullQPS", "registryBurst", "eventRecordQPS", "eventBurst", "enableDebuggingHandlers", "minimumGCAge", "maxPerPodContainerCount", "maxContainerCount", "cAdvisorPort", "healthzPort", "healthzBindAddress", "oomScoreAdj", "registerNode", "clusterDomain", "masterServiceNamespace", "clusterDNS", "streamingConnectionIdleTimeout", "nodeStatusUpdateFrequency", "imageMinimumGCAge", "imageGCHighThresholdPercent", "imageGCLowThresholdPercent", "lowDiskSpaceThresholdMB", "volumeStatsAggPeriod", "networkPluginName", "networkPluginDir", "cniConfDir", "cniBinDir", "networkPluginMTU", "volumePluginDir", "cloudProvider", "cloudConfigFile", "kubeletCgroups", "runtimeCgroups", "systemCgroups", "cgroupRoot", "containerRuntime", "remoteRuntimeEndpoint", "remoteImageEndpoint", "runtimeRequestTimeout", "rktPath", "experimentalMounterPath", "rktAPIEndpoint", "rktStage1Image", "lockFilePath", "exitOnLockContention", "hairpinMode", "babysitDaemons", "maxPods", "nvidiaGPUs", "dockerExecHandlerName", "podCIDR", "resolvConf", "cpuCFSQuota", "containerized", "maxOpenFiles", "reconcileCIDR", "registerSchedulable", "contentType", "kubeAPIQPS", "kubeAPIBurst", "serializeImagePulls", "outOfDiskTransitionFrequency", "nodeIP", "nodeLabels", "nonMasqueradeCIDR", "enableCustomMetrics", "evictionHard", "evictionSoft", "evictionSoftGracePeriod", "evictionPressureTransitionPeriod", "evictionMaxPodGracePeriod", "evictionMinimumReclaim", "podsPerCore", "enableControllerAttachDetach", "systemReserved", "kubeReserved", "protectKernelDefaults", "makeIPTablesUtilChains", "iptablesMasqueradeBit", "iptablesDropBit", "featureGates", "experimentalFailSwapOn", "ExperimentalCheckNodeCapabilitiesBeforeMount"},
Required: []string{"TypeMeta", "podManifestPath", "syncFrequency", "fileCheckFrequency", "httpCheckFrequency", "manifestURL", "manifestURLHeader", "enableServer", "address", "port", "readOnlyPort", "tlsCertFile", "tlsPrivateKeyFile", "certDirectory", "authentication", "authorization", "hostnameOverride", "podInfraContainerImage", "dockerEndpoint", "rootDirectory", "seccompProfileRoot", "allowPrivileged", "hostNetworkSources", "hostPIDSources", "hostIPCSources", "registryPullQPS", "registryBurst", "eventRecordQPS", "eventBurst", "enableDebuggingHandlers", "minimumGCAge", "maxPerPodContainerCount", "maxContainerCount", "cAdvisorPort", "healthzPort", "healthzBindAddress", "oomScoreAdj", "registerNode", "clusterDomain", "masterServiceNamespace", "clusterDNS", "streamingConnectionIdleTimeout", "nodeStatusUpdateFrequency", "imageMinimumGCAge", "imageGCHighThresholdPercent", "imageGCLowThresholdPercent", "lowDiskSpaceThresholdMB", "volumeStatsAggPeriod", "networkPluginName", "networkPluginDir", "cniConfDir", "cniBinDir", "networkPluginMTU", "volumePluginDir", "cloudProvider", "cloudConfigFile", "kubeletCgroups", "runtimeCgroups", "systemCgroups", "cgroupRoot", "containerRuntime", "remoteRuntimeEndpoint", "remoteImageEndpoint", "runtimeRequestTimeout", "rktPath", "rktAPIEndpoint", "rktStage1Image", "lockFilePath", "exitOnLockContention", "hairpinMode", "babysitDaemons", "maxPods", "nvidiaGPUs", "dockerExecHandlerName", "podCIDR", "resolvConf", "cpuCFSQuota", "containerized", "maxOpenFiles", "reconcileCIDR", "registerSchedulable", "contentType", "kubeAPIQPS", "kubeAPIBurst", "serializeImagePulls", "outOfDiskTransitionFrequency", "nodeIP", "nodeLabels", "nonMasqueradeCIDR", "enableCustomMetrics", "evictionHard", "evictionSoft", "evictionSoftGracePeriod", "evictionPressureTransitionPeriod", "evictionMaxPodGracePeriod", "evictionMinimumReclaim", "podsPerCore", "enableControllerAttachDetach", "systemReserved", "kubeReserved", "protectKernelDefaults", "makeIPTablesUtilChains", "iptablesMasqueradeBit", "iptablesDropBit"},
},
},
Dependencies: []string{
Expand Down Expand Up @@ -15724,7 +15719,7 @@ var OpenAPIDefinitions *common.OpenAPIDefinitions = &common.OpenAPIDefinitions{
},
},
},
Required: []string{"type", "status", "lastUpdateTime", "lastTransitionTime", "reason", "message"},
Required: []string{"type", "status"},
},
},
Dependencies: []string{
Expand Down Expand Up @@ -15865,7 +15860,7 @@ var OpenAPIDefinitions *common.OpenAPIDefinitions = &common.OpenAPIDefinitions{
},
},
},
Required: []string{"template", "progressDeadlineSeconds"},
Required: []string{"template"},
},
},
Dependencies: []string{
Expand Down Expand Up @@ -15925,7 +15920,6 @@ var OpenAPIDefinitions *common.OpenAPIDefinitions = &common.OpenAPIDefinitions{
},
},
},
Required: []string{"conditions"},
},
},
Dependencies: []string{
Expand Down Expand Up @@ -15973,7 +15967,6 @@ var OpenAPIDefinitions *common.OpenAPIDefinitions = &common.OpenAPIDefinitions{
},
},
},
Required: []string{"metadata", "deleteOptions"},
},
},
Dependencies: []string{
Expand Down Expand Up @@ -16950,7 +16943,6 @@ var OpenAPIDefinitions *common.OpenAPIDefinitions = &common.OpenAPIDefinitions{
},
},
},
Required: []string{"metadata", "spec", "status"},
},
},
Dependencies: []string{
Expand Down Expand Up @@ -16979,7 +16971,7 @@ var OpenAPIDefinitions *common.OpenAPIDefinitions = &common.OpenAPIDefinitions{
},
},
},
Required: []string{"metadata", "items"},
Required: []string{"items"},
},
},
Dependencies: []string{
Expand All @@ -17003,7 +16995,6 @@ var OpenAPIDefinitions *common.OpenAPIDefinitions = &common.OpenAPIDefinitions{
},
},
},
Required: []string{"minAvailable", "selector"},
},
},
Dependencies: []string{
Expand Down