This repository contains Tidepool Platform API documentation in OpenAPI v3 format with additional narrative content in Stoplight-flavored CommonMark format which in turn is a less ambiguous formal definition of Markdown.
These API definitions can be used to generate stub code for either server or client side. Currently, we only do this with the clinic
service (see below for special note on that).
We have an account in Stoplight for publishing the documentation and API specifications. The goal is for that site to soon replace the current developer portal. It is possible to edit the documentation files directly online in Stoplight - however we are not using that capability, for several reasons:
- Doing so requires using one of a limited number of seats (5).
- It does not fit well into our normal review/approval workflow.
- It requires integration with GitHub with broad scopes including access to private repositories.
- It does not enable us to run pre-merge checks, in particular to validate changes that could break generated server stub code such as the
clinic
service. See thecheck
andgenerate
steps in the Makefile. - It does not enable us to run pre-processing steps necessary to consolidate multiple API specification files into a single OpenAPI v3 specification to make the published API view more coherent. See the
prepare
steps in the Makefile. - We automatically publish two sets of API specifications from the same source files:
- public documentation that only describes APIs useful to client application developers.
- private/full documentation that describes all APIs, even ones that are only accessible to Tidepool team internal use.
The preferred workflow is to edit these files offline, then commit them to GitHub which automatically pushes updates into Stoplight, including work branches though they are not visible to people outside of Tidepool. Here are the workflow details:
-
Clone this repository and install the validation & publishing tools. You only need to to this once.
git clone https://github.com/tidepool-org/TidepoolApi.git cd TidepoolApi make install_tools
-
Create a work branch for your edits:
git checkout master git pull git checkout master -b {branch}
-
Edit and preview the files offline using any of the tools listed below.
-
Validate your changes locally:
make check make prepare
-
Commit your changes to the work branch and push to GitHub. This will automatically kick off a GitHub Action that checks & publishes the new (draft) documentation into a branch in Stoplight.
git add {file(s)} git commit -m "{description}" git checkout master git pull git checkout {branch} git merge --no-ff master git push -u origin HEAD
-
Post a pull request (PR) to review the changes
-
Once the PR is approved, merge to master which will again automatically update the master branch in the Stoplight site.
It is also possible to publish your work branch to Stoplight from your local folder. You will need the API tokens for Stoplight stored in
If you add a brand new top-level OpenAPI 3.0 specification file, it needs to be added to the templates/openapi-merge.jsonnet
template file so that it gets included in the combined specification file that is published in Stoplight.
To publish documentation and API specifications locally, you will need the corresponding API token from Stoplight. Those API tokens are not directly found in the Stoplight project settings UI, but they are documented here or if that link no longer works, Google for it.
The tokens are configured as secrets for the GitHub Actions and can be found here:
- Token for Public API
- Token for Full API
The contents in Tidepool's organization home page in Stoplight comes from a file in this repository. To update it:
- Edit the landing.md Markdown file.
- Commit the changes & push to GitHub, for posterity.
- Copy & paste the file's Markdown contents into the Settings page. This requires admin permissions in Stoplight.
- Free Stoplight Studio. This is the recommended tool since it is the closest rendering to the publishing site.
- Free Microsoft Visual Studio Code, with plug-ins for validating and rendering OpenAPI v3 specifications and Markdown documentation.
- Many other IDEs offer similar plug-ins.
The Makefile makes use of several CLI tools to check, prepare, and publish the documentation and specifications. You can install the tools by executing the following command:
make install_tools
You can check if you have all the tools installed by executing the following command:
make check_tools
Tool | Description |
---|---|
markdownlint | Validates Markdown files. |
markdown-link-check | Validates hyperlinks in Markdown files. |
spectral | Validates OpenAPI 3.0 specification files. |
swagger-cli | Validates OpenAPI 3.0 specification files. Also bundles multiple OAS3 files into a single file, that is required by some downstream use-cases. |
redocly | Validates OpenAPI 3.0 specification files. Also bundles multiple OAS3 files into a single file, that is required by some downstream use-cases. |
jsonnet | Data templating tool. Used here to generate the configuration file for openapi-merge-cli . |
openapi-merge-cli | Merges OpenAPI 3.0 specification files into single file. |
stoplight | Publishes OpenAPI 3.0 specifications and documentation in Markdown format to Stoplight's web site. |
oapi-codegen | Generates server and client stub code from OpenAPI 3.0 specifications. Used currently to generate the clinic service code. |