Skip to content

Commit

Permalink
fix remaining Nullable discrepencies
Browse files Browse the repository at this point in the history
  • Loading branch information
davidbloss committed Jan 3, 2025
1 parent d12cc57 commit 8f0631c
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 54 deletions.
2 changes: 1 addition & 1 deletion .changes/unreleased/Refactor-20241227-103359.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
kind: Refactor
body: 'BREAKING CHANGE: "Nullable" type now wraps optional "string", "ID", "bool", and timestamp struct fields of API input objects. This "Nullable" type enables fields to be set to the JSON "null" value.'
body: 'BREAKING CHANGE: "Nullable" type now wraps some optional struct fields of API input objects. This "Nullable" type enables fields to be set to the JSON "null" value.'
time: 2024-12-27T10:33:59.906375-06:00
37 changes: 20 additions & 17 deletions check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,16 +321,17 @@ func getCheckTestCases() map[string]TmpCheckTestCase {
"severity": []string{"sev1"},
}),
body: func(c *ol.Client) (*ol.Check, error) {
maxAllowed := 1
input := ol.NewCheckUpdateInputTypeOf[ol.CheckCodeIssueUpdateInput](checkUpdateInput)
input.Constraint = ol.CheckCodeIssueConstraintEnumAny
input.IssueName = nil // API NOTE - not allowed when constraint is "any"
input.IssueType = &[]string{"big-bug", "big-error"}
input.MaxAllowed = ol.RefOf(1)
input.IssueType = ol.RefOf([]string{"big-bug", "big-error"})
input.MaxAllowed = &maxAllowed
input.ResolutionTime = &ol.CodeIssueResolutionTimeInput{
Unit: ol.CodeIssueResolutionTimeUnitEnumWeek,
Value: 1,
}
input.Severity = &[]string{"sev1"}
input.Severity = ol.RefOf([]string{"sev1"})
return c.UpdateCheckCodeIssue(*input)
},
expectedCheck: CheckWithExtras(map[string]any{
Expand All @@ -346,31 +347,32 @@ func getCheckTestCases() map[string]TmpCheckTestCase {
fixture: BuildUpdateRequest("CodeIssue", map[string]any{
"constraint": ol.CheckCodeIssueConstraintEnumContains,
"issueName": "code-issue-updated",
"issueType": &[]string{}, // API NOTE - not allowed when constraint is "contains"
"issueType": nil, // API NOTE - not allowed when constraint is "contains"
"maxAllowed": 1,
"resolutionTime": map[string]any{"unit": "week", "value": 1},
"severity": &[]string{}, // API NOTE - not allowed when constraint is "contains"
"severity": nil, // API NOTE - not allowed when constraint is "contains"
}),
body: func(c *ol.Client) (*ol.Check, error) {
maxAllowed := 1
input := ol.NewCheckUpdateInputTypeOf[ol.CheckCodeIssueUpdateInput](checkUpdateInput)
input.Constraint = ol.CheckCodeIssueConstraintEnumContains
input.IssueName = ol.NewNullableFrom("code-issue-updated")
input.IssueType = &[]string{}
input.MaxAllowed = ol.NewNullableFrom(1)
input.IssueName = ol.RefOf("code-issue-updated")
input.IssueType = ol.RefOf(([]string)(nil))
input.MaxAllowed = &maxAllowed
input.ResolutionTime = &ol.CodeIssueResolutionTimeInput{
Unit: ol.CodeIssueResolutionTimeUnitEnumWeek,
Value: 1,
}
input.Severity = &[]string{}
input.Severity = ol.RefOf(([]string)(nil))
return c.UpdateCheckCodeIssue(*input)
},
expectedCheck: CheckWithExtras(map[string]any{
"constraint": ol.CheckCodeIssueConstraintEnumContains,
"issueName": "code-issue-updated",
"issueType": &[]string{},
"issueType": nil,
"maxAllowed": 1,
"resolutionTime": map[string]any{"unit": "week", "value": 1},
"severity": &[]string{},
"severity": nil,
}),
},

Expand Down Expand Up @@ -403,8 +405,9 @@ func getCheckTestCases() map[string]TmpCheckTestCase {
"UpdateHasRecentDeploy": {
fixture: BuildUpdateRequest("HasRecentDeploy", map[string]any{"days": 5}),
body: func(c *ol.Client) (*ol.Check, error) {
maxAllowed := 5
input := ol.NewCheckUpdateInputTypeOf[ol.CheckHasRecentDeployUpdateInput](checkUpdateInput)
input.Days = ol.RefOf(5)
input.Days = &maxAllowed
return c.UpdateCheckHasRecentDeploy(*input)
},
expectedCheck: CheckWithExtras(map[string]any{"days": 5}),
Expand Down Expand Up @@ -616,7 +619,7 @@ func getCheckTestCases() map[string]TmpCheckTestCase {
body: func(c *ol.Client) (*ol.Check, error) {
input := ol.NewCheckUpdateInputTypeOf[ol.CheckRepositoryFileUpdateInput](checkUpdateInput)
input.DirectorySearch = ol.RefOf(true)
input.FilePaths = &[]string{"/src", "/test", "/foo/bar"}
input.FilePaths = ol.RefOf([]string{"/src", "/test", "/foo/bar"})
input.FileContentsPredicate = predicateUpdateInput
input.UseAbsoluteRoot = ol.RefOf(false)
return c.UpdateCheckRepositoryFile(*input)
Expand Down Expand Up @@ -656,7 +659,7 @@ func getCheckTestCases() map[string]TmpCheckTestCase {
body: func(c *ol.Client) (*ol.Check, error) {
input := ol.NewCheckUpdateInputTypeOf[ol.CheckRepositoryGrepUpdateInput](checkUpdateInput)
input.DirectorySearch = ol.RefOf(true)
input.FilePaths = &[]string{"go.mod", "**/go.mod"}
input.FilePaths = ol.RefOf([]string{"go.mod", "**/go.mod"})
input.FileContentsPredicate = predicateUpdateInput
return c.UpdateCheckRepositoryGrep(*input)
},
Expand All @@ -675,7 +678,7 @@ func getCheckTestCases() map[string]TmpCheckTestCase {
body: func(c *ol.Client) (*ol.Check, error) {
input := ol.NewCheckUpdateInputTypeOf[ol.CheckRepositoryGrepUpdateInput](checkUpdateInput)
input.DirectorySearch = ol.RefOf(false)
input.FilePaths = &[]string{"**/go.mod"}
input.FilePaths = ol.RefOf([]string{"**/go.mod"})
input.FileContentsPredicate = predicateUpdateInput
return c.UpdateCheckRepositoryGrep(*input)
},
Expand Down Expand Up @@ -708,7 +711,7 @@ func getCheckTestCases() map[string]TmpCheckTestCase {
}),
body: func(c *ol.Client) (*ol.Check, error) {
input := ol.NewCheckCreateInputTypeOf[ol.CheckRepositorySearchCreateInput](checkCreateInput)
input.FileExtensions = &[]string{"sbt", "py"}
input.FileExtensions = ol.RefOf([]string{"sbt", "py"})
input.FileContentsPredicate = *predicateInput
return c.CreateCheckRepositorySearch(*input)
},
Expand All @@ -724,7 +727,7 @@ func getCheckTestCases() map[string]TmpCheckTestCase {
}),
body: func(c *ol.Client) (*ol.Check, error) {
input := ol.NewCheckUpdateInputTypeOf[ol.CheckRepositorySearchUpdateInput](checkUpdateInput)
input.FileExtensions = &[]string{"sbt", "py"}
input.FileExtensions = ol.RefOf([]string{"sbt", "py"})
input.FileContentsPredicate = predicateUpdateInput
return c.UpdateCheckRepositorySearch(*input)
},
Expand Down
16 changes: 16 additions & 0 deletions gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -1033,6 +1033,7 @@ func graphqlTypeToGolang(graphqlType string) string {
isRequired := strings.HasSuffix(graphqlType, "!")
convertedType := strings.TrimSuffix(graphqlType, "!")

// GraphQL type to Go type: [String] -> *[]string
isSlice := strings.HasPrefix(convertedType, "[") && strings.HasSuffix(convertedType, "]")
if isSlice {
convertedType = strings.TrimPrefix(convertedType, "[")
Expand All @@ -1047,10 +1048,25 @@ func graphqlTypeToGolang(graphqlType string) string {
convertedType = "float64"
case "Int":
convertedType = "int"
if isSlice {
convertedType = "[]" + convertedType
}
if !isRequired {
convertedType = "*" + convertedType
}
return convertedType
case "ISO8601DateTime":
convertedType = "iso8601.Time"
case "String":
convertedType = "string"
if isSlice {
convertedType = "[]" + convertedType
if isRequired {
return convertedType
} else {
return wrapWithNullable(convertedType)
}
}
case "ID":
convertedType = "ID"
default:
Expand Down
Loading

0 comments on commit 8f0631c

Please sign in to comment.