0

We are running Backstage v1.37, and are trying to render our OpenAPI definitions by referencing them in the definition field, rather than hard-coding the content into our YAML files that define the catalog entry. Specifically as this allows the document itself to live separately from the Catalog entry.

In this case, we are specifically setting up an object of kind "API", as per docs, here: https://backstage.io/docs/features/software-catalog/descriptor-format/#kind-api

As an example, this is what the definition might look like:

---
apiVersion: backstage.io/v1alpha1
kind: API
metadata:
  name: ourapi-api
  description: An API that does things that we want it to do, because reasons.
  title: Our API
  annotations:
    dev.azure.com/host-org: dev.azure.com/a-host-org
  tags:
  - net8
  - api
  links:  
  - url: https://domain.example/app/113235224
spec:
  type: openapi
  lifecycle: production
  owner: my-owning-team
  system: our-system
  definition: 
    $text: https://domain.example/static/swagger.prod.json

As you can see, we're using the substitution setup, using $text to give us the option to pull in data from an external URL, in line with the documentation found here: https://backstage.io/docs/features/software-catalog/descriptor-format/#substitutions-in-the-descriptor-format

As "definition" is a text field, we must use $text. Using $json does not work (we have tried).

We have modified our Backstage app.config to include the relevant backend URLs we want to allow reading from, like so:

backend:
  baseUrl: ...
  reading:
    allow:
      - host: *.domain.example

Requesting the OpenAPI document from our hosting results in a 200 OK request, which looks like this, locally: Image showing successful 304 response, with valid openapi document displayed on screen

We've checked our OpenAPI doc is valid by pasting it into https://editor.swagger.io/, and receive no warnings / errors at all.

The actual error we receive from the Backstage UI is:

Unable to render this definition The provided definition does not specify a valid version field.

Please indicate a valid Swagger or OpenAPI version field. Supported version fields are swagger: "2.0" and those that match openapi: 3.x.y (for example, openapi: 3.1.0).

However, as you can clearly see in the screenshot above, the first property of the returned document is in fact the openapi version:

{
    "openapi": "3.0.4",
    "info": { ...

We are able to load the OpenAPI definition into Swagger UI hosted by our API, too, which suggests it is indeed valid.

As Backstage is not the most common tool, finding resources that touch specifically on this topic has not been easy - the ones that I have found, including asking CoPilot, google searching and looking at example repos, all seem to set things up in exactly the way described here. Any help would be appreciated!

1 Answer 1

1

I resolved this by manually updating the @backstage/plugin-api-docs to version "0.13.0-next.1". This has a new version of "swagger-ui-react" which fixed this exact issue in https://github.com/swagger-api/swagger-ui/issues/10502.

Sign up to request clarification or add additional context in comments.

2 Comments

This looks promising! However, I can't seem to get this working, primarily because of my lack of knowledge(?). I run a yarn remove @backstage/plugin-api-docs, and then a yarn add @backstage/[email protected] This seems to update everything, as the next time Backstage is launched, i see that the versions installed shows: "0.13.0-next.1, 0.12.5" Am i missing something obvious?
I updated the version in the package.json file and ran yarn install. After that it worked. I'm also not very knowledgable when it comes to frontend stuff like this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.