Skip to content

Commit

Permalink
feat: generate docs from openapi with a script (#1235)
Browse files Browse the repository at this point in the history
Co-authored-by: Shahar Glazner <[email protected]>
  • Loading branch information
onurio and shahargl authored Jun 13, 2024
1 parent b86c6b9 commit 1f8da48
Show file tree
Hide file tree
Showing 53 changed files with 222 additions and 1 deletion.
3 changes: 3 additions & 0 deletions docs/api-ref/alerts/assign-alert.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
openapi: post /alerts/{fingerprint}/assign/{last_received}
---
3 changes: 3 additions & 0 deletions docs/api-ref/alerts/delete-alert.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
openapi: delete /alerts
---
3 changes: 3 additions & 0 deletions docs/api-ref/alerts/enrich-alert.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
openapi: post /alerts/enrich
---
3 changes: 3 additions & 0 deletions docs/api-ref/alerts/get-alert-history.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
openapi: get /alerts/{fingerprint}/history
---
3 changes: 3 additions & 0 deletions docs/api-ref/alerts/get-alert.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
openapi: get /alerts/{fingerprint}
---
3 changes: 3 additions & 0 deletions docs/api-ref/alerts/get-all-alerts.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
openapi: get /alerts
---
3 changes: 3 additions & 0 deletions docs/api-ref/alerts/receive-generic-event.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
openapi: post /alerts/event
---
3 changes: 3 additions & 0 deletions docs/api-ref/alerts/search-alerts.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
openapi: post /alerts/search
---
3 changes: 3 additions & 0 deletions docs/api-ref/enrichment/create-extraction-rule.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
openapi: post /extraction
---
3 changes: 3 additions & 0 deletions docs/api-ref/enrichment/create-rule.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
openapi: post /mapping
---
3 changes: 3 additions & 0 deletions docs/api-ref/enrichment/delete-extraction-rule.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
openapi: delete /extraction/{rule_id}
---
3 changes: 3 additions & 0 deletions docs/api-ref/enrichment/delete-rule.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
openapi: delete /mapping/{rule_id}
---
3 changes: 3 additions & 0 deletions docs/api-ref/enrichment/get-extraction-rules.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
openapi: get /extraction
---
3 changes: 3 additions & 0 deletions docs/api-ref/enrichment/get-rules.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
openapi: get /mapping
---
3 changes: 3 additions & 0 deletions docs/api-ref/enrichment/update-extraction-rule.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
openapi: put /extraction/{rule_id}
---
3 changes: 3 additions & 0 deletions docs/api-ref/enrichment/update-rule.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
openapi: put /mapping
---
3 changes: 3 additions & 0 deletions docs/api-ref/groups/get-groups.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
openapi: get /groups/
---
3 changes: 3 additions & 0 deletions docs/api-ref/preset/create-preset.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
openapi: post /preset
---
3 changes: 3 additions & 0 deletions docs/api-ref/preset/delete-preset.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
openapi: delete /preset/{uuid}
---
3 changes: 3 additions & 0 deletions docs/api-ref/preset/get-presets.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
openapi: get /preset
---
3 changes: 3 additions & 0 deletions docs/api-ref/preset/update-preset.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
openapi: put /preset/{uuid}
---
3 changes: 3 additions & 0 deletions docs/api-ref/providers/get-installed-providers.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
openapi: get /providers/export
---
3 changes: 3 additions & 0 deletions docs/api-ref/providers/install-provider-oauth2.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
openapi: post /providers/install/oauth2/{provider_type}
---
3 changes: 3 additions & 0 deletions docs/api-ref/providers/invoke-provider-method.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
openapi: post /providers/{provider_id}/invoke/{method}
---
3 changes: 3 additions & 0 deletions docs/api-ref/providers/update-provider.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
openapi: put /providers/{provider_id}
---
3 changes: 3 additions & 0 deletions docs/api-ref/providers/validate-provider-scopes.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
openapi: post /providers/{provider_id}/scopes
---
3 changes: 3 additions & 0 deletions docs/api-ref/pusher/pusher-authentication.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
openapi: post /pusher/auth
---
3 changes: 3 additions & 0 deletions docs/api-ref/rules/create-rule.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
openapi: post /rules
---
3 changes: 3 additions & 0 deletions docs/api-ref/rules/delete-rule.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
openapi: delete /rules/{rule_id}
---
3 changes: 3 additions & 0 deletions docs/api-ref/rules/get-rules.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
openapi: get /rules
---
3 changes: 3 additions & 0 deletions docs/api-ref/rules/update-rule.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
openapi: put /rules/{rule_id}
---
3 changes: 3 additions & 0 deletions docs/api-ref/settings/create-key.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
openapi: post /settings/apikey
---
3 changes: 3 additions & 0 deletions docs/api-ref/settings/create-user.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
openapi: post /settings/users
---
3 changes: 3 additions & 0 deletions docs/api-ref/settings/delete-api-key.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
openapi: delete /settings/apikey/{keyId}
---
3 changes: 3 additions & 0 deletions docs/api-ref/settings/delete-smtp-settings.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
openapi: delete /settings/smtp
---
3 changes: 3 additions & 0 deletions docs/api-ref/settings/delete-user.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
openapi: delete /settings/users/{user_email}
---
3 changes: 3 additions & 0 deletions docs/api-ref/settings/get-keys.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
openapi: get /settings/apikeys
---
3 changes: 3 additions & 0 deletions docs/api-ref/settings/get-smtp-settings.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
openapi: get /settings/smtp
---
3 changes: 3 additions & 0 deletions docs/api-ref/settings/get-users.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
openapi: get /settings/users
---
3 changes: 3 additions & 0 deletions docs/api-ref/settings/test-smtp-settings.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
openapi: post /settings/smtp/test
---
3 changes: 3 additions & 0 deletions docs/api-ref/settings/update-api-key.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
openapi: put /settings/apikey
---
3 changes: 3 additions & 0 deletions docs/api-ref/settings/update-smtp-settings.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
openapi: post /settings/smtp
---
3 changes: 3 additions & 0 deletions docs/api-ref/status/status.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
openapi: get /status
---
3 changes: 3 additions & 0 deletions docs/api-ref/users/delete-user.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
openapi: delete /users/{user_email}
---
3 changes: 3 additions & 0 deletions docs/api-ref/whoami/get-tenant-id.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
openapi: get /whoami
---
3 changes: 3 additions & 0 deletions docs/api-ref/workflows/get-raw-workflow-by-id.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
openapi: get /workflows/{workflow_id}/raw
---
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
openapi: get /workflows/executions
---
3 changes: 3 additions & 0 deletions docs/api-ref/workflows/get-workflow-executions.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
openapi: get /workflows/executions/list
---
3 changes: 3 additions & 0 deletions docs/api-ref/workflows/run-workflow-from-definition.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
openapi: post /workflows/test
---
3 changes: 3 additions & 0 deletions docs/api-ref/workflows/update-workflow-by-id.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
openapi: put /workflows/{workflow_id}
---
8 changes: 8 additions & 0 deletions docs/generate_readme_from_openapijson.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

#!/bin/bash

# Before running this script, make sure you have update the openapi.json from the backend, (/docs route)

python3 openapi_converter.py --source ./openapi.json --dest ./openapi_converted.json
npx @mintlify/scraping@latest openapi-file ./openapi_converted.json -o ./api-ref
rm ./openapi_converted.json
2 changes: 1 addition & 1 deletion docs/openapi.json

Large diffs are not rendered by default.

63 changes: 63 additions & 0 deletions docs/openapi_converter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
from argparse import ArgumentParser
import typing as t
import json
Json = dict[str | t.Literal["anyOf", "type"], "Json"] | list["Json"] | str | bool


## Reference: https://github.com/tiangolo/fastapi/discussions/9789
def convert_3_dot_1_to_3_dot_0(json: dict[str, Json]):
"""Will attempt to convert version 3.1.0 of some openAPI json into 3.0.2

Usage:

>>> from pprint import pprint
>>> json = {
... "some_irrelevant_keys": {...},
... "nested_dict": {"nested_key": {"anyOf": [{"type": "string"}, {"type": "null"}]}},
... "examples": [{...}, {...}]
... }
>>> convert_3_dot_1_to_3_dot_0(json)
>>> pprint(json)
{'example': {Ellipsis},
'nested_dict': {'nested_key': {'anyOf': [{'type': 'string'}],
'nullable': True}},
'openapi': '3.0.2',
'some_irrelevant_keys': {Ellipsis}}
"""
json["openapi"] = "3.0.2"

def inner(yaml_dict: Json):
if isinstance(yaml_dict, dict):
if "anyOf" in yaml_dict and isinstance((anyOf := yaml_dict["anyOf"]), list):
for i, item in enumerate(anyOf):
if isinstance(item, dict) and item.get("type") == "null":
anyOf.pop(i)
yaml_dict["nullable"] = True
if "examples" in yaml_dict:
examples = yaml_dict["examples"]
del yaml_dict["examples"]
if isinstance(examples, list) and len(examples):
yaml_dict["example"] = examples[0]
for value in yaml_dict.values():
inner(value)
elif isinstance(yaml_dict, list):
for item in yaml_dict:
inner(item)

inner(json)
return json

if __name__ == "__main__":

parser = ArgumentParser(description="Script for converting openapi version 3.1.0 to 3.0.2")
parser.add_argument("-s", "--source", help="The path to openapi.json")
parser.add_argument("-d", "--dest", help="The path to output")

args = parser.parse_args()

with open(args.source, "r") as fd:
content = json.load(fd)

output = json.dumps(convert_3_dot_1_to_3_dot_0(content))
with open(args.dest, "wt") as wt:
wt.write(output)

0 comments on commit 1f8da48

Please sign in to comment.