Skip to content

Commit

Permalink
chore(oas2kong): cleanup unnecessary pointers to slices
Browse files Browse the repository at this point in the history
  • Loading branch information
Tieske committed Jul 6, 2023
1 parent a7b666b commit 2ff4529
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
6 changes: 3 additions & 3 deletions cmd/openapi2kong.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ func executeOpenapi2Kong(cmd *cobra.Command, _ []string) error {
return fmt.Errorf("failed getting cli argument 'uuid-base'; %w", err)
}

var entityTags *[]string
var entityTags []string
{
tags, err := cmd.Flags().GetStringSlice("select-tag")
if err != nil {
return fmt.Errorf("failed getting cli argument 'select-tag'; %w", err)
}
entityTags = &tags
if len(*entityTags) == 0 {
entityTags = tags
if len(entityTags) == 0 {
entityTags = nil
}
}
Expand Down
6 changes: 3 additions & 3 deletions openapi2kong/openapi2kong.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const (

// O2KOptions defines the options for an O2K conversion operation
type O2kOptions struct {
Tags *[]string // Array of tags to mark all generated entities with, taken from 'x-kong-tags' if omitted.
Tags []string // Array of tags to mark all generated entities with, taken from 'x-kong-tags' if omitted.
DocName string // Base document name, will be taken from x-kong-name, or info.title (for UUID generation!)
UUIDNamespace uuid.UUID // Namespace for UUID generation, defaults to DNS namespace for UUID v5
}
Expand Down Expand Up @@ -60,10 +60,10 @@ func sanitizeRegexCapture(varName string) string {
// getKongTags returns the provided tags or if nil, then the `x-kong-tags` property,
// validated to be a string array. If there is no error, then there will always be
// an array returned for safe access later in the process.
func getKongTags(doc *openapi3.T, tagsProvided *[]string) ([]string, error) {
func getKongTags(doc *openapi3.T, tagsProvided []string) ([]string, error) {
if tagsProvided != nil {
// the provided tags take precedence, return them
return *tagsProvided, nil
return tagsProvided, nil
}

if doc.ExtensionProps.Extensions == nil || doc.ExtensionProps.Extensions["x-kong-tags"] == nil {
Expand Down
2 changes: 1 addition & 1 deletion openapi2kong/openapi2kong_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func Test_Openapi2kong(t *testing.T) {
fileNameOut := strings.TrimSuffix(fileNameIn, ".yaml") + ".generated.json"
dataIn, _ := os.ReadFile(fixturePath + fileNameIn)
dataOut, err := Convert(dataIn, O2kOptions{
Tags: &[]string{"OAS3_import", "OAS3file_" + fileNameIn},
Tags: []string{"OAS3_import", "OAS3file_" + fileNameIn},
})
if err != nil {
t.Error(fmt.Sprintf("'%s' didn't expect error: %%w", fixturePath+fileNameIn), err)
Expand Down
8 changes: 4 additions & 4 deletions openapi2kong/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func getDefaultParamStyle(givenStyle string, paramType string) string {
// generateParameterSchema returns the given schema if there is one, a generated
// schema if it was specified, or nil if there is none.
// Parameters include path, query, and headers
func generateParameterSchema(operation *openapi3.Operation) *[]map[string]interface{} {
func generateParameterSchema(operation *openapi3.Operation) []map[string]interface{} {
parameters := operation.Parameters
if parameters == nil {
return nil
Expand Down Expand Up @@ -76,7 +76,7 @@ func generateParameterSchema(operation *openapi3.Operation) *[]map[string]interf
}
}

return &result
return result
}

// generateBodySchema returns the given schema if there is one, a generated
Expand Down Expand Up @@ -108,7 +108,7 @@ func generateBodySchema(operation *openapi3.Operation) string {

// generateContentTypes returns an array of allowed content types. nil if none.
// Returned array will be sorted by name for deterministic comparisons.
func generateContentTypes(operation *openapi3.Operation) *[]string {
func generateContentTypes(operation *openapi3.Operation) []string {
requestBody := operation.RequestBody
if requestBody == nil {
return nil
Expand Down Expand Up @@ -136,7 +136,7 @@ func generateContentTypes(operation *openapi3.Operation) *[]string {
}
sort.Strings(list)

return &list
return list
}

// generateValidatorPlugin generates the validator plugin configuration, based
Expand Down

0 comments on commit 2ff4529

Please sign in to comment.