-
-
Notifications
You must be signed in to change notification settings - Fork 493
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hide endpoints from OpenAPI schema by default #1196
Hide endpoints from OpenAPI schema by default #1196
Conversation
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.
Very nice! Thanks for the great addition.
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.
Thanks, @DaelonSuzuka, for this great PR! I'd love to improve NiceGUI's OpenAPI support.
There are, however, several concerns with the current implementation. Some are mainly aesthetics, others are more serious:
-
For consistency with the
uvicorn_reload
parameters, I'd like to support comma-separated lists that are processed with the very samesplit_args
functions.But since we're not dealing with arbitrary strings, a
List[Literal['internal', 'page', 'all']]
might be even better. This would support auto-completion and static type checkers without adding too much user code (['internal', 'page']
instead of'internal page'
).Actually we only need one string at the moment: "", "internal", "page", or "all". So I could imagine declaring the type as
Literal['none', 'internal', 'page', 'all'] = 'none'
for now. If needed, we could add additional support for lists of literals later. -
The check
'internal' not in endpoint_documentation
is not very precise, as it would match for something like "no_internals". Of course, this is related to points 1. Using a stricter type for the parameter has impact on the way we can implement conditions. If we go with a single literal, we can writeif endpoint_documentation in {'internal', 'all'}: ...
. -
I think we also need to consider
ui.run_with()
. Both functionsui.run()
andui.run_with()
could share the code for setting theinclude_in_schema
attributes. -
I experimented a bit with the pytests, shortened the code a little and remove the page decorators, because the auto-index page should be enough for these test cases. But some tests fail and I don't know why. Looks like we need tests with and without page decorators.
-
Routes might be created later. Especially the
app.add_static_*
methods add routes automatically. But there might be even more places we need to consider.
Great feedback, I agree with all of it except maybe the
Fwiw, I like
Funny story, I actually implemented the whole thing that way first, realized that normal routes get processed before
Wow, it's embarrassing how much cleaner you made those. I see this is going to be another project with a high educational value from contributing. |
Routes should now be correctly filtered whether they're created before or after I could add that case to the filter, but I think that creates a chance for colliding with legitimate names from user-created API-endpoints? Advice/opinions welcome.
|
# Conflicts: # nicegui/globals.py
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.
I just reviewed the code once again. Looks good to me. 🙂
But of course, we need to fix the failing tests. @DaelonSuzuka Can you elaborate on the choice of these two conditions:
if route.path.startswith('/_nicegui') and hasattr(route, 'methods'):
# handle internal route
if route.name == 'decorated':
# handle page route
I'm not sure if they are stable enough and catch all cases. Especially the auto-index page "/" doesn't seem to be correctly handled, probably because it isn't decorated. I couldn't find a quick fix. But maybe you help me understand the current approach before I try to improve it.
@falkoschindler There wasn't much of an approach, tbh. I made an example app with some
I don't know how common it is for FastAPI users to set names on routes. I've never seen it in a tutorial or stack overflow answer, but that's hardly definitive. A user wanting to set custom names as a kwarg to |
Ok, I think I could fix both tests by checking if the route is in But the tests still fail when run all in one go. It looks like something isn't reset between individual tests. |
Yay, I managed to reset the |
Well, in combination with all other tests, the endpoint tests fail. 😕 But maybe it is related to the current problem with the Chrome driver. I had to create driver manager like this to get the tests working at all: s = Service(ChromeDriverManager(version='114.0.5735.90').install()) Even with this hack some tests fail for the v1.3.6 tag, let alone this branch. So I think we should fix the test infrastructure before merging new features. |
I read the commits and your changes are much cleaner, but I pulled the branch to my local machine. I have the same issue with the unit tests, but I also found this problem: User-provided routes other than
No objections here. Possibly related side note: I did have trouble getting NiceGUI installed in the first place. It felt like the requirements were out of date or were only tested on one OS. I also couldn't get the development docker environment to work, but I didn't put much effort into diagnosing why. |
@DaelonSuzuka Weird. I thought our tests would cover this case. Well, we'll need to look into it. I won't have time over the weekend, but maybe you'll have some insight. Our docker setup is probably not in the best shape right now. There are multiple related issues and PRs working on it: #1255, #1057, #1018. |
Well that was easy, basically just a typo. My manual testing all works now. Off topic:I do find it a bit strange that The test suite fails with stuff like |
Ok, we finally fixed the pytests and merged into main. Thanks again, @DaelonSuzuka! Regarding |
Implementation of #1188
There's not much to say, this is pretty simple. The tests were definitely more work than the feature, but the existing tests had everything I needed to
stealborrow.