Skip to content

Commit

Permalink
fix: handling of windows file paths for gen.yaml search
Browse files Browse the repository at this point in the history
  • Loading branch information
TristanSpeakEasy committed Dec 19, 2023
1 parent bc2fdad commit 8aa6f8b
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
13 changes: 11 additions & 2 deletions io.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,14 +212,23 @@ func Save(dir string, cfg *Config, opts ...Option) error {
}

func findConfigFile(dir string, o *options) ([]byte, string, error) {
path := filepath.Join(dir, "gen.yaml")
absPath, err := filepath.Abs(dir)
if err != nil {
return nil, "", fmt.Errorf("failed to get absolute path: %w", err)
}

path := filepath.Join(absPath, "gen.yaml")

for {
data, err := o.readFileFunc(path)
if err != nil {
if errors.Is(err, fs.ErrNotExist) {
currentDir := filepath.Dir(path)
if currentDir == "." || currentDir == "/" {
// Check for the root of the filesystem or path
// ie `.` for `./something`
// or `/` for `/some/absolute/path` in linux
// or `:\\` for `C:\\` in windows
if currentDir == "." || currentDir == "/" || currentDir[1:] == ":\\" {
return nil, "", ErrNotFound
}

Expand Down
31 changes: 31 additions & 0 deletions io_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ func TestLoad_Success(t *testing.T) {
SDKClassName: "SDK",
SingleTagPerOp: false,
MaintainOpenAPIOrder: true,
UsageSnippets: &UsageSnippets{
OptionalPropertyRendering: "withExample",
},
Fixes: &Fixes{
NameResolutionDec2023: true,
},
UseClassNamesForArrayFields: true,
},
New: map[string]bool{
"go": true,
Expand Down Expand Up @@ -81,6 +88,12 @@ func TestLoad_Success(t *testing.T) {
OmitDescriptionIfSummaryPresent: true,
DisableComments: false,
},
UsageSnippets: &UsageSnippets{
OptionalPropertyRendering: "withExample",
},
Fixes: &Fixes{
NameResolutionDec2023: false,
},
},
Features: map[string]map[string]string{},
New: map[string]bool{},
Expand Down Expand Up @@ -117,6 +130,12 @@ func TestLoad_Success(t *testing.T) {
DisableComments: false,
OmitDescriptionIfSummaryPresent: true,
},
UsageSnippets: &UsageSnippets{
OptionalPropertyRendering: "withExample",
},
Fixes: &Fixes{
NameResolutionDec2023: false,
},
},
Features: map[string]map[string]string{
"go": {
Expand Down Expand Up @@ -157,6 +176,12 @@ func TestLoad_Success(t *testing.T) {
DisableComments: false,
OmitDescriptionIfSummaryPresent: true,
},
UsageSnippets: &UsageSnippets{
OptionalPropertyRendering: "withExample",
},
Fixes: &Fixes{
NameResolutionDec2023: false,
},
},
Features: map[string]map[string]string{
"go": {
Expand Down Expand Up @@ -200,6 +225,12 @@ func TestLoad_Success(t *testing.T) {
DisableComments: false,
OmitDescriptionIfSummaryPresent: true,
},
UsageSnippets: &UsageSnippets{
OptionalPropertyRendering: "withExample",
},
Fixes: &Fixes{
NameResolutionDec2023: false,
},
},
Features: map[string]map[string]string{
"go": {
Expand Down

0 comments on commit 8aa6f8b

Please sign in to comment.