Skip to content

References to Relative Documents With Embedded Schema cannot be resolved on Windows #220

@F7502

Description

@F7502

I want to parse an OpenAPI file that references another OpenAPI file like this (example taken from https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.3.md#referenceObject):

{
  "$ref": "definitions.json#/Pet"
}

I do this as follows:

func main() {
	// on Linux e.g. /dev/my-openapi.json
	// on Windows e.g. C:/dev/my-openapi.json
	openapi := filepath.FromSlash("C:/dev/my-openapi.json")
	swg := openapi3.NewSwaggerLoader()
	swg.IsExternalRefsAllowed = true
	oas, err := swg.LoadSwaggerFromFile(openapi)
	if err != nil {
		fmt.Println(err.Error())
	} else {
		fmt.Printf("%s\n", oas.Info.Title)
	}
}

This works on Linux (tested on a Mac) but not on Windows. Here I get something like this (my-openapi.json references my-other-openapi.json and both files are located in the same folder):

Error while resolving reference 'my-other-openapi.json#/components/responses/DefaultResponse': open my-other-openapi.json: The system cannot find the file specified.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions