Downloading API specs with external references

We have REST APIs that are defined across multiple OpenAPI definition files, where the main specification references other using an external $ref reference.

API Hub offers a getContents API that returns a JSON object with the mime type and the content of the API definition as a byte64-encoded string. This API poses the first issue: it’s difficult for consumers to download the file the response needs converting. The second issue is that once downloaded, there is no way for OpenAPI tooling to resolve external references with API Hub.

I can build a proxy around this to enable direct downloading and reference resolving, but perhaps there is a better way?

Hi @Jon_Black ,

I agree the API Hub APIs are a bit challenging in that regard.

For the first issue, I suggest you look at apigeecli, it is useful for simplifying access to API Hub and hides lots of the “challenges” with the APIs behind CLI commands.

Use: “apigeecli tree” to see all the commands in a hierarchical view.

Here’s an example set of commands to get a specification:

apigeecli --org=$ORG --region=us-central1 apihub apis list
...
{
   "name": "projects/apigeex-enterprise/locations/us-central1/apis/5a114fbd-70a6-403c-96c7-9b4d772d73bb",
   "displayName": "bu1-proxy-1",
...

apigeecli --org=$ORG --region=us-central1 apihub apis versions list \
    --api-id=5a114fbd-70a6-403c-96c7-9b4d772d73bb
{
  "versions": [
    {
      "name": "projects/apigeex-enterprise/locations/us-central1/apis/5a114fbd-70a6-403c-96c7-9b4d772d73bb/versions/b8fb7302-a5e3-4697-b1af-ae20a9d9ceba",
      "displayName": "1",
      "specs": [
        "projects/apigeex-enterprise/locations/us-central1/apis/5a114fbd-70a6-403c-96c7-9b4d772d73bb/versions/b8fb7302-a5e3-4697-b1af-ae20a9d9ceba/specs/04c3c161-4ba2-4d0b-9fd7-c9960db874ec"
      ]

apigeecli --org=$ORG --region=us-central1 apihub apis versions specs list \
    --api-id=5a114fbd-70a6-403c-96c7-9b4d772d73bb \
    --version=b8fb7302-a5e3-4697-b1af-ae20a9d9ceba
{
  "specs": [
    {
      "name": "projects/apigeex-enterprise/locations/us-central1/apis/5a114fbd-70a6-403c-96c7-9b4d772d73bb/versions/b8fb7302-a5e3-4697-b1af-ae20a9d9ceba/specs/04c3c161-4ba2-4d0b-9fd7-c9960db874ec",
      "displayName": "bu1-proxy-1",
     

apigeecli --org=$ORG --region=us-central1 apihub apis versions specs get \
    --api-id=5a114fbd-70a6-403c-96c7-9b4d772d73bb \
    --version=b8fb7302-a5e3-4697-b1af-ae20a9d9ceba \
    --spec-id=04c3c161-4ba2-4d0b-9fd7-c9960db874ec \
    --contents --output=oas.yaml
Contents of Spec 04c3c161-4ba2-4d0b-9fd7-c9960db874ec written to oas.yaml

head oas.yaml
openapi: 3.0.0
info:
  title: Food Trucks API
  description: API for food trucks, menus, locations and comments (fixed)
  version: 1.0.0
  contact: {}
paths:
  /foodTrucks:
    get:

As for the second issue, yeah, that’s gonna take some work.
Basically, you are asking API Hub to ack like a repository of API specs with direct access to referenced APIs from within your spec via $ref. Even if you were willing to change the $refs in your spec, API Hub does not provide a “raw” access to the spec.

Regards,
Kurt

Hi @kurtkanaskie

Thanks for the quick reply. apigeecli is an interesting option indeed but it would still be blocked by the second issue. Most OpenAPI tooling will resolve external references so it’s a shame API Hub doesn’t offer raw access to the spec. Do you think this is something that could be added to the API?

In the meantime, I think a proxy that provides this API and translating references is the best workaround I can think of outside of merging spec files or using archives (both not ideal).

Kind regards,

Jon

I’ve been thinking a bit more about this problem and I see an opportunity for API Hub to provide more support for multi-file specs for shared components. We have some components (a good example is the definition for a ProblemJSON response) that many teams use. It would be useful to have a space in API Hub to share these.