-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
31 lines (18 loc) · 844 Bytes
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# REST API of the SQL schema generator
from fastapi import FastAPI
from sql_schema_generator import open_yaml, yaml_to_postgresql_schema
app = FastAPI()
@app.post("/sql-schema/{subject}/{datamodel}")
async def generate_schema(subject: str, datamodel:str):
yaml_source = f"https://raw.githubusercontent.com/smart-data-models/dataModel.{subject}/master/{datamodel}/model.yaml"
try:
schema = open_yaml(yaml_source)
sql_schema = yaml_to_postgresql_schema(schema)
return {"success": True, "sql_schema": sql_schema}
except Exception as e:
return {"success": False, "error": str(e)}
if __name__ == "__main__":
import uvicorn
# Only run this way in testing mode
uvicorn.run(app, host="0.0.0.0", port=8000)
print("To test the API, navigate to: http://localhost:8000/docs")