Corrected remote document lookup behavior

When remote documents are requested and there is no way to know the base URL, the index will now try and determine the base path from the way the spec was loaded (if it comes in remote, we use the base URL of the spec)
This commit is contained in:
Dave Shanley
2023-04-02 12:19:46 -04:00
parent ec83a9ca9b
commit 24d094ca7b
3 changed files with 410 additions and 344 deletions

View File

@@ -504,6 +504,35 @@ paths:
assert.Equal(t, d, strings.TrimSpace(string(rend)))
}
func TestDocument_RemoteWithoutBaseURL(t *testing.T) {
// This test will push the index to do try and locate remote references that use relative references
spec := `openapi: 3.0.2
info:
title: Test
version: 1.0.0
paths:
/test:
get:
parameters:
- $ref: "https://schemas.opengis.net/ogcapi/features/part2/1.0/openapi/ogcapi-features-2.yaml#/components/parameters/crs"`
config := datamodel.NewOpenDocumentConfiguration()
doc, err := NewDocumentWithConfiguration([]byte(spec), config)
if err != nil {
panic(err)
}
result, errs := doc.BuildV3Model()
if len(errs) > 0 {
panic(errs)
}
assert.Equal(t, "crs", result.Model.Paths.PathItems["/test"].Get.Parameters[0].Name)
}
func TestDocument_ExampleMap(t *testing.T) {
var d = `openapi: "3.1"
components: