Skip to content
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

experimenting for Swagger api docs #27

Merged
merged 3 commits into from
Jan 31, 2021

Conversation

sinisaos
Copy link
Member

@dantownsend Small changes for Piccolo admin api. Experimenting for Swagger admin api docs.

@dantownsend
Copy link
Member

@sinisaos I had a play around with it locally. You're right about the CSRF thing being a pain.

I was hoping that the Swagger docs would be configurable, and we could tell it to embed the CSRF token in the header of each request, but this doesn't seem possible.

https://swagger.io/docs/specification/authentication/cookie-authentication/

As you mentioned, we could add a CSRF field to each form, but it's not a great user experience, as they would have to copy the CSRF token into that field each time they did a POST.

Even without being able to POST data, it's still useful as documentation though using Redoc.

Screenshot 2021-01-27 at 23 52 01

@sinisaos
Copy link
Member Author

@dantownsend You are absolutely right. I forget about Redoc (which looks much nicer) and with it we get free api documentation with all the methods and parameters per table. For interactivity we have Piccolo admin UI :) which is much better, easier and with much more features than Swagger UI. If you are going to merge this I can make another commit to update Piccolo admin Read the Docs to show users for that possibility and to add title with sitename and description with table name to FastAPI instance in FastAPIWrapper in admin endpoints.py.

@dantownsend
Copy link
Member

@sinisaos Yes, feel free to extend the docs. I do intend on merging it in, but will play around with it a bit more at the weekend.

At the moment we have documentation for the /api/tables/<tablename> endpoints, but I'd like to see if the following can also be added too:

/api/tables
/api/meta
/api/user

It's not super important, but would be nice to have it all documented.

@sinisaos
Copy link
Member Author

@dantownsend Can you resolve this conflict or I need to remove FastAPI from requirements.txt and add this to endpoints.py?

try:
    from fastapi import FastAPI
except ImportError:
    print(
        "Install fastapi to use this feature - "
        "pip install piccolo_api[fastapi]."
    )

Thanks.

@dantownsend
Copy link
Member

@sinisaos I've resolved the merge conflicts - didn't realise you could do it from within the GitHub GUI.

@sinisaos
Copy link
Member Author

@dantownsend Thanks. Please check for errors in new docs file because I am not a native English speaker.

@dantownsend
Copy link
Member

@sinisaos Cool, no problem - I'll merge it into a feature branch and have a play around.

@dantownsend dantownsend changed the base branch from master to fastapi_backend January 31, 2021 18:18
@dantownsend dantownsend merged commit fc21364 into piccolo-orm:fastapi_backend Jan 31, 2021
@sinisaos
Copy link
Member Author

@dantownsend Great. Thanks.

@sinisaos sinisaos deleted the swagger-admin-docs branch February 5, 2021 05:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants