Skip to content

Commit

Permalink
feat: add config for maintaining openapi order and fix bug with comme…
Browse files Browse the repository at this point in the history
…nts defaults
  • Loading branch information
TristanSpeakEasy committed Nov 4, 2023
1 parent 8694c27 commit 1a26252
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 5 deletions.
33 changes: 30 additions & 3 deletions config.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package config

import (
"strings"

"github.com/AlekSi/pointer"
"github.com/mitchellh/mapstructure"
)
Expand Down Expand Up @@ -40,6 +42,7 @@ type Generation struct {
SingleTagPerOp bool `yaml:"singleTagPerOp,omitempty"`
TagNamespacingDisabled bool `yaml:"tagNamespacingDisabled,omitempty"`
RepoURL string `yaml:"repoURL,omitempty"`
MaintainOpenAPIOrder bool `yaml:"maintainOpenAPIOrder,omitempty"`
}

type DevContainers struct {
Expand Down Expand Up @@ -149,7 +152,25 @@ func GetDefaultConfig(newSDK bool, getLangDefaultFunc GetLanguageDefaultFunc, la
fields := map[string]any{}
for _, field := range defaults {
if field.DefaultValue != nil {
fields[field.Name] = *field.DefaultValue
if strings.Contains(field.Name, ".") {
parts := strings.Split(field.Name, ".")

currMap := fields

for i, part := range parts {
if i == len(parts)-1 {
currMap[part] = *field.DefaultValue
} else {
if _, ok := currMap[part]; !ok {
currMap[part] = map[string]any{}
}

currMap = currMap[part].(map[string]any)
}
}
} else {
fields[field.Name] = *field.DefaultValue
}
}
}

Expand Down Expand Up @@ -225,17 +246,23 @@ func GetGenerationDefaults(newSDK bool) []SDKGenConfigField {
Description: pointer.To("Operations with multiple tags will only generate methods namespaced by the first tag"),
},
{
Name: "disableComments",
Name: "comments.disableComments",
Required: false,
DefaultValue: ptr(false),
Description: pointer.To("Disable generating comments from spec on the SDK"),
},
{
Name: "omitDescriptionIfSummaryPresent",
Name: "comments.omitDescriptionIfSummaryPresent",
Required: false,
DefaultValue: ptr(false),
Description: pointer.To("Omit generating comment descriptions if spec provides a summary"),
},
{
Name: "maintainOpenAPIOrder",
Required: false,
DefaultValue: ptr(newSDK),
Description: pointer.To("Maintains the order of things like parameters and fields when generating the SDK"),
},
}
}

Expand Down
9 changes: 7 additions & 2 deletions io_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,13 @@ func TestLoad_Success(t *testing.T) {
},
},
Generation: Generation{
SDKClassName: "SDK",
SingleTagPerOp: false,
Comments: &Comments{
DisableComments: false,
OmitDescriptionIfSummaryPresent: false,
},
SDKClassName: "SDK",
SingleTagPerOp: false,
MaintainOpenAPIOrder: true,
},
New: map[string]bool{
"go": true,
Expand Down

0 comments on commit 1a26252

Please sign in to comment.