Skip to content

chore: Make destination config optional #348

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

Merged
merged 5 commits into from
May 19, 2025
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion cmd/e2e/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,6 @@ func (suite *basicSuite) TestDestinationsAPI() {
Body: map[string]interface{}{
"message": "validation error",
"data": map[string]interface{}{
"config": "required",
"topics": "required",
"type": "required",
},
Expand Down
44 changes: 12 additions & 32 deletions docs/apis/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ components:
type:
type: string
description: Type of the destination.
enum: [webhook] # Specific type
enum: [webhook]
example: "webhook"
topics:
$ref: "#/components/schemas/Topics"
Expand All @@ -238,7 +238,6 @@ components:
format: date-time
description: ISO Date when the destination was created.
example: "2024-01-01T00:00:00Z"
# Type-specific properties
config:
$ref: "#/components/schemas/WebhookConfig"
credentials:
Expand Down Expand Up @@ -279,7 +278,7 @@ components:
type:
type: string
description: Type of the destination.
enum: [aws_sqs] # Specific type
enum: [aws_sqs]
example: "aws_sqs"
topics:
$ref: "#/components/schemas/Topics"
Expand All @@ -294,7 +293,6 @@ components:
format: date-time
description: ISO Date when the destination was created.
example: "2024-01-01T00:00:00Z"
# Type-specific properties
config:
$ref: "#/components/schemas/AWSSQSConfig"
credentials:
Expand Down Expand Up @@ -335,7 +333,7 @@ components:
type:
type: string
description: Type of the destination.
enum: [rabbitmq] # Specific type
enum: [rabbitmq]
example: "rabbitmq"
topics:
$ref: "#/components/schemas/Topics"
Expand All @@ -350,7 +348,6 @@ components:
format: date-time
description: ISO Date when the destination was created.
example: "2024-01-01T00:00:00Z"
# Type-specific properties
config:
$ref: "#/components/schemas/RabbitMQConfig"
credentials:
Expand Down Expand Up @@ -392,7 +389,7 @@ components:
type:
type: string
description: Type of the destination.
enum: [hookdeck] # Specific type
enum: [hookdeck]
example: "hookdeck"
topics:
$ref: "#/components/schemas/Topics"
Expand All @@ -407,7 +404,6 @@ components:
format: date-time
description: ISO Date when the destination was created.
example: "2024-01-01T00:00:00Z"
# Type-specific properties
config: {} # Empty config
credentials:
$ref: "#/components/schemas/HookdeckCredentials"
Expand Down Expand Up @@ -444,7 +440,7 @@ components:
type:
type: string
description: Type of the destination.
enum: [aws_kinesis] # Specific type
enum: [aws_kinesis]
example: "aws_kinesis"
topics:
$ref: "#/components/schemas/Topics"
Expand All @@ -459,7 +455,6 @@ components:
format: date-time
description: ISO Date when the destination was created.
example: "2024-01-01T00:00:00Z"
# Type-specific properties
config:
$ref: "#/components/schemas/AWSKinesisConfig"
credentials:
Expand Down Expand Up @@ -508,8 +503,7 @@ components:

DestinationCreateWebhook:
type: object
# Properties duplicated from DestinationCreateBase
required: [type, topics, config] # Credentials not required for webhook create base
required: [type, topics, config]
properties:
id:
type: string
Expand All @@ -518,18 +512,16 @@ components:
type:
type: string
description: Type of the destination. Must be 'webhook'.
enum: [webhook] # Specific type
enum: [webhook]
topics:
$ref: "#/components/schemas/Topics"
# Type-specific properties
config:
$ref: "#/components/schemas/WebhookConfig"
credentials:
# Secret is optional on create for admin, forbidden for tenant
$ref: "#/components/schemas/WebhookCredentials"
DestinationCreateAWSSQS:
type: object
# Properties duplicated from DestinationCreateBase + specific required
required: [type, topics, config, credentials]
properties:
id:
Expand All @@ -539,17 +531,15 @@ components:
type:
type: string
description: Type of the destination. Must be 'aws_sqs'.
enum: [aws_sqs] # Specific type
enum: [aws_sqs]
topics:
$ref: "#/components/schemas/Topics"
# Type-specific properties
config:
$ref: "#/components/schemas/AWSSQSConfig"
credentials:
$ref: "#/components/schemas/AWSSQSCredentials"
DestinationCreateRabbitMQ:
type: object
# Properties duplicated from DestinationCreateBase + specific required
required: [type, topics, config, credentials]
properties:
id:
Expand All @@ -559,17 +549,15 @@ components:
type:
type: string
description: Type of the destination. Must be 'rabbitmq'.
enum: [rabbitmq] # Specific type
enum: [rabbitmq]
topics:
$ref: "#/components/schemas/Topics"
# Type-specific properties
config:
$ref: "#/components/schemas/RabbitMQConfig"
credentials:
$ref: "#/components/schemas/RabbitMQCredentials"
DestinationCreateHookdeck:
type: object
# Properties duplicated from DestinationCreateBase + specific required
required: [type, topics, credentials] # No config
properties:
id:
Expand All @@ -579,16 +567,14 @@ components:
type:
type: string
description: Type of the destination. Must be 'hookdeck'.
enum: [hookdeck] # Specific type
enum: [hookdeck]
topics:
$ref: "#/components/schemas/Topics"
# Type-specific properties
config: {} # Empty config
config: {}
credentials:
$ref: "#/components/schemas/HookdeckCredentials"
DestinationCreateAWSKinesis:
type: object
# Properties duplicated from DestinationCreateBase + specific required
required: [type, topics, config, credentials]
properties:
id:
Expand All @@ -598,10 +584,9 @@ components:
type:
type: string
description: Type of the destination. Must be 'aws_kinesis'.
enum: [aws_kinesis] # Specific type
enum: [aws_kinesis]
topics:
$ref: "#/components/schemas/Topics"
# Type-specific properties
config:
$ref: "#/components/schemas/AWSKinesisConfig"
credentials:
Expand Down Expand Up @@ -647,7 +632,6 @@ components:
properties:
topics:
$ref: "#/components/schemas/Topics"
# Type-specific properties
config:
$ref: "#/components/schemas/WebhookConfig" # URL is required here, but PATCH means it's optional in the request
credentials:
Expand All @@ -658,7 +642,6 @@ components:
properties:
topics:
$ref: "#/components/schemas/Topics"
# Type-specific properties
config:
$ref: "#/components/schemas/AWSSQSConfig" # queue_url is required here, but PATCH means it's optional
credentials:
Expand All @@ -669,7 +652,6 @@ components:
properties:
topics:
$ref: "#/components/schemas/Topics"
# Type-specific properties
config:
$ref: "#/components/schemas/RabbitMQConfig" # server_url/exchange required here, but PATCH means optional
credentials:
Expand All @@ -680,7 +662,6 @@ components:
properties:
topics:
$ref: "#/components/schemas/Topics"
# Type-specific properties
config: {} # Empty config, cannot be updated
credentials:
$ref: "#/components/schemas/HookdeckCredentials" # token required here, but PATCH means optional
Expand All @@ -690,7 +671,6 @@ components:
properties:
topics:
$ref: "#/components/schemas/Topics"
# Type-specific properties
config:
$ref: "#/components/schemas/AWSKinesisConfig" # stream_name/region required here, but PATCH means optional
credentials:
Expand Down
5 changes: 4 additions & 1 deletion internal/services/api/destination_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,14 +313,17 @@ type CreateDestinationRequest struct {
ID string `json:"id" binding:"-"`
Type string `json:"type" binding:"required"`
Topics models.Topics `json:"topics" binding:"required"`
Config models.Config `json:"config" binding:"required"`
Config models.Config `json:"config" binding:"-"`
Credentials models.Credentials `json:"credentials" binding:"-"`
}

func (r *CreateDestinationRequest) ToDestination(tenantID string) models.Destination {
if r.ID == "" {
r.ID = uuid.New().String()
}
if r.Config == nil {
r.Config = make(map[string]string)
}
if r.Credentials == nil {
r.Credentials = make(map[string]string)
}
Expand Down