11 min • read

Developer Portal

Rendering API documentation

The Dev Portal uses the Mapping resource to automatically discover services known by the Ambassador Edge Stack.

For each Mapping, the Dev Portal will attempt to fetch an OpenAPI V3 document when a docs attribute is specified.

docs attribute in Mappings

This documentation endpoint is defined by the optional docs attribute in the Mapping.

yaml
docs:
path: "string" # optional; default is ""
url: "string" # optional; default is ""
ignored: bool # optional; default is false
timeout_ms: integer # optional; default is 5000
display_name: "string" # optional; default is ""

where:

  • path: path for the OpenAPI V3 document. The Ambassador Edge Stack will append the value of docs.path to the prefix in the Mapping so it will be able to use Envoy's routing capabilities for fetching the documentation from the upstream service . You will need to update your microservice to return a Swagger or OAPI document at this URL.
  • url: absolute URL to an OpenAPI V3 document.
  • ignored: ignore this Mapping for documenting services. Note that the service will appear in the Dev Portal anyway if another, non-ignored Mapping exists for the same service.
  • timeout_ms: number of milliseconds that the devportal HTTP client will wait for a service to respond on their docs endpoint
  • display_name: custom name to show for this service in the devportal.

Note:

Previous versions of the Dev Portal tried to obtain documentation automatically from /.ambassador-internal/openapi-docs by default, while the current version will not try to obtain documentation unless a docs attribute is specified. Users should set docs.path to /.ambassador-internal/openapi-docs in their Mappings in order to keep the previous behavior.

The docs field of Mappings was not introduced until Ambassador Edge Stack version 1.9 because Ambassador Edge Stack was automatically searching for docs on /.ambassador-internal/openapi-docs. Make sure to update your CRDs with the following command if you are encountering problems after upgrading from an earlier version of Ambassador Edge Stack.

yaml
`kubectl apply -f https://getambassador.io/yaml/aes-crds.yaml`

If you are on an earlier version of Ambassador Edge Stack, either upgrade to a newer version, or make your documentation available on /.ambassador-internal/openapi-docs

Example:

With the Mappings below, the Dev Portal would fetch OpenAPI documentation from service-a:5000 at the path /srv/openapi/ and from httpbin from an external URL. service-b would have no documentation. The httpbin service must respond in 4000 seconds or else the request will time out.

yaml
---
apiVersion: getambassador.io/v2
kind: Mapping
metadata:
name: service-a
spec:
prefix: /service-a/
rewrite: /srv/
service: service-a:5000
docs:
path: /openapi/ ## docs will be obtained from `/srv/openapi/`
---
apiVersion: getambassador.io/v2
kind: Mapping
metadata:
name: service-b
spec:
prefix: /service-b/
service: service-b ## no `docs` attribute, so service-b will not be documented
---
apiVersion: getambassador.io/v2
kind: Mapping
metadata:
name: regular-httpbin
spec:
host_rewrite: httpbin.org
prefix: /httpbin/
service: httpbin.org
docs:
timeout_ms:4000
url: https://httpbin.org/spec.json

Notes on access to documentation paths:

By default, all the paths where documentation has been found will NOT be publicly exposed by the Ambassador Edge Stack. This is controlled by a special FilterPolicy installed internally.

Limitations on Mappings with a host attribute

The Dev Portal will ignore Mappings that contain hosts that cannot be parsed as a valid hostname, or use a regular expression (when host_regex: true).

Publishing the documentation

All rendered API documentation is published at the /docs/ URL by default. Users can achieve a higher level of customization by creating a DevPortal resource. DevPortal resources allow the customization of:

  • what documentation is published
  • how it looks

Users can create a DevPortal resource for specifying the default configuration for the Dev Portal, filtering Mappings and namespaces and specifying the content.

Note: when several DevPortal resources exist, the Dev Portal will pick a random one and ignore the rest. A specific DevPortal can be used as the default configuration by setting the default attribute to true. Future versions will use other DevPortals for configuring alternative views of the Dev Portal.

DevPortal resources have the following syntax:

yaml
apiVersion: getambassador.io/v2
kind: DevPortal
metadata:
name: "string"
namespace: "string"
spec:
default: bool ## optional; default false
docs: ## optional; default is []
- service: "string" ## required
url: "string" ## required
content: ## optional
url: "string" ## optional; see below
branch: "string" ## optional; see below
dir: "string" ## optional; see below
selector: ## optional
matchNamespaces: ## optional; default is []
- "string"
matchLabels: ## optional; default is {}
"string": "string"
naming_scheme: "string" ## optional; supported values [ "namespace.name", "name.prefix" ]; default "namespace.name"
search:
enabled: bool ## optional; default false
type: "string" ## optional; supported values ["title-only", "all-content"]; default "title-only"
preserve_servers: bool ## optional; see below

where:

  • default: true when this is the default Dev Portal configuration.
  • content: see section below.
  • selector: rules for filtering Mappings:
    • matchNamespaces: list of namespaces, used for filtering the Mappings that will be shown in the DevPortal. When multiple namespaces are provided, the DevPortal will consider Mappings in any of those namespaces.
    • matchLabels: dictionary of labels, filtering the Mappings that will be shown in the DevPortal. When multiple labels are provided, the DevPortal will only consider the Mappings that match all the labels.
  • docs: static list of service/documentation pairs that will be shown in the Dev Portal. Only the documentation from this list will be shown in the Dev Portal (unless additional docs are included with a selector).
    • service: service name used for listing user-provided documentation.
    • url: a full URL to a OpenAPI document for this service. This document will be served as it is, with no extra processing from the Dev Portal (besides replacing the hostname).
  • naming_scheme: Configures how DevPortal docs are displayed and linked to in the UI.
    • "namespace.name" will display the docs with the namespace and name of the mapping. e.g. a Mapping named quote in namespace default will be displayed as default.quote and its docs will have the relative path of /default/quote
    • "name.prefix" will display the docs with the name and prefix of the mapping. e.g. a Mapping named quote with a prefix backend will be displayed as quote.backend and its docs will have the relative path of /quote/backend
  • search: as of Ambassador Edge Stack 1.13.0, the DevPortal content is now searchable
    • enabled: default `false``; set to true to enable search functionality.
      • When enabled=false, the DevPortal search endpoint (/[DEVPORTAL_PATH/api/search) will return an empty response
    • type: Configure the items fed into search
      • title-only (default): only search over the names of DevPortal services and markdown pages
      • all-content: Search over openapi spec content and markdown page content.
  • preserve_servers: when set to true, configures the DevPortal to use server definitions from openAPI documents instead of implicitly building server definitions.

Example:

The scope of the default Dev Portal can be restricted to Mappings with the public-api: true and documented: true labels by creating a DevPortal ambassador resource like this:

yaml
---
apiVersion: getambassador.io/v2
kind: DevPortal
metadata:
name: ambassador
spec:
default: true
content:
url: https://github.com/datawire/devportal-content-v2.git
selector:
matchLabels:
public-api: "true" ## labels for matching only some Mappings
documented: "true" ## (note that "true" must be quoted)

Example:

The Dev Portal can show a static list OpenAPI docs. In this example, a eks.aws-demo service is shown with the documentation obtained from a URL. In addition, the Dev Portal will show documentation for all the services discovered in the aws-demo namespace:

yaml
---
apiVersion: getambassador.io/v2
kind: DevPortal
metadata:
name: ambassador
spec:
default: true
docs:
- service: eks.aws-demo
url: https://api.swaggerhub.com/apis/kkrlogistics/amazon-elastic_kubernetes_service/2017-11-01/swagger.json
selector:
matchNamespaces:
- aws-demo ## matches all the services in the `aws-demo` namespace
## (note that Mappings must contain a `docs` attribute)

Note:

The free and unlicensed versions of Ambassador Edge Stack only support documentation for five services in the DevPortal. When you start publishing documentation for more services to your DevPortal, keep in mind that you will not see more than 5 OpenAPI documents even if you have more than 5 services properly configured to report their OpenAPI specifications. For more information on extending the number of services in your DevPortal please contact sales via our pricing information page.

Styling the DevPortal

The look and feel of a DevPortal can be fully customized for your particular organization by specifying a different content, customizing not only what is shown but how it is shown, and giving the possibility to add some specific content on your API documentation (e.g., best practices, usage tips, etc.) depending on where it has been published.

The default Dev Portal content is loaded in order from:

  • the ambassador DevPortal resource.
  • the Git repo specified in the optional DEVPORTAL_CONTENT_URL environment variable.
  • the default repository at GitHub.

To use your own styling, clone or copy the repository, create an ambassador DevPortal and update the content attribute to point to the repository. If you wish to use a private GitHub repository, create a Personal Access Token and include it in the content following the example below:

yaml
---
apiVersion: getambassador.io/v2
kind: DevPortal
metadata:
name: ambassador
spec:
default: true
content:
url: https://9cb034008ddfs819da268d9z13b7ecd26@github.com/datawire/private-devportal-repo.git
selector:
matchLabels:
public-api: true

The content can be have the following attributes:

yaml
content:
url: "string" ## optional; default is the default repo
branch: "string" ## optional; default is "master"
dir: "string" ## optional; default is "/"

where:

  • url: Git URL for the content
  • branch: the Git branch
  • dir: subdirectory in the Git repo

Iterating on Dev Portal styling and content

Local Development

Check out a local copy of your content repo and from within run the following docker image:

shell
docker run -it --rm --volume $PWD:/content --entrypoint local-devportal --publish 1080:1080
docker.io/datawire/aes:1.14.1 /content

and open http://localhost:1080 in your browser. Any changes made locally to devportal content will be reflected immediately on page refresh.

Note:

The docker command above will only work for AES versions 1.13.0+.

Remote Ambassador Edge Stack

After committing and pushing changes to your devportal content repo changes to git, set your DevPortal to fetch from your branch:

yaml
---
apiVersion: getambassador.io/v2
kind: DevPortal
metadata:
name: ambassador
spec:
default: true
content:
url: $REPO_URL
branch: $DEVELOPMENT_BRANCH

Then you can force a reload of DevPortal content by hitting a refresh endpoint on your remote ambassador:

shell
# first, get your ambassador service
export AMBASSADOR_LB_ENDPOINT=$(kubectl -n ambassador get svc ambassador \
-o "go-template={{range .status.loadBalancer.ingress}}{{or .ip .hostname}}{{end}}")
# Then refresh the DevPortal content
curl -X POST -Lk ${AMBASSADOR_LB_ENDPOINT}/docs/api/refreshContent

Note:

The DevPortal does not share a cache between replicas, so the content refresh endpoint will only refresh the content on a single replica. It is suggested that you use this endpoint in a single replica Ambassador Edge Stack setup.

Customizing documentation names and paths

The Dev Portal displays the documentation's Mapping name and namespace by default, but you can override this behavior.

To change the documentation naming scheme for the entire Dev Portal, you can set naming_scheme in the DevPortal resource:

yaml
---
apiVersion: getambassador.io/v2
kind: DevPortal
metadata:
name: ambassador
spec:
default: true
naming_scheme: "name.prefix"

With the above configuration, a mapping for service-a:

yaml
---
apiVersion: getambassador.io/v2
kind: Mapping
metadata:
name: service-a
spec:
prefix: /path/
service: service-a:5000
docs:
path: /openapi/

Will be displayed in the Dev Portal as service-a.path, and the API documentation will be accessed at $AMBASSADOR_URL/docs/doc/service-a/path.

You can also override the display name of documentation on a per-mapping basis. Per-mapping overrides will take precedence over the DevPortal naming_scheme.

A mapping for service-b with display_name set:

yaml
---
apiVersion: getambassador.io/v2
kind: Mapping
metadata:
name: service-b
spec:
prefix: /otherpath/
service: service-b:5000
docs:
path: /openapi/
display_name: "Cat Service"

Will be displayed in the Dev Portal as Cat Service, and the documentation will be accessed at $AMBASSADOR_URL/docs/doc/Cat%20Service.

Default configuration

The Dev Portal supports some default configuration in some environment variables (for backwards compatibility).

Environment variables

The Dev Portal can also obtain some default configuration from environment variables defined in the AES Deployment. This configuration method is considered deprecated and kept only for backwards compatibility: users should configure the default values with the ambassador DevPortal.

SettingDescription
AMBASSADOR_URLExternal URL of Ambassador Edge Stack; include the protocol (e.g., https://)
POLL_EVERY_SECSInterval for polling OpenAPI docs; default 60 seconds
DEVPORTAL_CONTENT_URLDefault URL to the repository hosting the content for the Portal
DEVPORTAL_CONTENT_DIRDefault content subdir (defaults to /)
DEVPORTAL_CONTENT_BRANCHDefault content branch (defaults to master)
DEVPORTAL_DOCS_BASE_PATHBase path for api docs (defaults to /doc/)