Skip to content

Commit fd69ba2

Browse files
authored
Merge pull request #348 from hookdeck/destination-validation
chore: Make destination config optional
2 parents 5efd2a3 + 4923d34 commit fd69ba2

File tree

3 files changed

+16
-34
lines changed

3 files changed

+16
-34
lines changed

cmd/e2e/api_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,6 @@ func (suite *basicSuite) TestDestinationsAPI() {
344344
Body: map[string]interface{}{
345345
"message": "validation error",
346346
"data": map[string]interface{}{
347-
"config": "required",
348347
"topics": "required",
349348
"type": "required",
350349
},

docs/apis/openapi.yaml

Lines changed: 12 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ components:
223223
type:
224224
type: string
225225
description: Type of the destination.
226-
enum: [webhook] # Specific type
226+
enum: [webhook]
227227
example: "webhook"
228228
topics:
229229
$ref: "#/components/schemas/Topics"
@@ -238,7 +238,6 @@ components:
238238
format: date-time
239239
description: ISO Date when the destination was created.
240240
example: "2024-01-01T00:00:00Z"
241-
# Type-specific properties
242241
config:
243242
$ref: "#/components/schemas/WebhookConfig"
244243
credentials:
@@ -279,7 +278,7 @@ components:
279278
type:
280279
type: string
281280
description: Type of the destination.
282-
enum: [aws_sqs] # Specific type
281+
enum: [aws_sqs]
283282
example: "aws_sqs"
284283
topics:
285284
$ref: "#/components/schemas/Topics"
@@ -294,7 +293,6 @@ components:
294293
format: date-time
295294
description: ISO Date when the destination was created.
296295
example: "2024-01-01T00:00:00Z"
297-
# Type-specific properties
298296
config:
299297
$ref: "#/components/schemas/AWSSQSConfig"
300298
credentials:
@@ -335,7 +333,7 @@ components:
335333
type:
336334
type: string
337335
description: Type of the destination.
338-
enum: [rabbitmq] # Specific type
336+
enum: [rabbitmq]
339337
example: "rabbitmq"
340338
topics:
341339
$ref: "#/components/schemas/Topics"
@@ -350,7 +348,6 @@ components:
350348
format: date-time
351349
description: ISO Date when the destination was created.
352350
example: "2024-01-01T00:00:00Z"
353-
# Type-specific properties
354351
config:
355352
$ref: "#/components/schemas/RabbitMQConfig"
356353
credentials:
@@ -392,7 +389,7 @@ components:
392389
type:
393390
type: string
394391
description: Type of the destination.
395-
enum: [hookdeck] # Specific type
392+
enum: [hookdeck]
396393
example: "hookdeck"
397394
topics:
398395
$ref: "#/components/schemas/Topics"
@@ -407,7 +404,6 @@ components:
407404
format: date-time
408405
description: ISO Date when the destination was created.
409406
example: "2024-01-01T00:00:00Z"
410-
# Type-specific properties
411407
config: {} # Empty config
412408
credentials:
413409
$ref: "#/components/schemas/HookdeckCredentials"
@@ -444,7 +440,7 @@ components:
444440
type:
445441
type: string
446442
description: Type of the destination.
447-
enum: [aws_kinesis] # Specific type
443+
enum: [aws_kinesis]
448444
example: "aws_kinesis"
449445
topics:
450446
$ref: "#/components/schemas/Topics"
@@ -459,7 +455,6 @@ components:
459455
format: date-time
460456
description: ISO Date when the destination was created.
461457
example: "2024-01-01T00:00:00Z"
462-
# Type-specific properties
463458
config:
464459
$ref: "#/components/schemas/AWSKinesisConfig"
465460
credentials:
@@ -508,8 +503,7 @@ components:
508503

509504
DestinationCreateWebhook:
510505
type: object
511-
# Properties duplicated from DestinationCreateBase
512-
required: [type, topics, config] # Credentials not required for webhook create base
506+
required: [type, topics, config]
513507
properties:
514508
id:
515509
type: string
@@ -518,18 +512,16 @@ components:
518512
type:
519513
type: string
520514
description: Type of the destination. Must be 'webhook'.
521-
enum: [webhook] # Specific type
515+
enum: [webhook]
522516
topics:
523517
$ref: "#/components/schemas/Topics"
524-
# Type-specific properties
525518
config:
526519
$ref: "#/components/schemas/WebhookConfig"
527520
credentials:
528521
# Secret is optional on create for admin, forbidden for tenant
529522
$ref: "#/components/schemas/WebhookCredentials"
530523
DestinationCreateAWSSQS:
531524
type: object
532-
# Properties duplicated from DestinationCreateBase + specific required
533525
required: [type, topics, config, credentials]
534526
properties:
535527
id:
@@ -539,17 +531,15 @@ components:
539531
type:
540532
type: string
541533
description: Type of the destination. Must be 'aws_sqs'.
542-
enum: [aws_sqs] # Specific type
534+
enum: [aws_sqs]
543535
topics:
544536
$ref: "#/components/schemas/Topics"
545-
# Type-specific properties
546537
config:
547538
$ref: "#/components/schemas/AWSSQSConfig"
548539
credentials:
549540
$ref: "#/components/schemas/AWSSQSCredentials"
550541
DestinationCreateRabbitMQ:
551542
type: object
552-
# Properties duplicated from DestinationCreateBase + specific required
553543
required: [type, topics, config, credentials]
554544
properties:
555545
id:
@@ -559,17 +549,15 @@ components:
559549
type:
560550
type: string
561551
description: Type of the destination. Must be 'rabbitmq'.
562-
enum: [rabbitmq] # Specific type
552+
enum: [rabbitmq]
563553
topics:
564554
$ref: "#/components/schemas/Topics"
565-
# Type-specific properties
566555
config:
567556
$ref: "#/components/schemas/RabbitMQConfig"
568557
credentials:
569558
$ref: "#/components/schemas/RabbitMQCredentials"
570559
DestinationCreateHookdeck:
571560
type: object
572-
# Properties duplicated from DestinationCreateBase + specific required
573561
required: [type, topics, credentials] # No config
574562
properties:
575563
id:
@@ -579,16 +567,14 @@ components:
579567
type:
580568
type: string
581569
description: Type of the destination. Must be 'hookdeck'.
582-
enum: [hookdeck] # Specific type
570+
enum: [hookdeck]
583571
topics:
584572
$ref: "#/components/schemas/Topics"
585-
# Type-specific properties
586-
config: {} # Empty config
573+
config: {}
587574
credentials:
588575
$ref: "#/components/schemas/HookdeckCredentials"
589576
DestinationCreateAWSKinesis:
590577
type: object
591-
# Properties duplicated from DestinationCreateBase + specific required
592578
required: [type, topics, config, credentials]
593579
properties:
594580
id:
@@ -598,10 +584,9 @@ components:
598584
type:
599585
type: string
600586
description: Type of the destination. Must be 'aws_kinesis'.
601-
enum: [aws_kinesis] # Specific type
587+
enum: [aws_kinesis]
602588
topics:
603589
$ref: "#/components/schemas/Topics"
604-
# Type-specific properties
605590
config:
606591
$ref: "#/components/schemas/AWSKinesisConfig"
607592
credentials:
@@ -647,7 +632,6 @@ components:
647632
properties:
648633
topics:
649634
$ref: "#/components/schemas/Topics"
650-
# Type-specific properties
651635
config:
652636
$ref: "#/components/schemas/WebhookConfig" # URL is required here, but PATCH means it's optional in the request
653637
credentials:
@@ -658,7 +642,6 @@ components:
658642
properties:
659643
topics:
660644
$ref: "#/components/schemas/Topics"
661-
# Type-specific properties
662645
config:
663646
$ref: "#/components/schemas/AWSSQSConfig" # queue_url is required here, but PATCH means it's optional
664647
credentials:
@@ -669,7 +652,6 @@ components:
669652
properties:
670653
topics:
671654
$ref: "#/components/schemas/Topics"
672-
# Type-specific properties
673655
config:
674656
$ref: "#/components/schemas/RabbitMQConfig" # server_url/exchange required here, but PATCH means optional
675657
credentials:
@@ -680,7 +662,6 @@ components:
680662
properties:
681663
topics:
682664
$ref: "#/components/schemas/Topics"
683-
# Type-specific properties
684665
config: {} # Empty config, cannot be updated
685666
credentials:
686667
$ref: "#/components/schemas/HookdeckCredentials" # token required here, but PATCH means optional
@@ -690,7 +671,6 @@ components:
690671
properties:
691672
topics:
692673
$ref: "#/components/schemas/Topics"
693-
# Type-specific properties
694674
config:
695675
$ref: "#/components/schemas/AWSKinesisConfig" # stream_name/region required here, but PATCH means optional
696676
credentials:

internal/services/api/destination_handlers.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,14 +313,17 @@ type CreateDestinationRequest struct {
313313
ID string `json:"id" binding:"-"`
314314
Type string `json:"type" binding:"required"`
315315
Topics models.Topics `json:"topics" binding:"required"`
316-
Config models.Config `json:"config" binding:"required"`
316+
Config models.Config `json:"config" binding:"-"`
317317
Credentials models.Credentials `json:"credentials" binding:"-"`
318318
}
319319

320320
func (r *CreateDestinationRequest) ToDestination(tenantID string) models.Destination {
321321
if r.ID == "" {
322322
r.ID = uuid.New().String()
323323
}
324+
if r.Config == nil {
325+
r.Config = make(map[string]string)
326+
}
324327
if r.Credentials == nil {
325328
r.Credentials = make(map[string]string)
326329
}

0 commit comments

Comments
 (0)