-
-
Notifications
You must be signed in to change notification settings - Fork 483
Description
Loading an OpenAPI definition file will only attempt to load any external references in schemas that are defined according to the standard OpenAPI definition layout. More specifically, your references must be wrapped in an components object so this tool can inline them into the definition.
This is an assumption on layout, which is not strictly enforced by OpenAPI. For example, I am using this tool with a structure like this:
Where the request.json consists of the following:
{
"type": "object",
"required": [
"definition_reference"
],
"properties": {
"definition_reference": {
"$ref": "definitions.json#/definitions/External"
}
}
}
And definitions.json of the following:
{
"definitions": {
"External": {
"type": "string"
}
}
}
Loading the openapi.json will fail with the following message:
failed to resolve "#/definitions/External" in fragment in URI: "External": struct field "External" not found
I think this tool should support arbitrary schema references and not rely on users to always implement it by keeping the references in OpenAPI component objects.
A small side-note, I have attempted to take a shot at fixing this, but I am struggling with overseeing the impact of changes I make in other flows because I am not familiar with the entire codebase. 😅 I would be able to submit a PR if someone could give me some guidance as of where this should be changed (probably somewhere around swagger_loader.go and how to perhaps set this up in a way that it doesn't impact the old implementation of loading references.
I created a branch on my fork which contains a unit test that describes the issue: commit
