Skip to content

Commit b1695fe

Browse files
committed
add instructions for generating Swagger/OpenAPI docs
1 parent 8b97603 commit b1695fe

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

CONTRIBUTING.md

+15
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ Have questions about this document or anything not covered here? Come chat with
2424
* [Start a shell](#start-the-shell)
2525
* [Create a superuser](#create-a-superuser)
2626
* [Load the data](#load-the-data)
27+
* [Building API Documentation](#build-documentation)
2728
* [Accessing the AWX web interface](#accessing-the-awx-web-interface)
2829
* [Purging containers and images](#purging-containers-and-images)
2930
* [What should I work on?](#what-should-i-work-on)
@@ -261,6 +262,20 @@ You can optionally load some demo data. This will create a demo project, invento
261262
> This information will persist in the database running in the `tools_postgres_1` container, until the container is removed. You may periodically need to recreate
262263
this container, and thus the database, if the database schema changes in an upstream commit.
263264

265+
##### Building API Documentation
266+
267+
AWX includes support for building [Swagger/OpenAPI
268+
documentation](https://swagger.io). To build the documentation locally, run:
269+
270+
```bash
271+
(container)/awx_devel$ make swagger
272+
```
273+
274+
This will write a file named `swagger.json` that contains the API specification
275+
in OpenAPI format. A variety of online tools are available for translating
276+
this data into more consumable formats (such as HTML). http://editor.swagger.io
277+
is an example of one such service.
278+
264279
### Accessing the AWX web interface
265280

266281
You can now log into the AWX web interface at [https://localhost:8043](https://localhost:8043), and access the API directly at [https://localhost:8043/api/](https://localhost:8043/api/).

awx/main/tests/docs/test_swagger_generation.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,10 @@ def test_autogen_response_examples(self, swagger_autogen):
152152
content_type, resp, request_data = value
153153
if method in node:
154154
status_code = str(status_code)
155-
node[method].setdefault('produces', []).append(content_type)
155+
if content_type:
156+
produces = node[method].setdefault('produces', [])
157+
if content_type not in produces:
158+
produces.append(content_type)
156159
if request_data and status_code.startswith('2'):
157160
# DRF builds a schema based on the serializer
158161
# fields. This is _pretty good_, but if we
@@ -181,5 +184,5 @@ def test_autogen_response_examples(self, swagger_autogen):
181184
def teardown_class(cls):
182185
with open('swagger.json', 'w') as f:
183186
f.write(force_bytes(
184-
json.dumps(cls.JSON, cls=i18nEncoder, indent=5)
187+
json.dumps(cls.JSON, cls=i18nEncoder)
185188
))

0 commit comments

Comments
 (0)