FastAPI as Orchest service cannot display documentation
astrojuanlu opened this issue · comments
I configured a simple FastAPI application as a service, and cannot display the documentation.
- Image: https://hub.docker.com/r/astrojuanlu/fastapi-helloworld
- Source code: https://github.com/astrojuanlu/fastapi-helloworld
Opening the service URL works ✔️
However, opening either /docs
or /redoc
result in a failure ❌
/docs
(Swagger UI)
Server logs:
INFO: 172.17.0.5:54554 - "GET /docs HTTP/1.1" 200 OK
INFO: 172.17.0.5:55430 - "GET /docs HTTP/1.1" 200 OK
(nothing weird spotted)
JavaScript logs:
Object { name: "YAMLException", reason: "end of the stream or a document separator is expected", mark: {…}, message: "end of the stream or a document separator is expected (13:14)\n\n 10 | <body>\n 11 | <style>/* latin-ext */\n 12 | @font-face {\n 13 | font-family: \"Inter\";\n-------------------^\n 14 | font-style: normal;\n 15 | font-weight: 400;", stack: "i@https://cdn.jsdelivr.net/npm/swagger-ui-dist@4/swagger-ui-bundle.js:2:895328\nue@https://cdn.jsdelivr.net/npm/swagger-ui-dist@4/swagger-ui-bundle.js:2:908467\nce@https://cdn.jsdelivr.net/npm/swagger-ui-dist@4/swagger-ui-bundle.js:2:908501\nSe@https://cdn.jsdelivr.net/npm/swagger-ui-dist@4/swagger-ui-bundle.js:2:923591\nAe@https://cdn.jsdelivr.net/npm/swagger-ui-dist@4/swagger-ui-bundle.js:2:924034\nload@https://cdn.jsdelivr.net/npm/swagger-ui-dist@4/swagger-ui-bundle.js:2:924259\n51228/le/<@https://cdn.jsdelivr.net/npm/swagger-ui-dist@4/swagger-ui-bundle.js:2:128862\n90242/Ee/</</<@https://cdn.jsdelivr.net/npm/swagger-ui-dist@4/swagger-ui-bundle.js:2:236138\n97779/f/<@https://cdn.jsdelivr.net/npm/swagger-ui-dist@4/swagger-ui-bundle.js:2:749436\n77508/u/<@https://cdn.jsdelivr.net/npm/swagger-ui-dist@4/swagger-ui-bundle.js:2:147358\nn@https://cdn.jsdelivr.net/npm/swagger-ui-dist@4/swagger-ui-bundle.js:2:937582\n$/<@https://cdn.jsdelivr.net/npm/swagger-ui-dist@4/swagger-ui-bundle.js:2:941438\n28560/i/updateSpec/<@https://cdn.jsdelivr.net/npm/swagger-ui-dist@4/swagger-ui-bundle.js:2:110189\nn@https://cdn.jsdelivr.net/npm/swagger-ui-dist@4/swagger-ui-bundle.js:2:937582\n$/<@https://cdn.jsdelivr.net/npm/swagger-ui-dist@4/swagger-ui-bundle.js:2:941438\np@https://cdn.jsdelivr.net/npm/swagger-ui-dist@4/swagger-ui-bundle.js:2:71220\n" }
actions.js:68:12
/redoc
(ReDoc)
Server logs:
INFO: 172.17.0.5:56774 - "GET /redoc HTTP/1.1" 200 OK
JavaScript logs:
Error: end of the stream or a document separator is expected in "https://festive-panini-317af3ac.orchestapp.io/openapi.json" (13:14)
d resolve.js:60
parseDocument resolve.js:137
i resolve.js:148
promise callback*4182/resolveDocument/< resolve.js:147
r resolve.js:8
r resolve.js:4
resolveDocument resolve.js:141
bundle bundle.js:41
r bundle.js:8
r bundle.js:4
bundle bundle.js:36
n loadAndBundleSpec.ts:37
e loadAndBundleSpec.ts:15
e loadAndBundleSpec.ts:38
n StoreBuilder.ts:48
Mu StoreBuilder.ts:42
Mu StoreBuilder.ts:52
Mu StoreBuilder.ts:55
Il React
unstable_runWithPriority scheduler.production.min.js:18
React 3
D scheduler.production.min.js:16
onmessage scheduler.production.min.js:12
53 scheduler.production.min.js:12
Webpack 12
react-dom.production.min.js:216:199
Uncaught (in promise) Error: end of the stream or a document separator is expected in "https://festive-panini-317af3ac.orchestapp.io/openapi.json" (13:14)
d resolve.js:60
parseDocument resolve.js:137
i resolve.js:148
promise callback*4182/resolveDocument/< resolve.js:147
r resolve.js:8
r resolve.js:4
resolveDocument resolve.js:141
bundle bundle.js:41
r bundle.js:8
r bundle.js:4
bundle bundle.js:36
n loadAndBundleSpec.ts:37
e loadAndBundleSpec.ts:15
e loadAndBundleSpec.ts:38
n StoreBuilder.ts:48
Mu StoreBuilder.ts:42
Mu StoreBuilder.ts:52
Mu StoreBuilder.ts:55
Il React
unstable_runWithPriority scheduler.production.min.js:18
React 3
D scheduler.production.min.js:16
onmessage scheduler.production.min.js:12
53 scheduler.production.min.js:12
Webpack 12
resolve.js:60:8
This is likely not an Orchest issue but related to path handling and FastAPI prefix path configuration: https://stackoverflow.com/questions/70219200/python-fastapi-base-path-control
Thanks for the pointer @ricklamers. If I understand correctly, this means that, if my service is served under, say,
https://grumpy-panini-aaabbbccc.orchestapp.io/service-fastapi-xxx-yyy-zzz-uuu-www_9999/
Then I'd need to configure FastAPI with
prefix_router = APIRouter(prefix="service-fastapi-xxx-yyy-zzz-uuu-www_9999")
?
The Streamlit example shows how to do this dynamically. Orchest uses templating for this under the hood:
The string $BASE_PATH_PREFIX
will be replaced by the service-fastapi-xxx-yyy-zzz-uuu-www
value (which is dynamic).
So in this case I'd set an environment variable FASTAPI_BASE_PATH=$BASE_PATH_PREFIX_8000
in the UI. (the _8000
part is dependent on which port you choose).
Then in the Python code you can refer to the prefix using:
prefix_router = APIRouter(prefix=os.environ.get("FASTAPI_BASE_PATH"))
We still need to add this to the docs, it's somewhat of an advanced usage pattern of services and not necessary for all container base services (e.g. not for Metabase).
@astrojuanlu can you pretty please add this to the docs?