Skip to content

Commit

Permalink
Merge pull request canonical#149 from keirthana/automate-api-reference
Browse files Browse the repository at this point in the history
Automate loading of AMS and Gateway API spec from swagger
  • Loading branch information
keirthana authored Sep 20, 2024
2 parents 469c536 + 436427d commit 8255967
Show file tree
Hide file tree
Showing 12 changed files with 6,750 additions and 12 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@ __pycache__
.vscode/
.sphinx/styles/*
.sphinx/vale.ini
.sphinx/deps/
.sphinx/_static/swagger-ui/
1 change: 1 addition & 0 deletions .sphinx/_extra/ams-api.yaml
1 change: 1 addition & 0 deletions .sphinx/_extra/gateway-api.yaml
15 changes: 15 additions & 0 deletions .sphinx/_static/swagger-override.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 38 additions & 0 deletions custom_conf.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import datetime
import os
import subprocess


# Custom configuration for the Sphinx documentation builder.
# All configuration specific to your project should be done in this file.
Expand Down Expand Up @@ -216,3 +219,38 @@
.. role:: center
:class: align-center
'''

## Generate dynamic configuration using scripts
# Inject AMS configuration valuues and Node configuration values from the swagger
# specification hosted on Github.
def generate_ams_configuration():
from scripts.ams_configuration import get_swagger_from_url, parse_swagger

with open("scripts/requirements.txt", "r") as f:
for req in f.readlines():
custom_required_modules.append(req)
ams_configuration_file = "reference/ams-configuration.md"
parse_swagger(get_swagger_from_url(), ams_configuration_file)

## The following code is to automatically load the API from swagger into documentation.

# Path to copy the YAML files during build
html_extra_path = ['.sphinx/_extra']

# The swagger-ui repository is required to be able to render the swagger YAML
# file as browseable API documentation. The below variable specifies which
# git repository to fetch it from.
swagger_ui_repository = "https://github.com/swagger-api/swagger-ui"

# Download and link swagger-ui files
if not os.path.isdir('.sphinx/deps/swagger-ui'):
subprocess.check_call(["git", "clone", "--depth=1", swagger_ui_repository, ".sphinx/deps/swagger-ui"])

os.makedirs('.sphinx/_static/swagger-ui/', exist_ok=True)

if not os.path.islink('.sphinx/_static/swagger-ui/swagger-ui-bundle.js'):
os.symlink('../../deps/swagger-ui/dist/swagger-ui-bundle.js', '.sphinx/_static/swagger-ui/swagger-ui-bundle.js')
if not os.path.islink('.sphinx/_static/swagger-ui/swagger-ui-standalone-preset.js'):
os.symlink('../../deps/swagger-ui/dist/swagger-ui-standalone-preset.js', '.sphinx/_static/swagger-ui/swagger-ui-standalone-preset.js')
if not os.path.islink('.sphinx/_static/swagger-ui/swagger-ui.css'):
os.symlink('../../deps/swagger-ui/dist/swagger-ui.css', '.sphinx/_static/swagger-ui/swagger-ui.css')
29 changes: 29 additions & 0 deletions reference/api-reference/ams-api.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# AMS HTTP API

<link rel="stylesheet" type="text/css" href="../../../_static/swagger-ui/swagger-ui.css" ></link>
<link rel="stylesheet" type="text/css" href="../../../_static/swagger-override.css" ></link>
<div id="swagger-ui"></div>

<script src="../../../_static/swagger-ui/swagger-ui-bundle.js" charset="UTF-8"> </script>
<script src="../../../_static/swagger-ui/swagger-ui-standalone-preset.js" charset="UTF-8"> </script>
<script>
window.onload = function() {
// Begin Swagger UI call region
const ui = SwaggerUIBundle({
url: window.location.pathname +"../../../ams-api.yaml",
dom_id: '#swagger-ui',
deepLinking: true,
presets: [
SwaggerUIBundle.presets.apis,
SwaggerUIStandalonePreset
],
plugins: [],
validatorUrl: "none",
defaultModelsExpandDepth: -1,
supportedSubmitMethods: []
})
// End Swagger UI call region

window.ui = ui
}
</script>
Loading

0 comments on commit 8255967

Please sign in to comment.