Skip to content

For the complete documentation index, see llms.txt. Markdown versions of all docs pages are available by appending .md to any docs URL.

Create ApiDocs

Page as Markdown

Create ApiDoc resources to pair OpenAPI schemas with your backend services.

This guide must be completed by a Portal admin.

An ApiDoc resource represents the OpenAPI schema that is served by a backend Kubernetes service. The portal controller reads ApiDocs to render the API reference documentation in the portal frontend.

Before you begin

  1. Follow the Get started guide to install Solo Enterprise for kgateway.
  2. Set up a portal. For more information, see Get started with portal.

Deploy a sample app

  1. Deploy the petstore sample app. The examples in this guide use this app as the backing service for the ApiDocs resource.

    kubectl apply -f https://raw.githubusercontent.com/kgateway-dev/kgateway.dev/refs/heads/main/assets/docs/examples/petstore.yaml

    Verify that the petstore pod is running.

    kubectl get pods -n default -l app=petstore

    Example output:

    NAME                        READY   STATUS    RESTARTS   AGE
    petstore-6fd9c7f69d-4bntz   1/1     Running   0          10s
  2. Create an HTTPRoute for the petstore sample app. If you followed the Get started with portal guide, you already exposed the httpbin app under the api.example.com sample domain. This domain can be used as an umbrella for all APIs that you want to expose in the portal, including the petstore app from this example. To distinguish the routing paths for the different apps, you expose the petstore API endpoints under the /petstore prefix and use a URLRewrite filter to remove that prefix before forwarding requests to the petstore app.

    kubectl apply -f- <<EOF
    apiVersion: gateway.networking.k8s.io/v1
    kind: HTTPRoute
    metadata:
      name: petstore-route
      namespace: default
    spec:
      parentRefs:
      - name: portal-gateway
        namespace: default
      hostnames:
      - "api.example.com"
      rules:
      - matches:
        - path:
            type: PathPrefix
            value: /petstore
        filters:
        - type: URLRewrite
          urlRewrite:
            path:
              type: ReplacePrefixMatch
              replacePrefixMatch: /
        backendRefs:
        - name: petstore
          port: 8080
    EOF

Set up ApiDocs

Create an ApiDocs resource that represents the OpenAPI schema that your services serve. You can choose between the following options to provide your OpenAPI schema:

  • Manual: You can manually add the OpenAPI schema to the ApiDocs resource and inline each API endpoint in the resource directly.
  • URL: Provide a URL that exposes the OpenAPI schema that you want to serve.
  • Kube: Fetch the OpenAPI schema from an endpoint that is exposed by an in-cluster Kubernetes service.

Inline the full OpenAPI schema directly in the ApiDoc resource. Use this option when you want full control over the spec or when your service does not expose the schema on a specific path. The schema must be a valid OpenAPI v2 or v3 spec in JSON or YAML format.

Make sure to add the servedBy field to pair the ApiDoc with the service that serves the OpenAPI schema.

kubectl apply -f- <<EOF
apiVersion: portal.solo.io/v1alpha1
kind: ApiDoc
metadata:
  name: petstore-apidoc
  namespace: default
spec:
  source:
    manual:
      content: |
        {
          "openapi": "3.0.0",
          "info": {
            "title": "Petstore API",
            "version": "1.0.0"
          },
          "paths": {
            "/pets": {
              "get": {
                "summary": "List all pets",
                "responses": {
                  "200": {
                    "description": "A list of pets"
                  }
                }
              }
            }
          }
        }
  servedBy:
    name: petstore
    namespace: default
    port: 8080
EOF
SettingDescription
source.manual.contentThe full OpenAPI v2 or v3 schema in JSON or YAML format.
servedByThe Kubernetes service that backs this API.
servedBy.nameThe name of the Kubernetes service.
servedBy.namespaceThe namespace of the Kubernetes service.
servedBy.portThe port of the Kubernetes service.

Fetch the OpenAPI schema from an externally hosted HTTP or HTTPS endpoint. Use this option when the OpenAPI spec is maintained outside the cluster and you do not want to store a local copy.

Make sure to add the servedBy field to pair the ApiDoc with the service that serves the OpenAPI schema.

kubectl apply -f- <<EOF
apiVersion: portal.solo.io/v1alpha1
kind: ApiDoc
metadata:
  name: petstore-url-apidoc
  namespace: default
spec:
  source:
    url:
      endpoint: "https://petstore3.swagger.io/api/v3/openapi.json"
  servedBy:
    name: petstore
    namespace: default
    port: 8080
EOF
SettingDescription
source.url.endpointThe full HTTP or HTTPS URL where the portal controller fetches the OpenAPI schema. For HTTPS, the URL must be included in the certificate that validates the HTTPS traffic.
servedByThe Kubernetes service that backs this API. Required for URL sources because the controller cannot infer the backend automatically.
servedBy.nameThe name of the Kubernetes service.
servedBy.namespaceThe namespace of the Kubernetes service.
servedBy.portThe port of the Kubernetes service.

Fetch the OpenAPI schema from an endpoint that is exposed by an in-cluster Kubernetes service. Use this option when the service exposes its own OpenAPI spec at a known path, such as /openapi.json or /swagger.json.

Note that you do not need to set the servedBy field, because the services is automatically derived from the service that is referenced in the targetRef field.

kubectl apply -f- <<EOF
apiVersion: portal.solo.io/v1alpha1
kind: ApiDoc
metadata:
  name: petstore-kube-apidoc
  namespace: default
spec:
  source:
    kube:
      targetRef:
        name: petstore
        port: 8080
      path: /openapi.json
EOF
SettingDescription
source.kube.targetRef.nameThe name of the Kubernetes service that exposes the OpenAPI schema.
source.kube.targetRef.portThe port of the Kubernetes service.
source.kube.pathThe path on the service where the OpenAPI schema is available, such as /openapi.json or /swagger.json.
servedByOptional. If not specified, the controller infers the backend from source.kube.targetRef.

Verify ApiDocs

  1. List the ApiDocs in your namespace. Verify that their READY status is set to True.

    kubectl get apidoc -n default

    Example output:

    NAME                    SOURCE   READY
    petstore-apidoc         Manual   True
    petstore-url-apidoc     URL      True
    petstore-kube-apidoc    Kube     True
  2. If an ApiDoc does not show Ready=True, describe the resource to see error details.

    kubectl describe apidoc <name> -n default

    Common issues that you might encounter include:

    • The OpenAPI schema exceeds the 1MB size limit.
    • The schema contains invalid OpenAPI syntax.
    • The servedBy field is missing or the referenced service is unreachable.
    • For URL sources, the endpoint is not accessible or the HTTPS certificate is invalid.

Next

Was this page helpful?