Skip to content

Commit a39fc89

Browse files
authored
Merge pull request #3 from incident-io/rob/fillout-rest-of-incidents-api
Add definitions and types for incidents, users
2 parents 413c5c4 + e6798be commit a39fc89

22 files changed

+784
-15
lines changed

model/actor_v2.go

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package model
2+
3+
import "github.com/incident-io/singer-tap/client"
4+
5+
type actorV2 struct{}
6+
7+
var ActorV2 actorV2
8+
9+
func (actorV2) Schema() Property {
10+
return Property{
11+
Types: []string{"object"},
12+
Properties: map[string]Property{
13+
"api_key": Optional(APIKey.Schema()),
14+
"user": Optional(UserV1.Schema()),
15+
},
16+
}
17+
}
18+
19+
func (actorV2) Serialize(input client.ActorV2) map[string]any {
20+
var user map[string]any
21+
if input.User != nil {
22+
user = UserV1.Serialize(*input.User)
23+
}
24+
25+
var apiKey map[string]any
26+
if input.ApiKey != nil {
27+
apiKey = APIKey.Serialize(*input.ApiKey)
28+
}
29+
30+
return map[string]any{
31+
"api_key": apiKey,
32+
"user": user,
33+
}
34+
}

model/api_key_v2.go

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package model
2+
3+
import "github.com/incident-io/singer-tap/client"
4+
5+
type apiKeyV2 struct{}
6+
7+
var APIKey apiKeyV2
8+
9+
func (apiKeyV2) Schema() Property {
10+
return Property{
11+
Types: []string{"object"},
12+
Properties: map[string]Property{
13+
"id": {
14+
Types: []string{"string"},
15+
},
16+
"name": {
17+
Types: []string{"string"},
18+
},
19+
},
20+
}
21+
}
22+
23+
func (apiKeyV2) Serialize(input client.APIKeyV2) map[string]any {
24+
return DumpToMap(input)
25+
}

model/base_types.go

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package model
2+
3+
type dateTime struct{}
4+
5+
var DateTime dateTime
6+
7+
func (dateTime) Schema() Property {
8+
return Property{
9+
Types: []string{"string"},
10+
CustomFormat: "date-time",
11+
}
12+
}
13+
14+
func (dateTime) Serialize(input string) any {
15+
return input
16+
}

model/custom_field_entry_v1.go

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package model
2+
3+
import (
4+
"github.com/incident-io/singer-tap/client"
5+
"github.com/samber/lo"
6+
)
7+
8+
type customFieldEntryV1 struct{}
9+
10+
var CustomFieldEntryV1 customFieldEntryV1
11+
12+
func (customFieldEntryV1) Schema() Property {
13+
return Property{
14+
Types: []string{"object"},
15+
Properties: map[string]Property{
16+
"custom_field": CustomFieldTypeInfoV1.Schema(),
17+
"values": ArrayOf(CustomFieldValueV1.Schema()),
18+
},
19+
}
20+
}
21+
22+
func (customFieldEntryV1) Serialize(input client.CustomFieldEntryV1) map[string]any {
23+
return map[string]any{
24+
"custom_field": CustomFieldTypeInfoV1.Serialize(input.CustomField),
25+
"values": lo.Map(input.Values, func(value client.CustomFieldValueV1, _ int) map[string]any {
26+
return CustomFieldValueV1.Serialize(value)
27+
}),
28+
}
29+
}

model/custom_field_option_v1.go

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package model
2+
3+
import "github.com/incident-io/singer-tap/client"
4+
5+
type customFieldOptionV1 struct{}
6+
7+
var CustomFieldOptionV1 customFieldOptionV1
8+
9+
func (customFieldOptionV1) Schema() Property {
10+
return Property{
11+
Types: []string{"object"},
12+
Properties: map[string]Property{
13+
"id": {
14+
Types: []string{"string"},
15+
},
16+
"custom_field_id": {
17+
Types: []string{"string"},
18+
},
19+
"sort_key": {
20+
Types: []string{"integer"},
21+
},
22+
"value": {
23+
Types: []string{"string"},
24+
},
25+
},
26+
}
27+
}
28+
29+
func (customFieldOptionV1) Serialize(input *client.CustomFieldOptionV1) map[string]any {
30+
if input == nil {
31+
return nil
32+
}
33+
34+
return DumpToMap(input)
35+
}

model/custom_field_type_info_v1.go

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package model
2+
3+
import (
4+
"github.com/incident-io/singer-tap/client"
5+
"github.com/samber/lo"
6+
)
7+
8+
type customFieldTypeInfoV1 struct{}
9+
10+
var CustomFieldTypeInfoV1 customFieldTypeInfoV1
11+
12+
func (customFieldTypeInfoV1) Schema() Property {
13+
return Property{
14+
Types: []string{"object"},
15+
Properties: map[string]Property{
16+
"id": {
17+
Types: []string{"string"},
18+
},
19+
"name": {
20+
Types: []string{"string"},
21+
},
22+
"description": {
23+
Types: []string{"string"},
24+
},
25+
"field_type": {
26+
Types: []string{"string"},
27+
},
28+
"options": ArrayOf(CustomFieldOptionV1.Schema()),
29+
},
30+
}
31+
}
32+
33+
func (customFieldTypeInfoV1) Serialize(input client.CustomFieldTypeInfoV1) map[string]any {
34+
return map[string]any{
35+
"id": input.Id,
36+
"name": input.Name,
37+
"description": input.Description,
38+
"field_type": input.FieldType,
39+
"options": lo.Map(input.Options, func(option client.CustomFieldOptionV1, _ int) map[string]any {
40+
return CustomFieldOptionV1.Serialize(&option)
41+
}),
42+
}
43+
}

model/custom_field_value_v1.go

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package model
2+
3+
import "github.com/incident-io/singer-tap/client"
4+
5+
type customFieldValueV1 struct{}
6+
7+
var CustomFieldValueV1 customFieldValueV1
8+
9+
func (customFieldValueV1) Schema() Property {
10+
return Property{
11+
Types: []string{"object"},
12+
Properties: map[string]Property{
13+
"value_link": {
14+
Types: []string{"null", "string"},
15+
},
16+
"value_numeric": {
17+
Types: []string{"null", "number"},
18+
},
19+
"value_text": {
20+
Types: []string{"null", "string"},
21+
},
22+
"value_catalog_entry": Optional(EmbeddedCatalogEntryV1.Schema()),
23+
"value_option": Optional(CustomFieldOptionV1.Schema()),
24+
},
25+
}
26+
}
27+
28+
func (customFieldValueV1) Serialize(input client.CustomFieldValueV1) map[string]any {
29+
return map[string]any{
30+
"value_link": input.ValueLink,
31+
"value_numeric": input.ValueNumeric,
32+
"value_text": input.ValueText,
33+
"value_catalog_entry": EmbeddedCatalogEntryV1.Serialize(input.ValueCatalogEntry),
34+
"value_option": CustomFieldOptionV1.Serialize(input.ValueOption),
35+
}
36+
}

model/embedded_catalog_entry_v1.go

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package model
2+
3+
import (
4+
"github.com/incident-io/singer-tap/client"
5+
)
6+
7+
type embeddedCatalogEntryV1 struct{}
8+
9+
var EmbeddedCatalogEntryV1 embeddedCatalogEntryV1
10+
11+
func (embeddedCatalogEntryV1) Schema() Property {
12+
return Property{
13+
Types: []string{"object"},
14+
Properties: map[string]Property{
15+
"id": {
16+
Types: []string{"string"},
17+
},
18+
"name": {
19+
Types: []string{"string"},
20+
},
21+
"aliases": {
22+
Types: []string{"array", "null"},
23+
Items: &ArrayItem{
24+
Type: "string",
25+
},
26+
},
27+
"external_id": {
28+
Types: []string{"string", "null"},
29+
},
30+
},
31+
}
32+
}
33+
34+
func (embeddedCatalogEntryV1) Serialize(input *client.EmbeddedCatalogEntryV1) map[string]any {
35+
if input == nil {
36+
return nil
37+
}
38+
39+
return map[string]any{
40+
"id": input.Id,
41+
"name": input.Name,
42+
"aliases": input.Aliases,
43+
"external_id": input.ExternalId,
44+
}
45+
}

model/external_issue_reference_v2.go

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package model
2+
3+
import "github.com/incident-io/singer-tap/client"
4+
5+
type externalIssueReferenceV2 struct{}
6+
7+
var ExternalIssueReferenceV2 externalIssueReferenceV2
8+
9+
func (externalIssueReferenceV2) Schema() Property {
10+
return Property{
11+
Types: []string{"object", "null"},
12+
Properties: map[string]Property{
13+
"issue_name": {
14+
Types: []string{"string"},
15+
},
16+
"issue_permalink": {
17+
Types: []string{"string"},
18+
},
19+
"provider": {
20+
Types: []string{"string"},
21+
},
22+
},
23+
}
24+
}
25+
26+
func (externalIssueReferenceV2) Serialize(input *client.ExternalIssueReferenceV2) map[string]any {
27+
if input == nil {
28+
return nil
29+
}
30+
31+
return map[string]any{
32+
"issue_name": input.IssueName,
33+
"issue_permalink": input.IssuePermalink,
34+
"provider": input.Provider,
35+
}
36+
}

model/incident_role_assignment_v1.go

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package model
2+
3+
import "github.com/incident-io/singer-tap/client"
4+
5+
type incidentRoleAssignmentV1 struct{}
6+
7+
var IncidentRoleAssignmentV1 incidentRoleAssignmentV1
8+
9+
func (incidentRoleAssignmentV1) Schema() Property {
10+
return Property{
11+
Types: []string{"object"},
12+
Properties: map[string]Property{
13+
"assignee": Optional(UserV1.Schema()),
14+
"role": IncidentRoleV1.Schema(),
15+
},
16+
}
17+
}
18+
19+
func (incidentRoleAssignmentV1) Serialize(input client.IncidentRoleAssignmentV1) map[string]any {
20+
var assignee map[string]any
21+
if input.Assignee != nil {
22+
assignee = UserV1.Serialize(*input.Assignee)
23+
}
24+
25+
return map[string]any{
26+
"assignee": assignee,
27+
"role": IncidentRoleV1.Serialize(input.Role),
28+
}
29+
}

model/incident_role_v1.go

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package model
2+
3+
import "github.com/incident-io/singer-tap/client"
4+
5+
type incidentRoleV1 struct{}
6+
7+
var IncidentRoleV1 incidentRoleV1
8+
9+
func (incidentRoleV1) Schema() Property {
10+
return Property{
11+
Types: []string{"object"},
12+
Properties: map[string]Property{
13+
"id": {
14+
Types: []string{"string"},
15+
},
16+
"name": {
17+
Types: []string{"string"},
18+
},
19+
"description": {
20+
Types: []string{"string"},
21+
},
22+
"instructions": {
23+
Types: []string{"string"},
24+
},
25+
"required": {
26+
Types: []string{"boolean"},
27+
},
28+
"role_type": {
29+
Types: []string{"string"},
30+
},
31+
"short_form": {
32+
Types: []string{"string"},
33+
},
34+
"created_at": DateTime.Schema(),
35+
"updated_at": DateTime.Schema(),
36+
},
37+
}
38+
}
39+
40+
func (incidentRoleV1) Serialize(input client.IncidentRoleV1) map[string]any {
41+
// Just flat convert everything into a map[string]any
42+
return DumpToMap(input)
43+
}

0 commit comments

Comments
 (0)