|
| 1 | +"""Helper script to automatically generate OAS |
| 2 | +
|
| 3 | +This OAS are the source of truth |
| 4 | +""" |
| 5 | + |
| 6 | +# pylint: disable=redefined-outer-name |
| 7 | +# pylint: disable=unused-argument |
| 8 | +# pylint: disable=unused-variable |
| 9 | +# pylint: disable=too-many-arguments |
| 10 | + |
| 11 | + |
| 12 | +from typing import Annotated |
| 13 | + |
| 14 | +from _common import as_query |
| 15 | +from fastapi import APIRouter, Depends, status |
| 16 | +from models_library.api_schemas_webserver.conversations import ( |
| 17 | + ConversationMessagePatch, |
| 18 | + ConversationMessageRestGet, |
| 19 | + ConversationPatch, |
| 20 | + ConversationRestGet, |
| 21 | +) |
| 22 | +from models_library.generics import Envelope |
| 23 | +from models_library.rest_pagination import Page |
| 24 | +from simcore_service_webserver._meta import API_VTAG |
| 25 | +from simcore_service_webserver.conversations._controller._common import ( |
| 26 | + ConversationPathParams, |
| 27 | +) |
| 28 | +from simcore_service_webserver.conversations._controller._conversations_messages_rest import ( |
| 29 | + _ConversationMessageCreateBodyParams, |
| 30 | + _ConversationMessagePathParams, |
| 31 | + _ListConversationMessageQueryParams, |
| 32 | +) |
| 33 | +from simcore_service_webserver.conversations._controller._conversations_rest import ( |
| 34 | + _ConversationsCreateBodyParams, |
| 35 | + _ListConversationsQueryParams, |
| 36 | +) |
| 37 | + |
| 38 | +router = APIRouter( |
| 39 | + prefix=f"/{API_VTAG}", |
| 40 | + tags=[ |
| 41 | + "conversations", |
| 42 | + ], |
| 43 | +) |
| 44 | + |
| 45 | + |
| 46 | +# |
| 47 | +# API entrypoints CONVERSATIONS |
| 48 | +# |
| 49 | + |
| 50 | + |
| 51 | +@router.post( |
| 52 | + "/conversations", |
| 53 | + response_model=Envelope[ConversationRestGet], |
| 54 | + status_code=status.HTTP_201_CREATED, |
| 55 | +) |
| 56 | +async def create_conversation( |
| 57 | + _body: _ConversationsCreateBodyParams, |
| 58 | +): ... |
| 59 | + |
| 60 | + |
| 61 | +@router.get( |
| 62 | + "/conversations", |
| 63 | + response_model=Page[ConversationRestGet], |
| 64 | +) |
| 65 | +async def list_conversations( |
| 66 | + _query: Annotated[_ListConversationsQueryParams, Depends()], |
| 67 | +): ... |
| 68 | + |
| 69 | + |
| 70 | +@router.patch( |
| 71 | + "/conversations/{conversation_id}", |
| 72 | + response_model=Envelope[ConversationRestGet], |
| 73 | +) |
| 74 | +async def update_conversation( |
| 75 | + _params: Annotated[ConversationPathParams, Depends()], |
| 76 | + _body: ConversationPatch, |
| 77 | +): ... |
| 78 | + |
| 79 | + |
| 80 | +@router.delete( |
| 81 | + "/conversations/{conversation_id}", |
| 82 | + status_code=status.HTTP_204_NO_CONTENT, |
| 83 | +) |
| 84 | +async def delete_conversation( |
| 85 | + _params: Annotated[ConversationPathParams, Depends()], |
| 86 | +): ... |
| 87 | + |
| 88 | + |
| 89 | +@router.get( |
| 90 | + "/conversations/{conversation_id}", |
| 91 | + response_model=Envelope[ConversationRestGet], |
| 92 | +) |
| 93 | +async def get_conversation( |
| 94 | + _params: Annotated[ConversationPathParams, Depends()], |
| 95 | +): ... |
| 96 | + |
| 97 | + |
| 98 | +# |
| 99 | +# API entrypoints CONVERSATION MESSAGES |
| 100 | +# |
| 101 | + |
| 102 | + |
| 103 | +@router.post( |
| 104 | + "/conversations/{conversation_id}/messages", |
| 105 | + response_model=Envelope[ConversationMessageRestGet], |
| 106 | + status_code=status.HTTP_201_CREATED, |
| 107 | +) |
| 108 | +async def create_conversation_message( |
| 109 | + _params: Annotated[ConversationPathParams, Depends()], |
| 110 | + _body: _ConversationMessageCreateBodyParams, |
| 111 | +): ... |
| 112 | + |
| 113 | + |
| 114 | +@router.get( |
| 115 | + "/conversations/{conversation_id}/messages", |
| 116 | + response_model=Page[ConversationMessageRestGet], |
| 117 | +) |
| 118 | +async def list_conversation_messages( |
| 119 | + _params: Annotated[ConversationPathParams, Depends()], |
| 120 | + _query: Annotated[as_query(_ListConversationMessageQueryParams), Depends()], |
| 121 | +): ... |
| 122 | + |
| 123 | + |
| 124 | +@router.put( |
| 125 | + "/conversations/{conversation_id}/messages/{message_id}", |
| 126 | + response_model=Envelope[ConversationMessageRestGet], |
| 127 | +) |
| 128 | +async def update_conversation_message( |
| 129 | + _params: Annotated[_ConversationMessagePathParams, Depends()], |
| 130 | + _body: ConversationMessagePatch, |
| 131 | +): ... |
| 132 | + |
| 133 | + |
| 134 | +@router.delete( |
| 135 | + "/conversations/{conversation_id}/messages/{message_id}", |
| 136 | + status_code=status.HTTP_204_NO_CONTENT, |
| 137 | +) |
| 138 | +async def delete_conversation_message( |
| 139 | + _params: Annotated[_ConversationMessagePathParams, Depends()], |
| 140 | +): ... |
| 141 | + |
| 142 | + |
| 143 | +@router.get( |
| 144 | + "/conversations/{conversation_id}/messages/{message_id}", |
| 145 | + response_model=Envelope[ConversationMessageRestGet], |
| 146 | +) |
| 147 | +async def get_conversation_message( |
| 148 | + _params: Annotated[_ConversationMessagePathParams, Depends()], |
| 149 | +): ... |
0 commit comments