Skip to content

Commit

Permalink
still trying to reproduce
Browse files Browse the repository at this point in the history
Signed-off-by: Frederic BIDON <[email protected]>
  • Loading branch information
fredbi committed Dec 1, 2023
1 parent ce7ad70 commit 8f9f2ea
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 23 deletions.
6 changes: 2 additions & 4 deletions .github/workflows/go-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,11 @@ jobs:
go-version: '${{ matrix.go_version }}'
check-latest: true
cache: true

- uses: actions/checkout@v3

- run: go test -v -race -coverprofile="coverage-${{ matrix.os }}.${{ matrix.go_version }}.out" -covermode=atomic ./...

- run: go test -v -run 145
name: repro test
- name: repro test
run: go test -v -run '(145)|(NormalizeURI)|(NormalizeBase)'
env:
SWAGGER_DEBUG: '1'

Expand Down
17 changes: 17 additions & 0 deletions fixtures/bugs/145/Program Files (x86)/AppName/ref.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"definitions": {
"todo-partial": {
"title": "Todo Partial",
"type": "object",
"properties": {
"name": {
"type": "string"
},
"completed": {
"type": ["boolean", "null"]
}
},
"required": ["name", "completed"]
}
}
}
12 changes: 1 addition & 11 deletions fixtures/bugs/145/Program Files (x86)/AppName/todos.json
Original file line number Diff line number Diff line change
Expand Up @@ -294,17 +294,7 @@
},
"definitions": {
"todo-partial": {
"title": "Todo Partial",
"type": "object",
"properties": {
"name": {
"type": "string"
},
"completed": {
"type": ["boolean", "null"]
}
},
"required": ["name", "completed"]
"$ref": "ref.json#/definitions/todo-partial"
},
"todo-full": {
"title": "Todo Full",
Expand Down
6 changes: 4 additions & 2 deletions normalizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ func normalizeURI(refPath, base string) string {
}

fixWindowsURI(refURL, refPath) // noop on non-windows OS
debugLog("normalizeURI called:\noriginal: refPath=%q, base=%q\nafter fix windows: %q", refPath, base, refURL.String())

refURL.Path = path.Clean(refURL.Path)
if refURL.Path == "." {
Expand All @@ -67,6 +68,7 @@ func normalizeURI(refPath, base string) string {
// copying fragment from ref to base
baseURL.Fragment = refURL.Fragment

debugLog("normalizeURI called:\noriginal: refPath=%q, base=%q\nresult: %q", refPath, base, baseURL.String())
return baseURL.String()
}

Expand Down Expand Up @@ -176,7 +178,7 @@ func normalizeBase(in string) string {
u.Fragment = "" // any fragment in the base is irrelevant

fixWindowsURI(u, in) // noop on non-windows OS
debugLog("normalizBase called:\noriginal: %s\nafter fix windows: %s", in, u.String())
debugLog("normalizeBase called:\noriginal: %q\nafter fix windows: %q", in, u.String())

u.Path = path.Clean(u.Path)
if u.Path == "." { // empty after Clean()
Expand All @@ -199,6 +201,6 @@ func normalizeBase(in string) string {
u.Scheme = fileScheme
u.Path = absPath(u.Path) // platform-dependent
u.RawQuery = "" // any query component is irrelevant for a base
debugLog("normalizBase called:\noriginal: %s\nafter normalizeBase: %s", in, u.String())
debugLog("normalizeBase called:\noriginal: %q\nafter normalizeBase: %q", in, u.String())
return u.String()
}
5 changes: 5 additions & 0 deletions normalizer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,11 @@ func TestNormalizer_NormalizeBase(t *testing.T) {
Expected: "file:///e:/base/sub/file.json",
Windows: true,
},
{
// escaped characters in base (1)
Base: `file:///C:/base (x86)/Spec.json`,
Expected: `file:///C:/base%20%28x86%29/Spec.json`,
},
} {
testCase := toPin
if testCase.Windows && runtime.GOOS != windowsOS {
Expand Down
25 changes: 19 additions & 6 deletions schema_loader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,25 @@ import (
)

func TestLoader_Issue145(t *testing.T) {
basePath := filepath.Join("fixtures", "bugs", "145", "Program Files (x86)", "AppName", "todos.json")
todosDoc, err := jsonDoc(basePath)
require.NoError(t, err)
t.Run("with ExpandSpec", func(t *testing.T) {
basePath := filepath.Join("fixtures", "bugs", "145", "Program Files (x86)", "AppName", "todos.json")
todosDoc, err := jsonDoc(basePath)
require.NoError(t, err)

spec := new(Swagger)
require.NoError(t, json.Unmarshal(todosDoc, spec))
spec := new(Swagger)
require.NoError(t, json.Unmarshal(todosDoc, spec))

require.NoError(t, ExpandSpec(spec, &ExpandOptions{RelativeBase: basePath}))
require.NoError(t, ExpandSpec(spec, &ExpandOptions{RelativeBase: basePath}))
})

t.Run("with ExpandSchema", func(t *testing.T) {
basePath := filepath.Join("fixtures", "bugs", "145", "Program Files (x86)", "AppName", "ref.json")
schemaDoc, err := jsonDoc(basePath)
require.NoError(t, err)

sch := new(Schema)
require.NoError(t, json.Unmarshal(schemaDoc, sch))

require.NoError(t, ExpandSchema(sch, nil, nil))
})
}

0 comments on commit 8f9f2ea

Please sign in to comment.