Declarative documents
The declarative unit is the API-version: since a version is an API, one document
carries an API and its plans, with its documentation pages beside them. apis get produces it,
apply consumes it, and remote catalogs reconcile it.
apiVersion: otoroshi-apim.io/v1
kind: Api
metadata:
name: petstore # the slug: the document is upserted by (workspace, name, version)
spec:
version: 1.0.0
name: Petstore
description: Pets, as a product.
team: Platform team # a team name or id of the workspace
tags: [demo]
visibility: public # public | authenticated | restricted
acl: [] # tags, for restricted visibility
draft:
entrypoint: { domain: petstore.oto.tools, contextPath: /v1 }
backends:
- id: backend_echo
name: echo
targets: [{ hostname: echo, port: 8080, tls: false, weight: 1 }]
flows:
- id: default_flow
name: Default flow
plugins:
- { plugin: cp:otoroshi.next.plugins.OverrideHost }
- { group: Company security headers, version: 1 } # a shared policy group, by name
resources:
- { id: res_pets, name: Pets, path: /pets, methods: [GET, POST], backendId: backend_echo, flowId: default_flow }
plans:
- id: plan_petstore_discovery
name: Discovery
status: published
auth: { kind: apikey }
rateLimit: { enabled: true, calls: 5, windowMs: 1000 }
quota: { daily: 1000 }
resourceFilter: { mode: only, resources: [res_pets] }
validation: auto
openapi:
format: yaml
content: |
openapi: 3.0.3
…
documentation: { languages: [en, fr], defaultLanguage: en }
pages:
- slug: getting-started
title: { en: Getting started, fr: Démarrage }
content:
en: "# Petstore …"
fr: { file: docs/getting-started.fr.md } # a file beside the document
The complete file is examples/petstore.yaml;
examples/catalog/apis.yaml
holds several documents in one multi-document YAML file.
Every attribute of a plan described in Plans can be set; what is left out takes its default. Ids are yours to choose: they are stable, so a plan keeps its subscriptions from one apply to the next.
The version is spec.version, as in a Kubernetes resource, whose metadata
cannot carry it. metadata.version, the first form of the format, is still read; both given and
different, the document is refused.
What it pins, by name
A flow pins a shared policy group, a plan a
shared resource: the document names them —
{ group: Company security headers, version: 1 },
sharedResource: { name: Corporate IdP, version: 1 } — so that it moves from one installation to the
next, where the same names are published. An id (pgrp_…, res_…) is accepted too, as it is for a
team. The export writes names; the product keeps ids. A name names one object of its kind in a
workspace: a second group or resource of the same name is refused, and a name that is unknown —
or, in older data, shared by two — refuses the document, saying so.
The pages
The documentation pages are beside the draft, in spec.pages, by slug. A document that lists
its pages is their truth: a page it no longer lists is deleted. A document without pages leaves
them alone.
The content of a page, in a language, is the text itself or a file beside the document:
{ file: docs/getting-started.fr.md }, a path relative to the document that stays within its
source — no absolute path, no .., 1 MB at most. Whoever holds the files reads them: otoroshi-apim apply
from the disk, a remote catalog from its repository, its bucket or the
origin of its url. Over HTTP the content is given inline: the admin API refuses a file it cannot
read, and so does a Kubernetes resource.
Applying
otoroshi-apim apply default -f petstore.yaml # writes the draft
otoroshi-apim apply default -f petstore.yaml --publish # + freezes a snapshot if anything changed
otoroshi-apim apply default -f petstore.yaml --publish --deploy # + projects it
apply upserts by (workspace, metadata.name, spec.version) and writes the draft: publishing
and deploying stay explicit acts unless asked for. A document applied twice changes nothing
(snapshot unchanged). The draft it carries replaces the draft; the attributes it leaves out (its
name, its tags…) keep their value; its pages are their truth when it lists them.
--managed-by <source> marks the API as owned by that source: the console then refuses to edit it
by hand.
Over HTTP: POST /api/workspaces/<ws>/apply?publish=true&deploy=true with one document, a list, or
{"items": […]}.
The design of a portal
The developer portal of a workspace has a declarative document too, kind: Portal: its
design — mode, texts, theme, navigation, home, pages,
templates, style sheet, script and assets —, a folder that otoroshi-apim portal pull writes and
otoroshi-apim portal push sends back, and that a remote catalog reads beside the Api documents.