Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork8.7k
Static swagger#112
Conversation
Codecov Report
@@ Coverage Diff @@## master #112 +/- ##==========================================- Coverage 100% 99.96% -0.04%========================================== Files 124 125 +1 Lines 2987 3019 +32 ==========================================+ Hits 2987 3018 +31- Misses 0 1 +1
Continue to review full report at Codecov.
|
codecovbot commentedMar 26, 2019 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Codecov Report
@@ Coverage Diff @@## master #112 +/- ##====================================== Coverage 100% 100% ====================================== Files 170 175 +5 Lines 4122 4261 +139 ======================================+ Hits 4122 4261 +139
Continue to review full report at Codecov.
|
More tests, hopefully coverage increase
tiangolo commentedMar 29, 2019
First, thanks for your work@euri10 ! I have a couple of concerns: The compiled JS code is almost 1 MB, and at each new Swagger UI version, we would need to update it. And the changes would be huge, as it is not the source code but the "compiled" (transpiled/minified) version. I think one way to solve it could be to add a script for building the package, that pulls the lastest JS version from NPM (or any CDN) and adds it to the dist files. But I'm still not completely sure how to make Flit "bundle" it, and then how to add it/serve it in FastAPI, being a file included as part of the Another option would be to create an additional optional package, that includes those static JS files, and can be installed and used with FastAPI. Let's keep this on hold, I'll investigate what options do we have, and what's the best/most clean way to solve this use case. |
euri10 commentedMar 29, 2019
I'm not sure I understand your concern, I surely miss something :) It's just an option users will have:
If the css / js changes today, you'll update the 2 links in the docs.py file: https://github.com/tiangolo/fastapi/blob/08d849d5c588f9cf14a38ede9e9d4d0b29a6d9c2/fastapi/openapi/docs.py#L10 Should that option be implemented you'll change them in the spot they're defined by default, I don't see why you'd need to ship them with the library |
tiangolo commentedMar 30, 2019
Ah! Sorry, I was misunderstanding something. There's an actual copy of the Swagger UI JS bundle in the tests. I was thinking that it was meant to be included as the default static version. As this approach would still require users (developers) to download and configure the static files by hand and then pass additional parameters to the app object, it would be quite some effort to set everything up. So, most of the effort required in the original issue#110 would still be needed. I think I would prefer to:
Then, in the case of#110, to reduce as much as possible the steps to get static local docs, I think it could be done with an external installable Python package that includes those static files and can be connected somehow to the app. But I'm not sure yet about all the details. |
wshayes commentedMar 31, 2019
There is already a python package for swagger ui:https://pypi.org/project/swagger-ui-py |
tiangolo commentedMar 31, 2019
Thanks@wshayes ! Very interesting. I see it has official support for several specific frameworks. Although it seems maybe some of its utils could be re-used. It seems to be very close to what I think we could use, the drawback I see is that it's several versions behind. But still, it seems promising. |
More tests, hopefully coverage increase
3 files, js css and favicon, those that are notpassed default to their cdn version and a warning isissued
tiangolo left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Let's do the following, let's simplify the scope of this PR to making the URLs in the docs functions parameterizable, and testing them.
The only files that need to be included in the PR arefastapi/openapi/docs.py and the tests.
Then, in a future PR, we can document how to use them to create custom docs responses, overriding the default URLs.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
tiangolo commentedMay 15, 2019
Good job@euri10 , now it's just removing the extra files in There's no need to have permutations. Just test that the function without parameters returns the fixed URLs, and that adding parameters, they are included in the response. Then we're good to go with this. The next step will be documenting how to use it, but that will be later. |
euri10 commentedMay 16, 2019
done |
tiangolo commentedMay 20, 2019
Thanks@euri10 ! 🎉 🚀 BTW, nice job refactoring with f-strings 😉 🍰 |
ackerleytng commentedOct 16, 2019
It seems like while (and similarly for redoc) |
Signed-off-by lmignon
Uh oh!
There was an error while loading.Please reload this page.
About#110
it adds an optional
static_directoryto FastAPI, if it's None (which it is by default) the generated html uses the cdn existing at present and the icon also.If it's set to a path, path is added as a starlette StaticFile, and in that case, FastAPI needs an extra dictionary with js, css and favicon
I'd rather discuss if you're ok with that implementation before doing /redoc 🙈 , some stuff might be moved in
setup()and I'm struggling with those mypy errors, would love some help !