mirror of
https://github.com/ansible/awx.git
synced 2026-02-16 18:50:04 -03:30
Create AWX docsite with RST content (#14328)
Co-authored-by: Thanhnguyet Vo <tvo@ansible.com> Co-authored-by: TVo <thavo@redhat.com>
This commit is contained in:
50
docs/docsite/rst/rest_api/_swagger/swagger.py
Normal file
50
docs/docsite/rst/rest_api/_swagger/swagger.py
Normal file
@@ -0,0 +1,50 @@
|
||||
import io
|
||||
import json
|
||||
import os
|
||||
|
||||
import jinja2
|
||||
import pkg_resources
|
||||
import yaml
|
||||
|
||||
from sphinx.util.osutil import copyfile, ensuredir
|
||||
|
||||
here = os.path.abspath(os.path.dirname(__file__))
|
||||
with io.open(os.path.join(here, 'swagger.json'), 'r', encoding='utf-8') as f:
|
||||
spec = json.load(f)
|
||||
with io.open(os.path.join(here, 'tags.yml'), 'r', encoding='utf-8') as f:
|
||||
tags = yaml.load(f.read(), Loader=yaml.FullLoader)
|
||||
|
||||
|
||||
def add_spec(app, pagename, templatename, context, doctree):
|
||||
if pagename == 'rest_api/api_ref':
|
||||
# Write tags in the order we want them sorted
|
||||
for category in tags.get('categories', []):
|
||||
tag = {'name': category['name']}
|
||||
if 'description' in category:
|
||||
tag['description'] = category['description']
|
||||
spec.setdefault('tags', []).append(tag)
|
||||
|
||||
context['body'] = context['body'].replace('{{SPEC}}', json.dumps(spec))
|
||||
|
||||
|
||||
def assets(app, exception):
|
||||
for asset in os.listdir(here):
|
||||
if asset == '__pycache__':
|
||||
continue
|
||||
|
||||
_, extension = os.path.splitext(asset)
|
||||
if extension in ('py', 'pyc'):
|
||||
continue
|
||||
if not exception and os.path.exists(
|
||||
os.path.join(app.outdir, '_static')
|
||||
):
|
||||
copyfile(
|
||||
os.path.join(here, asset),
|
||||
os.path.join(app.outdir, '_static', asset))
|
||||
|
||||
|
||||
def setup(app):
|
||||
app.add_config_value('swagger', [], 'html')
|
||||
app.connect('html-page-context', add_spec)
|
||||
app.connect('build-finished', assets)
|
||||
return {'version': 1.0, 'parallel_read_safe': True}
|
||||
Reference in New Issue
Block a user