Skip to content

Commit

Permalink
Fixes #16852: Add openapi 11 version of the API doc
Browse files Browse the repository at this point in the history
  • Loading branch information
amousset committed Mar 4, 2020
1 parent f4fd80e commit f8c3d3b
Show file tree
Hide file tree
Showing 178 changed files with 6,770 additions and 0 deletions.
2 changes: 2 additions & 0 deletions api-doc/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/build
/target
14 changes: 14 additions & 0 deletions api-doc/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
API:=webapp relay

all: $(API)

$(API): clean
# Prepare all sources in build/ dir
mkdir -p build target/$@
cp -r ../$@/sources/api-doc build/$@
mkdir -p build/$@/assets
cp -r assets/. build/$@/assets
./build.py $@ build target

clean:
rm -rf build target
33 changes: 33 additions & 0 deletions api-doc/README.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
= API documentation

== Usage (openapi/redoc)

Building the doc requires installing:

```
npm install -g redoc-cli @redocly/openapi-cli
```

* `openapi-cli` builds a single openapi file from the sources
* `redoc-cli` produces the HTML output from the openapi file

Then run:

```
make
```

And the resulting files will be in `target/`.

== Sources

The sources are in `{component}/sources/api-doc`. The main file is `openapi.src.yml`.
It is then read and modified by the build process to add the documentation
from the markdown file in `info/description`.

Each Rudder branch contains the sources of the docs for the APIs introduced in
its version.

If a Rudder branch introduced several version, the latest one should be named
`openapi.src.yml`, and previous ones `openapi-VERSION.src.yml`
(to allow easier upmerge of changes).
Binary file added api-doc/assets/rudder.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
68 changes: 68 additions & 0 deletions api-doc/build.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#!/usr/bin/env python3

# loads a openapi.yml template and adds missing information to produce a valid
# openapi.yml file.
# Then build html docs

import sys
import yaml
import os
import subprocess
import glob
import shutil

# API to build
api = sys.argv[1]
source_dir = sys.argv[2]
target_dir = sys.argv[3]

# source dir
source = "%s/%s" % (source_dir, api)

# Read openapi(-ver).src.yml and read versions inside.
templates = glob.glob(source+"/openapi*.src.yml")

for template in templates:
with open(template, 'r') as content_file:
main = yaml.load(content_file.read(), Loader=yaml.FullLoader)
version = main["info"]["version"]
intro_file = main["info"]["description"]

print("Building version %s from %s" % (version, template))

# Fetch introduction content
with open(source+'/introduction.md', 'r') as content_file:
intro = content_file.read()

# Add external content
main["info"]["description"] = intro

# Dump target in target .yml file
src_openapi_file = template.replace(".src", "")
with open(src_openapi_file, 'w') as file:
documents = yaml.dump(main, file)

target = "%s/%s/%s" % (target_dir, api, version)

# Build final openapi.yml
openapi_file = "%s/openapi.yml" % target
subprocess.call(["openapi", "bundle", src_openapi_file,
"--output", openapi_file])

# Build doc from yaml file (with pre-rendered html)
html_file = "%s/openapi.html" % target
subprocess.call(["redoc-cli", "bundle", openapi_file,
"--output", html_file,
# Don't help google track our users
"--disableGoogleFont",
# The famous Rudder orange
"--options.theme.colors.primary.main='#f08004'",
# Expand success examples by default
"--options.expandResponses='200,'",
# More readable in central column
"--options.pathInMiddlePanel=1",
# Hostname is meaningless as it won't match rudder server
"--options.hideHostname=1"
])

shutil.copytree("%s/assets" % source, "%s/assets" % target)
Binary file added webapp/sources/api-doc/assets/APISettings.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
curl --header "X-API-Token: yourToken" --request GET https://rudder.example.com/rudder/api/latest/changeRequests --data "status=open"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
curl --header "X-API-Token: yourToken" --request GET https://rudder.example.com/rudder/api/latest/changeRequests --data "status=open"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
curl --header "X-API-Token: yourToken" --request DELETE https://rudder.example.com/rudder/api/latest/changeRequests/43
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
curl --header "X-API-Token: yourToken" --request POST https://rudder.example.com/rudder/api/latest/changeRequests/42 --data "name=new Name of change request" -d "description=add a new description"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
curl --header "X-API-Token: yourToken" --request GET 'https://rudder.example.com/rudder/api/latest/compliance?prettify=true'
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
curl --header "X-API-Token: yourToken" --request GET 'https://rudder.example.com/rudder/api/compliance/nodes/root?level=1'
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
curl --header "X-API-Token: yourToken" --request GET 'https://rudder.example.com/rudder/api/compliance/nodes?level=2'
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
curl --header "X-API-Token: yourToken" --request GET 'https://rudder.example.com/rudder/api/latest/compliance/rules/32377fd7-02fd-43d0-aab7-28460a91347b?level=2'
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
curl --header "X-API-Token: yourToken" --request GET 'https://rudder.example.com/rudder/api/latest/compliance/rules?level=2'
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
curl --header "X-API-Token: yourToken" --request GET 'https://rudder.example.com/rudder/api/latest/datasources'
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
curl --header "X-API-Token: yourToken" --request PUT https://rudder.example.com/rudder/api/latest/datasources --header "Content-type: application/json" --data @datasources.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
curl --header "X-API-Token: yourToken" --request DELETE https://rudder.example.com/rudder/api/latest/datasources/my-data-source
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
curl --header "X-API-Token: yourToken" --request GET https://rudder.example.com/rudder/api/latest/datasources/my-data-source
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
curl --header "X-API-Token: yourToken" --request POST https://rudder.example.com/rudder/api/latest/datasources/reload/datasourceId
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
curl --header "X-API-Token: yourToken" --request POST https://rudder.example.com/rudder/api/latest/nodes/nodeId/fetchData/datasourceId
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
curl --header "X-API-Token: yourToken" --request POST https://rudder.example.com/rudder/api/latest/nodes/17dadf50-6056-4c8b-a935-6b97d14b89a7/fetchData
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
curl --header "X-API-Token: yourToken" --request POST https://rudder.example.com/rudder/api/latest/datasources/reload
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
cat disable-datasource-1.json.json
{
"description": "This data source is temporarly no more used and so disabled",
"enabled": false
}

curl --header "X-API-Token: yourToken" --request POST https://rudder.example.com/rudder/api/latest/datasources/my-data-source --header "Content-type: application/json" --data @disable-datasource-1.json.json
1 change: 1 addition & 0 deletions webapp/sources/api-doc/code_samples/curl/directives/all.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
curl --header "X-API-Token: yourToken" --request GET https://rudder.example.com/rudder/api/latest/directives
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
curl --header "X-API-Token: yourToken" --request POST https://rudder.example.com/rudder/api/latest/directives/17dadf50-6056-4c8b-a935-6b97d14b89a7/check --data "displayName=Name of new directive"
47 changes: 47 additions & 0 deletions webapp/sources/api-doc/code_samples/curl/directives/create.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
directives.json:

{
"id": "cf2a6c72-18ae-4f82-a12c-0b887792db41",
"displayName": "Example Directive",
"shortDescription": "This in an example Directive to use in Rudder api documentation",
"longDescription": "",
"techniqueName": "genericVariableDefinition",
"techniqueVersion": "2.0",
"tags": {
"env" : "production",
"country" : "FR"
},
"parameters": {
"section": {
"name": "sections",
"sections": [
{
"section": {
"name": "Variable definition",
"vars": [
{
"var": {
"name": "GENERIC_VARIABLE_CONTENT",
"value": "new variable content"
}
},
{
"var": {
"name": "GENERIC_VARIABLE_NAME",
"value": "new_variable"
}
}
]
}
}
]
}
},
"priority": 3,
"enabled": true,
"system": false,
"policyMode": "default"
}

curl --header "X-API-Token: yourToken" --request PUT https://rudder.example.com/rudder/api/latest/directives --header "Content-type: application/json" --data @directive.json

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
curl --header "X-API-Token: yourToken" --request DELETE https://rudder.example.com/rudder/api/latest/directives/17dadf50-6056-4c8b-a935-6b97d14b89a7
1 change: 1 addition & 0 deletions webapp/sources/api-doc/code_samples/curl/directives/get.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
curl --header "X-API-Token: yourToken" --request GET https://rudder.example.com/rudder/api/latest/directives/17dadf50-6056-4c8b-a935-6b97d14b89a7
33 changes: 33 additions & 0 deletions webapp/sources/api-doc/code_samples/curl/directives/update.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
directive.json:
{
"longDescription": "Add a loooooooooooong description",
"parameters": {
"section": {
"name": "sections",
"sections": [
{
"section": {
"name": "Variable definition",
"vars": [
{
"var": {
"name": "GENERIC_VARIABLE_CONTENT",
"value": "Change Variable Content"
}
},
{
"var": {
"name": "GENERIC_VARIABLE_NAME",
"value": "new_variable"
}
}
]
}
}
]
}
},
"priority": 5
}

curl --header "X-API-Token: yourToken" --request POST https://rudder.example.com/rudder/api/latest/directives/cf2a6c72-18ae-4f82-a12c-0b887792db41 --header "Content-type: application/json" --data @directive.json
1 change: 1 addition & 0 deletions webapp/sources/api-doc/code_samples/curl/groups/all.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
curl --header "X-API-Token: yourToken" --request GET https://rudder.example.com/rudder/api/latest/groups
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
curl --header "X-API-Token: yourToken" --request DELETE 'https://rudder.example.com/rudder/api/latest/groups/categories/4306143d-eabf-4478-b7b1-1616f4aa02b5'
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
curl --header "X-API-Token: yourToken" --request PUT 'https://rudder.example.com/rudder/api/latest/groups/categories' --data "name=new category name" -d "parent=4306143d-eabf-4478-b7b1-1616f4aa02b5" -d "description=A new category created via API'
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
curl --header "X-API-Token: yourToken" --request POST 'https://rudder.example.com/rudder/api/latest/groups/categories/4306143d-eabf-4478-b7b1-1616f4aa02b5' --data "name=new category name"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
curl --header "X-API-Token: yourToken" --request GET 'https://rudder.example.com/rudder/api/latest/groups/categories/4306143d-eabf-4478-b7b1-1616f4aa02b5'
18 changes: 18 additions & 0 deletions webapp/sources/api-doc/code_samples/curl/groups/create.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
groups.json:
{
"category": "c355f46e-11b0-4c7a-aedd-6a5f3b0303b6",
"displayName": "Example group",
"description": "This is an example Group to use in Rudder api documentation",
"query":
{"select":"node","composition":"Or","where":
[
{"objectType":"node","attribute":"nodeId","comparator":"eq","value":"1ae6ccfe-00ba-44c0-b1aa-362d2f386032"},
{"objectType":"node","attribute":"nodeId","comparator":"eq","value":"e4a80fd8-373e-45fc-ad94-2ae618be32e3"}
]
},
"dynamic": true,
"enabled": true
}

curl --header "X-API-Token: yourToken" --request PUT https://rudder.example.com/rudder/api/latest/groups --header "Content-Type: application/json" --data @group.json

1 change: 1 addition & 0 deletions webapp/sources/api-doc/code_samples/curl/groups/delete.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
curl --header "X-API-Token: yourToken" --request DELETE 'https://rudder.example.com/rudder/api/latest/groups/17dadf50-6056-4c8b-a935-6b97d14b89a7'
1 change: 1 addition & 0 deletions webapp/sources/api-doc/code_samples/curl/groups/id.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
curl --header "X-API-Token: yourToken" --request GET 'https://rudder.example.com/rudder/api/latest/groups/17dadf50-6056-4c8b-a935-6b97d14b89a7'
1 change: 1 addition & 0 deletions webapp/sources/api-doc/code_samples/curl/groups/reload.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
curl --header "X-API-Token: yourToken" --request POST 'https://rudder.example.com/rudder/api/latest/groups/17dadf50-6056-4c8b-a935-6b97d14b89a7/reload'
1 change: 1 addition & 0 deletions webapp/sources/api-doc/code_samples/curl/groups/tree.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
curl --header "X-API-Token: yourToken" --request GET https://rudder.example.com/rudder/api/latest/groups/tree
1 change: 1 addition & 0 deletions webapp/sources/api-doc/code_samples/curl/groups/update.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
curl --header "X-API-Token: yourToken" --request POST 'https://rudder.example.com/rudder/api/latest/groups/17dadf50-6056-4c8b-a935-6b97d14b89a7' --data "displayName=New name of group"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
curl --header "X-API-Token: yourToken" https://rudder.example.com/rudder/api/latest/
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
curl --header "X-API-Token: yourToken" --request POST 'https://rudder.example.com/rudder/api/latest/inventories/watcher/restart'
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
curl --header "X-API-Token: yourToken" --request POST 'https://rudder.example.com/rudder/api/latest/inventories/watcher/start'
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
curl --header "X-API-Token: yourToken" --request POST 'https://rudder.example.com/rudder/api/latest/inventories/watcher/stop'
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
curl --request POST --header "X-API-Token: yourToken" https://rudder.example.com/rudder/api/latest/inventories/upload -F "file=@inventory-file" -F "signature=@signature-file"
1 change: 1 addition & 0 deletions webapp/sources/api-doc/code_samples/curl/nodes/all.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
curl --header "X-API-Token: yourToken" 'https://rudder.example.com/rudder/api/latest/nodes?where=\[\{"objectType":"node","attribute":"OS","comparator":"eq","value":"Linux"\},\{"objectType":"node","attribute":"nodeHostname","comparator":"regex","value":"node1.*"\}\]'
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
curl --header "X-API-Token: yourToken" --request POST --header "Content-Type: application/json" https://rudder.example.com/rudder/api/latest/nodes/applyPolicy
1 change: 1 addition & 0 deletions webapp/sources/api-doc/code_samples/curl/nodes/apply-id.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
curl --header "X-API-Token: yourToken" --request POST --header "Content-Type: application/json" https://rudder.example.com/rudder/api/latest/nodes/root/applyPolicy
1 change: 1 addition & 0 deletions webapp/sources/api-doc/code_samples/curl/nodes/delete.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
curl --header "X-API-Token: yourToken" --request DELETE https://rudder.example.com/rudder/api/latest/nodes/17dadf50-6056-4c8b-a935-6b97d14b89a7
16 changes: 16 additions & 0 deletions webapp/sources/api-doc/code_samples/curl/nodes/id-update.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Given the "data.json" JSON file with content:
{ "properties": [
{ "name": "env_type" , "value": "production" },
{ "name": "shell" , "value": "/bin/sh" },
{ "name": "utf-8 poetry", "value": "ᚠᛇᚻ᛫ᛒᛦᚦ᛫ᚠᚱᚩᚠᚢᚱ᛫ᚠᛁᚱᚪ᛫ᚷᛖᚻᚹᛦᛚᚳᚢᛗ" }
]
, "policyMode" : "audit"
}
# Setting properties from "data.json" and policy mode to audit:
curl --header "X-API-Token: yourToken" --request POST --header "Content-Type: application/json" https://rudder.example.com/rudder/api/latest/nodes/17dadf50-6056-4c8b-a935-6b97d14b89a7 --data @properties.json

# Removing the key "utf-8 poetry" from the command line and updating the "env_type" one
curl --header "X-API-Token: yourToken" --request POST --header "Content-Type: application/json" https://rudder.example.com/rudder/api/latest/nodes/17dadf50-6056-4c8b-a935-6b97d14b89a7 --data '{ "properties": [{ "name":"utf-8 poetry", "value":""}, {"name":"env_type", "value":"deprovisioned"}] }'

# Removing the key "env_type" and changing "shell" and use default policy mode
curl --header "X-API-Token: yourToken" --request POST https://rudder.example.com/rudder/api/latest/nodes/17dadf50-6056-4c8b-a935-6b97d14b89a7 --data "properties=shell=/bin/false" -d "properties=env_type=" -d "policyMode=default"
1 change: 1 addition & 0 deletions webapp/sources/api-doc/code_samples/curl/nodes/id.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
curl --header "X-API-Token: yourToken" https://rudder.example.com/rudder/api/latest/nodes/17dadf50-6056-4c8b-a935-6b97d14b89a7\?include=full
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
curl --header "X-API-Token: yourToken" --request POST https://rudder.example.com/rudder/api/latest/nodes/pending/17dadf50-6056-4c8b-a935-6b97d14b89a7 --data "status=accepted"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
curl --header "X-API-Token: yourToken" --header "Content-Type: application/json" --request PUT https://rudder.example.com/rudder/api/latest/parameters --data @JSON-file-name
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
curl --header "X-API-Token: yourToken" --request DELETE https://rudder.example.com/rudder/api/latest/parameters/ParameterId
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
curl --header "X-API-Token: yourToken" https://rudder.example.com/rudder/api/latest/parameters/ParameterId
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
curl --header "X-API-Token: yourToken" https://rudder.example.com/rudder/api/latest/parameters
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
curl --header "X-API-Token: yourToken" --request POST https://rudder.example.com/rudder/api/latest/parameters/ParameterId --data "value=### Edited by Rudder ###"
1 change: 1 addition & 0 deletions webapp/sources/api-doc/code_samples/curl/rules/all.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
curl --header "X-API-Token: yourToken" --request GET 'https://rudder.example.com/rudder/api/latest/rules'
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
curl --header "X-API-Token: yourToken" --request DELETE 'https://rudder.example.com/rudder/api/latest/rules/categories/4306143d-eabf-4478-b7b1-1616f4aa02b5?prettify=true'
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
curl --header "X-API-Token: yourToken" --request POST 'https://rudder.example.com/rudder/api/latest/rules/categories' --data "name=new category" -d "parent=4306143d-eabf-4478-b7b1-1616f4aa02b5" -d "description=A new category created via API'
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
curl --header "X-API-Token: yourToken" --request POST 'https://rudder.example.com/rudder/api/latest/rules/categories/4306143d-eabf-4478-b7b1-1616f4aa02b5?prettify=true' --data "name=new category name"
Loading

0 comments on commit f8c3d3b

Please sign in to comment.