-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
doc: automate ReST API documentation
The django extension drf_spectacular allows to generate OpenAPI schema. Via redoc, this schema can be rendered into a detailed html api documentation. This api documentation is referenced by Sphinx to be available on the GitHub pages documentation. Signed-off-by: Jonas Remmert <jremmert@gmx.net>
- Loading branch information
Showing
12 changed files
with
73 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Internal ReST APIs | ||
================== | ||
|
||
.. The following text is only a placeholder in case the api can not be | ||
generated (e.g. for the pdf version) | ||
The API Documentation is available at https://jonas-rem.github.io/lwm2m_server. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,4 +30,5 @@ Table of Contents | |
:maxdepth: 1 | ||
|
||
documentation | ||
api | ||
weblog |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Empty file.
32 changes: 32 additions & 0 deletions
32
server/django/sensordata/management/commands/generate_openapi.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
from django.core.management.base import BaseCommand | ||
from drf_spectacular.generators import SchemaGenerator | ||
import yaml | ||
import os | ||
|
||
class Command(BaseCommand): | ||
help = 'Generates the OpenAPI schema' | ||
|
||
def add_arguments(self, parser): | ||
parser.add_argument( | ||
'-o', | ||
type=str, | ||
help='File path where the OpenAPI schema should be saved', | ||
default='openapi-schema.yaml' | ||
) | ||
|
||
def handle(self, *args, **options): | ||
output_path = options['o'] | ||
|
||
# Ensure the directory exists | ||
os.makedirs(os.path.dirname(output_path), exist_ok=True) | ||
|
||
# Generate the OpenAPI schema | ||
generator = SchemaGenerator() | ||
schema = generator.get_schema(request=None, public=True) | ||
schema_yaml = yaml.dump(schema, default_flow_style=False) | ||
|
||
# Write the schema to the specified file | ||
with open(output_path, 'w') as file: | ||
file.write(schema_yaml) | ||
|
||
self.stdout.write(self.style.SUCCESS(f'Exported OpenAPI schema to {output_path}')) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,6 @@ | |
TEST_PAYLOAD = [ | ||
{ | ||
"ep": "qemu_x86", | ||
"res": "3", | ||
"val": { | ||
"instances": [ | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters