Skip to content

Commit

Permalink
Automate loading of AMS and Gateway API spec from swagger
Browse files Browse the repository at this point in the history
  • Loading branch information
keirthana committed Sep 18, 2024
1 parent 58f8aef commit 297c244
Show file tree
Hide file tree
Showing 12 changed files with 6,769 additions and 201 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.

33 changes: 33 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 @@ -213,6 +216,7 @@
rst_prolog = """
.. role:: center
:class: align-center
"""


Expand All @@ -227,3 +231,32 @@ def generate_ams_configuration():
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 variables specify which
# git repository to fetch it from and the revision in that repository to use.
# This will be helpful to protect against the documentation breaking due to
# backwards-incompatible changes in the swagger-ui repository. However, this
# means that updating to newer revisions of this repository needs to be done
# manually.
swagger_ui_repository = "https://github.com/swagger-api/swagger-ui"
swagger_ui_revision = "d1111837388816f0b68f27a1a0d6a6f37841b697"

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

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')
200 changes: 0 additions & 200 deletions reference/api-reference.md

This file was deleted.

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 @@
# Main API specification

<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 297c244

Please sign in to comment.