This is where the documentation for the Tracdelight API lives. We use apidocjs to document the API. Please read below to get started working with the documentation.
The files seen in this repo are the compiled source of the files which can be found in the edelight/api repository in the docs/api/ folder.
When updating documentation source files, you will be doing your work in the edelight/api repository and then a deployment job will transfer your compiled source to this repository.
All you need to know is the apiDoc-Params which will be processed by apidocjs
. If you need to inherit some code block, define it in _apidoc.py
and import using the @apiUse
parameter.
In order to get a quick feedback loop when writing your own documentation, you
can skip Docker
and just run the apidoc
command line tool which you can
install with npm.
Run:
$ npm install apidoc http-server -g
Then, get yourself to docs/api and run:
$ apidoc && http-server doc
This command will build the documentation and run a http-server
in the
compiled source folder. You can now visit http://localhost:8080
in your
browser and see the documentation. The doc
folder is ignored by our
.gitignore
, so don't worry about it.
Before finishing, you will want to test the documentation via a Docker
build. You can do this by running:
$ docker-compose build
$ docker-compose run docs apidoc -i docs/api -o build/apidocs
$ docker-compose up
You can now, again, visit http://localhost:8010
and see the documentation
that docker
has built.
The apidocjs version documentation summarises the general concepts. The version which you see on the top-right part of the beginning of the documentation is controlled by the version which is set in the apidoc.json.
It is important to keep a
@apiVersion
in each code block.
All code blocks will declare their version which should match the version set in apidoc.json
. When we do version upgrades, a
search-replace-all
will need to be done for the version in the following locations:
apidoc.json
- all
*.py
source files _apidoc.py
(where we store our inherited blocks)
When a semantic major, minor or patch occurs, we will want to:
- Upgrade our version in the correct files
- Preserve our
API
history
Preserving API
history is extremely important for consumers of the API
documentation. It can be extremely hard to keep up
with API
changes, especially when things move fast. In order to stop this problem, we will preserve all versions of our API
source files in the versioning/
folder.
A full example follows.
Say, for example, our current version is 1.0.0
and we decide to upgrade to 1.1.0
, we do the following:
-
Backup:
- Create a new folder in
versioninig/
with the name of the current version- In this example, we would do:
mkdir versioning/1.0.0
- In this example, we would do:
- Copy existing
*.py
, and_apidoc.json
source files intoversioning/1.0.0
- Create a new folder in
-
Upgrade:
- Upgrade the version from
1.0.0
inapidoc.json
, to1.1.0
- Upgrade the version from
1.0.0
in the source files (*.py
), to1.1.0
- Upgrade the version from
1.0.0
in_apidoc.py
, to1.1.0
- Upgrade the version from
apidocjs
will detect a lesser version of each source file in the directory structure (versioning/
) and will provide a diff when
an API
consumer uses the Compare with all predecessor
or when they directly choose a version. The new version will be
shown for all code blocks and the documentation header.
This is a template that can be used when starting a new top level documentation file.
"""
@api
@apiVersion
@apiName
@apiGroup
@apiDescription
@apiUse
@apiParam
@apiParam
@apiParam
@apiParamExample {json} Request example
@apiSuccess
@apiSuccessExample {json} Non-paginated result example
@apiExample {curl} curl
@apiExample {javascript} javascript
@apiExample {python} python
@apiUse NoAuthenticationCredentials
@apiUse NoAuthenticationCredentialsExample
@apiUse HTTPMethodNotAllowed
@apiUse HTTPMethodNotAllowedExample
"""