Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
  • Loading branch information
eddycharly committed Apr 18, 2024
1 parent 9fa5b31 commit 9a44bb1
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 31 deletions.
45 changes: 20 additions & 25 deletions pkg/openapiclient/local_schemas.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package openapiclient

import (
"errors"
"fmt"
"io/fs"
"path"
Expand Down Expand Up @@ -31,36 +30,32 @@ func (k *localSchemasClient) Paths() (map[string]openapi.GroupVersion, error) {
return nil, nil
}
res := map[string]openapi.GroupVersion{}
apiGroups, err := fs.ReadDir(k.fs, "apis")
if err != nil && !errors.Is(err, fs.ErrNotExist) {
return nil, fmt.Errorf("failed reading local files dir %s: %w", "apis", err)
}
for _, f := range apiGroups {
groupPath := path.Join("apis", f.Name())
versions, err := fs.ReadDir(k.fs, groupPath)
if err != nil {
return nil, fmt.Errorf("failed reading local files dir %s: %w", groupPath, err)
if apiGroups, err := fs.ReadDir(k.fs, "apis"); err == nil {
for _, f := range apiGroups {
groupPath := path.Join("apis", f.Name())
versions, err := fs.ReadDir(k.fs, groupPath)
if err != nil {
return nil, fmt.Errorf("failed reading local files dir %s: %w", groupPath, err)
}
for _, v := range versions {
if !utils.IsJson(v.Name()) {
continue
}
name := strings.TrimSuffix(v.Name(), path.Ext(v.Name()))
apisPath := path.Join("apis", f.Name(), name)
res[apisPath] = groupversion.NewForFile(k.fs, path.Join(groupPath, v.Name()))
}
}
for _, v := range versions {
}
if coregroup, err := fs.ReadDir(k.fs, "api"); err == nil {
for _, v := range coregroup {
if !utils.IsJson(v.Name()) {
continue
}
name := strings.TrimSuffix(v.Name(), path.Ext(v.Name()))
apisPath := path.Join("apis", f.Name(), name)
res[apisPath] = groupversion.NewForFile(k.fs, path.Join(groupPath, v.Name()))
}
}
coregroup, err := fs.ReadDir(k.fs, "api")
if err != nil && !errors.Is(err, fs.ErrNotExist) {
return nil, fmt.Errorf("failed reading local files dir %s: %w", "api", err)
}
for _, v := range coregroup {
if !utils.IsJson(v.Name()) {
continue
apiPath := path.Join("api", name)
res[apiPath] = groupversion.NewForFile(k.fs, path.Join("api", v.Name()))
}
name := strings.TrimSuffix(v.Name(), path.Ext(v.Name()))
apiPath := path.Join("api", name)
res[apiPath] = groupversion.NewForFile(k.fs, path.Join("api", v.Name()))
}
return res, nil
}
11 changes: 5 additions & 6 deletions pkg/openapiclient/local_schemas_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,8 @@ func TestNewLocalSchemaFiles(t *testing.T) {

func Test_localSchemasClient_Paths(t *testing.T) {
tests := []struct {
name string
fs fs.FS
// dir string
name string
fs fs.FS
want sets.Set[string]
wantErr bool
}{{
Expand Down Expand Up @@ -95,9 +94,9 @@ func Test_localSchemasClient_Paths(t *testing.T) {
fs: os.DirFS("../../invalid"),
want: sets.New[string](),
}, {
name: "not a dir",
fs: os.DirFS("../../testcases/schemas/error_not_a_dir"),
wantErr: true,
name: "not a dir",
fs: os.DirFS("../../testcases/schemas/error_not_a_dir"),
want: sets.New[string](),
}}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down

0 comments on commit 9a44bb1

Please sign in to comment.