swagger-js icon indicating copy to clipboard operation
swagger-js copied to clipboard

External file references interfere with local resolution of definitions.

Open watnotte opened this issue 10 years ago • 2 comments

I had originally opened this under swagger-ui https://github.com/swagger-api/swagger-ui/issues/2273) because I didn't see it happening in the online Swagger Editor but as requested, I'm opening a ticket under swagger-js.


I updated to the latest from the master branch and still see the same behaviour.

I have a swagger file:

sandbox-swagger.txt

that defines a Base and Composite resource definition. When I load it up in Swagger UI, it displays fine and the composite resource Example Value shows all the properties from both definitions.

without-external-ref

However, when I add a new operation that references an external resource:

    "/imported": {
        "$ref": "https://raw.githubusercontent.com/Voyent/swagger-ui/master/src/main/html/services/ops-swagger.json#/import"
    }

sandbox-swagger-import.txt

The Example Value now showing for the composite parameter is incorrect. It seems like it's not resolving the local definitions properly.

with-external-ref

Note:

  • I don't see any errors in the browser console.
  • Both files appear to get loaded properly.
  • I do not see the same issue in the Swagger Editor.
  • It doesn't matter if the reference is relative or absolute.
  • It works if I remove the reference or inline the information from the external file.

Just to follow up, I was playing around with other externally referenced files, for example this default response:

          "default": {
            "description": "An error occurred.",
            "schema": {
              "$ref": "definitions.json#/Error"
            }
          }

It appears that any externally referenced file interferes with the Example Value when it relies on an internal reference for composition. I'm really hoping to avoid copying and pasting all the external information into the specific API files.

watnotte avatar Jul 15 '16 16:07 watnotte

I worked on this a bit--it won't be in 2.1.16 but shortly after. It's a tricky one that we'll ensure is handled.

fehguy avatar Jul 21 '16 17:07 fehguy

This should be fixed. We cloned the response models to avoid the loops caused in the JS client.

fehguy avatar Jan 12 '17 00:01 fehguy