Extending generated OpenAPI docs (#799)

* Added login endpoint docs

* make format

* Changed login route into multiple examples.

* Added reset password router docs

* Updated /{id} routes for user

* Updated /me routes

* Fixed user already exists response description

* Updated the /register route

* Updated verify routes

* Updated oauth2 endpoints.

* Applied `make format`

* Renamed Authentication methods for getting their openapi schemas

- `get_login_responses_success` -> `get_openapi_login_responses_success`
- `get_logout_responses_success` -> `get_openapi_logout_responses_success`

* Fixed flake8 errors

* Not using `Final` to keep python37 compatibility

Co-authored-by: François Voron <fvoron@gmail.com>
This commit is contained in:
Matyáš Richter
2021-11-23 13:13:51 +01:00
committed by GitHub
parent 1f5ce51df2
commit c759bb6915
16 changed files with 546 additions and 35 deletions

View File

@ -1,7 +1,7 @@
from typing import Any, Generic, List, Optional
from typing import Any, Dict, Generic, List, Optional
import jwt
from fastapi import Response
from fastapi import Response, status
from fastapi.security import APIKeyCookie
from pydantic import UUID4
@ -113,6 +113,9 @@ class CookieAuthentication(
# so that FastAPI can terminate it properly
return None
def get_openapi_login_responses_success(self) -> Dict[str, Any]:
return {status.HTTP_200_OK: {"model": None}}
async def get_logout_response(
self,
user: models.UD,
@ -123,6 +126,9 @@ class CookieAuthentication(
self.cookie_name, path=self.cookie_path, domain=self.cookie_domain
)
def get_openapi_logout_responses_success(self) -> Dict[str, Any]:
return {status.HTTP_200_OK: {"model": None}}
async def _generate_token(self, user: models.UD) -> str:
data = {"user_id": str(user.id), "aud": self.token_audience}
return generate_jwt(data, self.secret, self.lifetime_seconds)