snok/drf-openapi-tester

Support for retrieving OpenAPI schema from URL

Closed this issue ยท 2 comments

I'm currently trying to use the package in our Django test suite for an specific service, the thing is that we have all our schemas in a separated repository that's why we spin up that repository and we can access the schemas the different schemas for example like http://schema_repository:{port}/xyz_schemas/openapi.yaml.

When attempting to pass that path to SchemaTester I found out that it fails to find the file, and checking into the code I see load_schema only attempts to read from a file (

with open(self.path, encoding="utf-8") as file:
) (which makes us now to grab the files we need, store them, pass the path and remove them).

It would be ideal if load_schema could support also the possibility of retrieving the schema itself from an URL.

The library has a concept of "loaders". There is a file-loader, a drf-yasg-loader, and a drf-spectacular-loader. This sounds like a use-case for an "url-loader" or something along those lines.

In other words, I think it would make sense to write your own class to handle the case where you need to retrieve a schema from a URL. If you do, a PR is welcome; this sounds useful ๐Ÿ‘

Here's the StaticSchemaLoader for reference. All you would need to do is write your own load_schema method which fetches the schema with a GET request.

@sondrelg thanks for clear guidance! I will submit a PR with this feature probably tomorrow then ๐Ÿ‘