Skip to content

Commit b9982d8

Browse files
authored
fix: mark json as omitempty to not explicitly set every field (#297)
* fix: mark json as omitempty to not explicitly set every field Fixes: #263 * fix: remove omitempty for required values * fix: set clientCert & Key as required for TLS
1 parent d66b354 commit b9982d8

File tree

6 files changed

+115
-115
lines changed

6 files changed

+115
-115
lines changed

pkg/jetstream/apis/jetstream/v1beta2/accounttypes.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ func (c *Account) GetSpec() interface{} {
2222

2323
// AccountSpec is the spec for a Account resource
2424
type AccountSpec struct {
25-
Servers []string `json:"servers"`
26-
TLS *TLSSecret `json:"tls"`
27-
Creds *CredsSecret `json:"creds"`
28-
Token *TokenSecret `json:"token"`
29-
User *User `json:"user"`
25+
Servers []string `json:"servers,omitempty"`
26+
TLS *TLSSecret `json:"tls,omitempty"`
27+
Creds *CredsSecret `json:"creds,omitempty"`
28+
Token *TokenSecret `json:"token,omitempty"`
29+
User *User `json:"user,omitempty"`
3030
}
3131

3232
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

pkg/jetstream/apis/jetstream/v1beta2/consumertypes.go

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -22,38 +22,38 @@ func (c *Consumer) GetSpec() interface{} {
2222

2323
// ConsumerSpec is the spec for a Consumer resource
2424
type ConsumerSpec struct {
25-
Description string `json:"description"`
26-
AckPolicy string `json:"ackPolicy"`
27-
AckWait string `json:"ackWait"`
28-
DeliverPolicy string `json:"deliverPolicy"`
29-
DeliverSubject string `json:"deliverSubject"`
30-
DeliverGroup string `json:"deliverGroup"`
31-
DurableName string `json:"durableName"` // Maps to Durable
32-
FilterSubject string `json:"filterSubject"`
33-
FilterSubjects []string `json:"filterSubjects"`
34-
FlowControl bool `json:"flowControl"`
35-
HeartbeatInterval string `json:"heartbeatInterval"` // Maps to IdleHeartbeat
36-
MaxAckPending int `json:"maxAckPending"`
37-
MaxDeliver int `json:"maxDeliver"`
38-
BackOff []string `json:"backoff"`
39-
MaxWaiting int `json:"maxWaiting"`
40-
OptStartSeq int `json:"optStartSeq"`
41-
OptStartTime string `json:"optStartTime"`
42-
RateLimitBps int `json:"rateLimitBps"` // Maps to RateLimit
43-
ReplayPolicy string `json:"replayPolicy"`
44-
SampleFreq string `json:"sampleFreq"` // Maps to SampleFrequency
45-
HeadersOnly bool `json:"headersOnly"`
46-
MaxRequestBatch int `json:"maxRequestBatch"`
47-
MaxRequestExpires string `json:"maxRequestExpires"`
48-
MaxRequestMaxBytes int `json:"maxRequestMaxBytes"`
49-
InactiveThreshold string `json:"inactiveThreshold"`
50-
Replicas int `json:"replicas"`
51-
MemStorage bool `json:"memStorage"` // Maps to MemoryStorage
52-
Metadata map[string]string `json:"metadata"`
53-
PauseUntil string `json:"pauseUntil"` // RFC3339 timestamp for pausing consumer
54-
PriorityPolicy string `json:"priorityPolicy"` // Priority policy: none, pinned_client, overflow, prioritized
55-
PinnedTTL string `json:"pinnedTtl"` // Duration for pinned client timeout
56-
PriorityGroups []string `json:"priorityGroups"` // List of priority groups
25+
Description string `json:"description,omitempty"`
26+
AckPolicy string `json:"ackPolicy,omitempty"`
27+
AckWait string `json:"ackWait,omitempty"`
28+
DeliverPolicy string `json:"deliverPolicy,omitempty"`
29+
DeliverSubject string `json:"deliverSubject,omitempty"`
30+
DeliverGroup string `json:"deliverGroup,omitempty"`
31+
DurableName string `json:"durableName,omitempty"` // Maps to Durable
32+
FilterSubject string `json:"filterSubject,omitempty"`
33+
FilterSubjects []string `json:"filterSubjects,omitempty"`
34+
FlowControl bool `json:"flowControl,omitempty"`
35+
HeartbeatInterval string `json:"heartbeatInterval,omitempty"` // Maps to IdleHeartbeat
36+
MaxAckPending int `json:"maxAckPending,omitempty"`
37+
MaxDeliver int `json:"maxDeliver,omitempty"`
38+
BackOff []string `json:"backoff,omitempty"`
39+
MaxWaiting int `json:"maxWaiting,omitempty"`
40+
OptStartSeq int `json:"optStartSeq,omitempty"`
41+
OptStartTime string `json:"optStartTime,omitempty"`
42+
RateLimitBps int `json:"rateLimitBps,omitempty"` // Maps to RateLimit
43+
ReplayPolicy string `json:"replayPolicy,omitempty"`
44+
SampleFreq string `json:"sampleFreq,omitempty"` // Maps to SampleFrequency
45+
HeadersOnly bool `json:"headersOnly,omitempty"`
46+
MaxRequestBatch int `json:"maxRequestBatch,omitempty"`
47+
MaxRequestExpires string `json:"maxRequestExpires,omitempty"`
48+
MaxRequestMaxBytes int `json:"maxRequestMaxBytes,omitempty"`
49+
InactiveThreshold string `json:"inactiveThreshold,omitempty"`
50+
Replicas int `json:"replicas,omitempty"`
51+
MemStorage bool `json:"memStorage,omitempty"` // Maps to MemoryStorage
52+
Metadata map[string]string `json:"metadata,omitempty"`
53+
PauseUntil string `json:"pauseUntil,omitempty"` // RFC3339 timestamp for pausing consumer
54+
PriorityPolicy string `json:"priorityPolicy,omitempty"` // Priority policy: none, pinned_client, overflow, prioritized
55+
PinnedTTL string `json:"pinnedTtl,omitempty"` // Duration for pinned client timeout
56+
PriorityGroups []string `json:"priorityGroups,omitempty"` // List of priority groups
5757

5858
StreamName string `json:"streamName"`
5959
BaseStreamConfig

pkg/jetstream/apis/jetstream/v1beta2/keyvaluetypes.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,18 @@ func (s *KeyValue) GetSpec() interface{} {
2323
// StreamSpec is the spec for a Stream resource
2424
type KeyValueSpec struct {
2525
Bucket string `json:"bucket"`
26-
Description string `json:"description"`
27-
MaxValueSize int `json:"maxValueSize"`
28-
History int `json:"history"`
29-
TTL string `json:"ttl"`
30-
MaxBytes int `json:"maxBytes"`
31-
Storage string `json:"storage"`
32-
Replicas int `json:"replicas"`
33-
Placement *StreamPlacement `json:"placement"`
34-
RePublish *RePublish `json:"republish"`
35-
Mirror *StreamSource `json:"mirror"`
36-
Sources []*StreamSource `json:"sources"`
37-
Compression bool `json:"compression"`
26+
Description string `json:"description,omitempty"`
27+
MaxValueSize int `json:"maxValueSize,omitempty"`
28+
History int `json:"history,omitempty"`
29+
TTL string `json:"ttl,omitempty"`
30+
MaxBytes int `json:"maxBytes,omitempty"`
31+
Storage string `json:"storage,omitempty"`
32+
Replicas int `json:"replicas,omitempty"`
33+
Placement *StreamPlacement `json:"placement,omitempty"`
34+
RePublish *RePublish `json:"republish,omitempty"`
35+
Mirror *StreamSource `json:"mirror,omitempty"`
36+
Sources []*StreamSource `json:"sources,omitempty"`
37+
Compression bool `json:"compression,omitempty"`
3838
BaseStreamConfig
3939
}
4040

pkg/jetstream/apis/jetstream/v1beta2/objectstoretypes.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ func (s *ObjectStore) GetSpec() interface{} {
2323
// StreamSpec is the spec for a Stream resource
2424
type ObjectStoreSpec struct {
2525
Bucket string `json:"bucket"`
26-
Description string `json:"description"`
27-
TTL string `json:"ttl"`
28-
MaxBytes int `json:"maxBytes"`
29-
Storage string `json:"storage"`
30-
Replicas int `json:"replicas"`
31-
Placement *StreamPlacement `json:"placement"`
32-
Compression bool `json:"compression"`
33-
Metadata map[string]string `json:"metadata"`
26+
Description string `json:"description,omitempty"`
27+
TTL string `json:"ttl,omitempty"`
28+
MaxBytes int `json:"maxBytes,omitempty"`
29+
Storage string `json:"storage,omitempty"`
30+
Replicas int `json:"replicas,omitempty"`
31+
Placement *StreamPlacement `json:"placement,omitempty"`
32+
Compression bool `json:"compression,omitempty"`
33+
Metadata map[string]string `json:"metadata,omitempty"`
3434
BaseStreamConfig
3535
}
3636

pkg/jetstream/apis/jetstream/v1beta2/streamtypes.go

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -23,42 +23,42 @@ func (s *Stream) GetSpec() interface{} {
2323
// StreamSpec is the spec for a Stream resource
2424
type StreamSpec struct {
2525
Name string `json:"name"`
26-
Description string `json:"description"`
27-
Subjects []string `json:"subjects"`
28-
Retention string `json:"retention"`
29-
MaxConsumers int `json:"maxConsumers"`
30-
MaxMsgsPerSubject int `json:"maxMsgsPerSubject"`
31-
MaxMsgs int `json:"maxMsgs"`
32-
MaxBytes int `json:"maxBytes"`
33-
MaxAge string `json:"maxAge"`
34-
MaxMsgSize int `json:"maxMsgSize"`
35-
Storage string `json:"storage"`
36-
Discard string `json:"discard"`
37-
Replicas int `json:"replicas"`
38-
NoAck bool `json:"noAck"`
39-
DuplicateWindow string `json:"duplicateWindow"` // Maps to Duplicates
40-
Placement *StreamPlacement `json:"placement"`
41-
Mirror *StreamSource `json:"mirror"`
42-
Sources []*StreamSource `json:"sources"`
43-
Compression string `json:"compression"`
44-
SubjectTransform *SubjectTransform `json:"subjectTransform"`
45-
RePublish *RePublish `json:"republish"`
46-
Sealed bool `json:"sealed"`
47-
DenyDelete bool `json:"denyDelete"`
48-
DenyPurge bool `json:"denyPurge"`
49-
AllowDirect bool `json:"allowDirect"`
50-
AllowRollup bool `json:"allowRollup"` // Maps to RollupAllowed
51-
MirrorDirect bool `json:"mirrorDirect"`
52-
DiscardPerSubject bool `json:"discardPerSubject"` // Maps to DiscardNewPer
53-
FirstSequence uint64 `json:"firstSequence"` // Maps to FirstSeq
54-
Metadata map[string]string `json:"metadata"`
55-
ConsumerLimits *ConsumerLimits `json:"consumerLimits"`
56-
AllowMsgTTL bool `json:"allowMsgTtl"`
57-
SubjectDeleteMarkerTTL string `json:"subjectDeleteMarkerTtl"`
58-
AllowMsgCounter bool `json:"allowMsgCounter"`
59-
AllowAtomicPublish bool `json:"allowAtomicPublish"`
60-
AllowMsgSchedules bool `json:"allowMsgSchedules"`
61-
PersistMode string `json:"persistMode"`
26+
Description string `json:"description,omitempty"`
27+
Subjects []string `json:"subjects,omitempty"`
28+
Retention string `json:"retention,omitempty"`
29+
MaxConsumers int `json:"maxConsumers,omitempty"`
30+
MaxMsgsPerSubject int `json:"maxMsgsPerSubject,omitempty"`
31+
MaxMsgs int `json:"maxMsgs,omitempty"`
32+
MaxBytes int `json:"maxBytes,omitempty"`
33+
MaxAge string `json:"maxAge,omitempty"`
34+
MaxMsgSize int `json:"maxMsgSize,omitempty"`
35+
Storage string `json:"storage,omitempty"`
36+
Discard string `json:"discard,omitempty"`
37+
Replicas int `json:"replicas,omitempty"`
38+
NoAck bool `json:"noAck,omitempty"`
39+
DuplicateWindow string `json:"duplicateWindow,omitempty"` // Maps to Duplicates
40+
Placement *StreamPlacement `json:"placement,omitempty"`
41+
Mirror *StreamSource `json:"mirror,omitempty"`
42+
Sources []*StreamSource `json:"sources,omitempty"`
43+
Compression string `json:"compression,omitempty"`
44+
SubjectTransform *SubjectTransform `json:"subjectTransform,omitempty"`
45+
RePublish *RePublish `json:"republish,omitempty"`
46+
Sealed bool `json:"sealed,omitempty"`
47+
DenyDelete bool `json:"denyDelete,omitempty"`
48+
DenyPurge bool `json:"denyPurge,omitempty"`
49+
AllowDirect bool `json:"allowDirect,omitempty"`
50+
AllowRollup bool `json:"allowRollup,omitempty"` // Maps to RollupAllowed
51+
MirrorDirect bool `json:"mirrorDirect,omitempty"`
52+
DiscardPerSubject bool `json:"discardPerSubject,omitempty"` // Maps to DiscardNewPer
53+
FirstSequence uint64 `json:"firstSequence,omitempty"` // Maps to FirstSeq
54+
Metadata map[string]string `json:"metadata,omitempty"`
55+
ConsumerLimits *ConsumerLimits `json:"consumerLimits,omitempty"`
56+
AllowMsgTTL bool `json:"allowMsgTtl,omitempty"`
57+
SubjectDeleteMarkerTTL string `json:"subjectDeleteMarkerTtl,omitempty"`
58+
AllowMsgCounter bool `json:"allowMsgCounter,omitempty"`
59+
AllowAtomicPublish bool `json:"allowAtomicPublish,omitempty"`
60+
AllowMsgSchedules bool `json:"allowMsgSchedules,omitempty"`
61+
PersistMode string `json:"persistMode,omitempty"`
6262
BaseStreamConfig
6363
}
6464

@@ -74,14 +74,14 @@ type StreamPlacement struct {
7474

7575
type StreamSource struct {
7676
Name string `json:"name"`
77-
OptStartSeq int `json:"optStartSeq"`
78-
OptStartTime string `json:"optStartTime"`
79-
FilterSubject string `json:"filterSubject"`
77+
OptStartSeq int `json:"optStartSeq,omitempty"`
78+
OptStartTime string `json:"optStartTime,omitempty"`
79+
FilterSubject string `json:"filterSubject,omitempty"`
8080

81-
ExternalAPIPrefix string `json:"externalApiPrefix"`
82-
ExternalDeliverPrefix string `json:"externalDeliverPrefix"`
81+
ExternalAPIPrefix string `json:"externalApiPrefix,omitempty"`
82+
ExternalDeliverPrefix string `json:"externalDeliverPrefix,omitempty"`
8383

84-
SubjectTransforms []*SubjectTransform `json:"subjectTransforms"`
84+
SubjectTransforms []*SubjectTransform `json:"subjectTransforms,omitempty"`
8585
}
8686

8787
type RePublish struct {

pkg/jetstream/apis/jetstream/v1beta2/types.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,46 +29,46 @@ type BaseStreamConfig struct {
2929
}
3030

3131
type ConnectionOpts struct {
32-
Account string `json:"account"`
33-
Creds string `json:"creds"`
34-
Nkey string `json:"nkey"`
35-
Servers []string `json:"servers"`
32+
Account string `json:"account,omitempty"`
33+
Creds string `json:"creds,omitempty"`
34+
Nkey string `json:"nkey,omitempty"`
35+
Servers []string `json:"servers,omitempty"`
3636
TLS TLS `json:"tls"`
37-
TLSFirst bool `json:"tlsFirst"`
38-
JsDomain string `json:"jsDomain"`
37+
TLSFirst bool `json:"tlsFirst,omitempty"`
38+
JsDomain string `json:"jsDomain,omitempty"`
3939
}
4040

4141
type ConsumerLimits struct {
42-
InactiveThreshold string `json:"inactiveThreshold"`
43-
MaxAckPending int `json:"maxAckPending"`
42+
InactiveThreshold string `json:"inactiveThreshold,omitempty"`
43+
MaxAckPending int `json:"maxAckPending,omitempty"`
4444
}
4545

4646
type TLS struct {
4747
ClientCert string `json:"clientCert"`
4848
ClientKey string `json:"clientKey"`
49-
RootCAs []string `json:"rootCas"`
49+
RootCAs []string `json:"rootCas,omitempty"`
5050
}
5151

5252
type TLSSecret struct {
53-
ClientCert string `json:"cert"`
54-
ClientKey string `json:"key"`
55-
RootCAs string `json:"ca"`
53+
ClientCert string `json:"cert,omitempty"`
54+
ClientKey string `json:"key,omitempty"`
55+
RootCAs string `json:"ca,omitempty"`
5656
Secret *SecretRef `json:"secret"`
5757
}
5858

5959
type CredsSecret struct {
60-
File string `json:"file"`
60+
File string `json:"file,omitempty"`
6161
Secret *SecretRef `json:"secret"`
6262
}
6363

6464
type TokenSecret struct {
65-
Token string `json:"token"`
65+
Token string `json:"token,omitempty"`
6666
Secret SecretRef `json:"secret"`
6767
}
6868

6969
type User struct {
70-
User string `json:"user"`
71-
Password string `json:"password"`
70+
User string `json:"user,omitempty"`
71+
Password string `json:"password,omitempty"`
7272
Secret SecretRef `json:"secret"`
7373
}
7474

0 commit comments

Comments
 (0)