KB Article #182463
OAS 3 error when using file based import
Problem
- Importing OAS 3 file gives error when imported as a file, but imports fine when imported from a URL.
- Error seen is: "Relative server URL not supported for scheme: 'file'. Please add $.servers to the OAS3 document, or host it as is, and import via URL."
- The OAS 3 file is missing the Servers section or an absolute URL field.
Resolution
This is expected behavior when using file based import of such an OAS 3 swagger file.
Workaround: either add a Servers section with a URL, or use URL based import. URL based import works for the same swagger import because the underlying import URL itself is used to substitute for the missing Severs section URL.
From the spec.
While technically the Servers section is optional, https://swagger.io/docs/specification/api-host-and...
"If the servers array is not provided or is empty, the server URL defaults to /:"
But that presents a problem when imported via file, https://swagger.io/docs/specification/api-host-and...#relative-urls
"The URLs in the servers
array can be relative, [...] In this case, the URL is resolved against the server that hosts the given OpenAPI definition."
Since if there was no absolute URL in Servers, and no URL that hosts the definition (because of file based import), then it is unable to determine what the relative path is relative to.