Skip to content

Commit

Permalink
Merge pull request #1609 from openmeterio/openapi-fixes
Browse files Browse the repository at this point in the history
fix: make id in subject a required-readOnly field
  • Loading branch information
sagikazarmark authored Oct 2, 2024
2 parents b4a5836 + 1ecde8b commit fb387b6
Show file tree
Hide file tree
Showing 8 changed files with 282 additions and 280 deletions.
274 changes: 137 additions & 137 deletions api/api.gen.go

Large diffs are not rendered by default.

272 changes: 136 additions & 136 deletions api/client/go/client.gen.go

Large diffs are not rendered by default.

4 changes: 1 addition & 3 deletions api/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3331,9 +3331,7 @@ components:
type: object
description: A subject is a unique identifier for a user or entity.
required:
# Validator doesn't obey required for readOnly properties
# See: https://github.com/stoplightio/spectral/issues/1274
# - id
- id
- key
additionalProperties: false
properties:
Expand Down
2 changes: 1 addition & 1 deletion openmeter/event/models/subject.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func (s SubjectKeyAndID) Validate() error {
}

type Subject struct {
Id *string `json:"id"`
Id string `json:"id"`
Key string `json:"key"`
DisplayName *string `json:"displayName,omitempty"`
Metadata map[string]interface{} `json:"metadata"`
Expand Down
2 changes: 1 addition & 1 deletion openmeter/notification/consumer/balancetreshold.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ func (b *BalanceThresholdEventHandler) createEvent(ctx context.Context, in creat
notification.AnnotationEventDedupeHash: in.DedupeHash,
}

if in.Snapshot.Subject.Id != nil && *in.Snapshot.Subject.Id != "" {
if in.Snapshot.Subject.Id != "" {
annotations[notification.AnnotationEventSubjectID] = in.Snapshot.Subject.Id
}

Expand Down
2 changes: 1 addition & 1 deletion openmeter/notification/internal/rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func NewTestEventPayload(eventType notification.EventType) notification.EventPay
CurrentPeriodEnd: convert.ToPointer(from),
CurrentPeriodStart: convert.ToPointer(to),
DisplayName: convert.ToPointer("Test Subject 1"),
Id: convert.ToPointer("01J5AW0ZD6T8624PCK0Q5TYX71"),
Id: "01J5AW0ZD6T8624PCK0Q5TYX71",
Key: "test-subject-1",
Metadata: &map[string]interface{}{
"test-metadata-key": "test-metadata-value",
Expand Down
4 changes: 4 additions & 0 deletions openmeter/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ func NewServer(config *Config) (*Server, error) {
// Unfortunately, the OpenAPI 3 filter library doesn't support context changes
AuthenticationFunc: openapi3filter.NoopAuthenticationFunc,
SkipSettingDefaults: true,

// Excluding read-only validation because required and readOnly fields in our Go models are translated to non-nil fields, leading to a zero-value being passed to the API
// The OpenAPI spec says read-only fields SHOULD NOT be sent in requests, so technically it should be fine, hence disabling validation for now to make our life easier
ExcludeReadOnlyValidations: true,
},
}),
},
Expand Down
2 changes: 1 addition & 1 deletion test/notification/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func NewBalanceThresholdPayload() notification.EventPayload {
CurrentPeriodEnd: &time.Time{},
CurrentPeriodStart: &time.Time{},
DisplayName: nil,
Id: convert.ToPointer("01J4VD1XZH5HM705DCPB8XD5QD"),
Id: "01J4VD1XZH5HM705DCPB8XD5QD",
Key: "customer-1",
Metadata: nil,
StripeCustomerId: nil,
Expand Down

0 comments on commit fb387b6

Please sign in to comment.