diff --git a/api/src/common/entity_mapper.py b/api/src/common/entity_mapper.py new file mode 100644 index 00000000..dc6b2ed4 --- /dev/null +++ b/api/src/common/entity_mapper.py @@ -0,0 +1,37 @@ +from typing import Optional, Type + +from pydantic import BaseModel + + +def filter_fields( + name: Optional[str] = None, + include: Optional[list[str]] = None, + exclude: Optional[list[str]] = None, +): + """Return a decorator to filter model fields""" + + def decorator(cls: Type[BaseModel]): + config = cls.Config() + to_include = getattr(config, "include", include) + to_exclude = getattr(config, "exclude", exclude) + + if name: + cls.__name__ = name + + include_ = set(cls.__fields__.keys()) + + if to_include is not None: + include_ &= set(to_include) + + exclude_ = set() + if to_exclude is not None: + exclude_ = set(to_exclude) + if to_include and to_exclude and set(to_include) & set(to_exclude): + raise ValueError("include and exclude cannot contain the same fields") + + for field in list(cls.__fields__): + if field not in include_ or field in exclude_: + del cls.__fields__[field] + return cls + + return decorator diff --git a/api/src/data_providers/repositories/TodoRepository.py b/api/src/data_providers/repositories/TodoRepository.py index 8e85aad9..549c85b1 100644 --- a/api/src/data_providers/repositories/TodoRepository.py +++ b/api/src/data_providers/repositories/TodoRepository.py @@ -9,7 +9,7 @@ def to_dict(todo_item: TodoItem): - dict = todo_item.__dict__ + dict = todo_item.dict() dict["_id"] = todo_item.id return dict diff --git a/api/src/entities/TodoItem.py b/api/src/entities/TodoItem.py index 8bde68ff..7e8c4969 100644 --- a/api/src/entities/TodoItem.py +++ b/api/src/entities/TodoItem.py @@ -1,19 +1,19 @@ -from dataclasses import asdict, dataclass, fields +from pydantic import BaseModel, Field +title_field = Field( + ..., title="The title of the item", max_length=30, min_length=1, example="Read about clean architecture" +) -@dataclass(frozen=True) -class TodoItem: + +class TodoItem(BaseModel): id: str user_id: str - title: str + title: str = title_field is_completed: bool = False - def to_dict(self): - return asdict(self) - @classmethod def from_dict(cls, dict_) -> "TodoItem": - class_fields = {f.name for f in fields(cls)} + class_fields = {field for field in cls.__fields__} if "_id" in dict_: dict_["id"] = dict_.pop("_id") data = {k: v for k, v in dict_.items() if k in class_fields} diff --git a/api/src/features/todo/shared_models.py b/api/src/features/todo/shared_models.py new file mode 100644 index 00000000..fa058659 --- /dev/null +++ b/api/src/features/todo/shared_models.py @@ -0,0 +1,10 @@ +from common.entity_mapper import filter_fields +from entities.TodoItem import TodoItem + + +# An alternative solution is to use Pydantic BaseModel +# and to duplicate all the fields except user_id +@filter_fields(name="TodoItem") +class TodoItemResponseModel(TodoItem): + class Config: + exclude = ["user_id"] diff --git a/api/src/features/todo/todo_feature.py b/api/src/features/todo/todo_feature.py index ce05eebf..4f4c9090 100644 --- a/api/src/features/todo/todo_feature.py +++ b/api/src/features/todo/todo_feature.py @@ -11,30 +11,27 @@ TodoRepositoryInterface, ) -from .use_cases.add_todo import AddTodoRequest, AddTodoResponse, add_todo_use_case -from .use_cases.delete_todo_by_id import DeleteTodoByIdResponse, delete_todo_use_case -from .use_cases.get_todo_all import GetTodoAllResponse, get_todo_all_use_case -from .use_cases.get_todo_by_id import GetTodoByIdResponse, get_todo_by_id_use_case -from .use_cases.update_todo import ( - UpdateTodoRequest, - UpdateTodoResponse, - update_todo_use_case, -) +from .shared_models import TodoItemResponseModel +from .use_cases.add_todo import AddTodoRequestModel, add_todo_use_case +from .use_cases.delete_todo_by_id import delete_todo_use_case +from .use_cases.get_todo_all import get_todo_all_use_case +from .use_cases.get_todo_by_id import get_todo_by_id_use_case +from .use_cases.update_todo import UpdateTodoRequest, update_todo_use_case router = APIRouter(tags=["todos"], prefix="/todos") -@router.post("", operation_id="create", response_model=AddTodoResponse) +@router.post("", operation_id="create", response_model=TodoItemResponseModel) @create_response(JSONResponse) def add_todo( - data: AddTodoRequest, + data: AddTodoRequestModel, user: User = Depends(auth_with_jwt), todo_repository: TodoRepositoryInterface = Depends(get_todo_repository), ): return add_todo_use_case(data=data, user_id=user.user_id, todo_repository=todo_repository).dict() -@router.get("/{id}", operation_id="get_by_id", response_model=GetTodoByIdResponse) +@router.get("/{id}", operation_id="get_by_id", response_model=TodoItemResponseModel) @create_response(JSONResponse) def get_todo_by_id( id: str, @@ -44,17 +41,17 @@ def get_todo_by_id( return get_todo_by_id_use_case(id=id, user_id=user.user_id, todo_repository=todo_repository).dict() -@router.delete("/{id}", operation_id="delete_by_id", response_model=DeleteTodoByIdResponse) +@router.delete("/{id}", operation_id="delete_by_id") @create_response(JSONResponse) def delete_todo_by_id( id: str, user: User = Depends(auth_with_jwt), todo_repository: TodoRepositoryInterface = Depends(get_todo_repository), ): - return delete_todo_use_case(id=id, user_id=user.user_id, todo_repository=todo_repository).dict() + return delete_todo_use_case(id=id, user_id=user.user_id, todo_repository=todo_repository) -@router.get("", operation_id="get_all", response_model=List[GetTodoAllResponse]) +@router.get("", operation_id="get_all", response_model=List[TodoItemResponseModel]) @create_response(JSONResponse) def get_todo_all( user: User = Depends(auth_with_jwt), todo_repository: TodoRepositoryInterface = Depends(get_todo_repository) @@ -62,7 +59,7 @@ def get_todo_all( return [todo.dict() for todo in get_todo_all_use_case(user_id=user.user_id, todo_repository=todo_repository)] -@router.put("/{id}", operation_id="update_by_id", response_model=UpdateTodoResponse) +@router.put("/{id}", operation_id="update_by_id", response_model=TodoItemResponseModel) @create_response(JSONResponse) def update_todo( id: str, diff --git a/api/src/features/todo/use_cases/add_todo.py b/api/src/features/todo/use_cases/add_todo.py index fdd30f17..040ef3db 100644 --- a/api/src/features/todo/use_cases/add_todo.py +++ b/api/src/features/todo/use_cases/add_todo.py @@ -1,38 +1,24 @@ import uuid -from pydantic import BaseModel, Field - +from common.entity_mapper import filter_fields from data_providers.repository_interfaces.TodoRepositoryInterface import ( TodoRepositoryInterface, ) from entities.TodoItem import TodoItem +from features.todo.shared_models import TodoItemResponseModel -class AddTodoRequest(BaseModel): - title: str = Field( - ..., - title="The title of the item", - max_length=300, - min_length=1, - example="Read about clean architecture", - ) - - -class AddTodoResponse(BaseModel): - id: str = Field(example="vytxeTZskVKR7C7WgdSP3d") - title: str = Field(example="Read about clean architecture") - is_completed: bool = False - - @staticmethod - def from_entity(todo_item: TodoItem) -> "AddTodoResponse": - return AddTodoResponse(id=todo_item.id, title=todo_item.title, is_completed=todo_item.is_completed) +# An alternative solution is to use Pydantic BaseModel +# and to duplicate the title and is_completed fields +@filter_fields(name="AddTodo") +class AddTodoRequestModel(TodoItem): + class Config: + include = ["title"] def add_todo_use_case( - data: AddTodoRequest, - user_id: str, - todo_repository: TodoRepositoryInterface, -) -> AddTodoResponse: + data: AddTodoRequestModel, user_id: str, todo_repository: TodoRepositoryInterface +) -> TodoItemResponseModel: todo_item = TodoItem(id=str(uuid.uuid4()), title=data.title, user_id=user_id) todo_repository.create(todo_item) - return AddTodoResponse.from_entity(todo_item) + return TodoItemResponseModel.parse_obj(todo_item) diff --git a/api/src/features/todo/use_cases/delete_todo_by_id.py b/api/src/features/todo/use_cases/delete_todo_by_id.py index 59eada21..1199de62 100644 --- a/api/src/features/todo/use_cases/delete_todo_by_id.py +++ b/api/src/features/todo/use_cases/delete_todo_by_id.py @@ -1,20 +1,13 @@ -from pydantic import BaseModel, Field - from common.exceptions import MissingPrivilegeException, NotFoundException from data_providers.repository_interfaces.TodoRepositoryInterface import ( TodoRepositoryInterface, ) -class DeleteTodoByIdResponse(BaseModel): - success: bool = Field(...) - - -def delete_todo_use_case(id: str, user_id: str, todo_repository: TodoRepositoryInterface) -> DeleteTodoByIdResponse: +def delete_todo_use_case(id: str, user_id: str, todo_repository: TodoRepositoryInterface) -> None: todo_item = todo_repository.get(id) if todo_item is None: raise NotFoundException if todo_item.user_id != user_id: raise MissingPrivilegeException todo_repository.delete(id) - return DeleteTodoByIdResponse(success=True) diff --git a/api/src/features/todo/use_cases/get_todo_all.py b/api/src/features/todo/use_cases/get_todo_all.py index 8806acf3..7461f688 100644 --- a/api/src/features/todo/use_cases/get_todo_all.py +++ b/api/src/features/todo/use_cases/get_todo_all.py @@ -1,29 +1,17 @@ from typing import List -from pydantic import BaseModel, Field - from data_providers.repository_interfaces.TodoRepositoryInterface import ( TodoRepositoryInterface, ) -from entities.TodoItem import TodoItem - - -class GetTodoAllResponse(BaseModel): - id: str = Field(...) - title: str = Field(...) - is_completed: bool - - @staticmethod - def from_entity(todo_item: TodoItem): - return GetTodoAllResponse(id=todo_item.id, title=todo_item.title, is_completed=todo_item.is_completed) +from features.todo.shared_models import TodoItemResponseModel def get_todo_all_use_case( user_id: str, todo_repository: TodoRepositoryInterface, -) -> List[GetTodoAllResponse]: +) -> List[TodoItemResponseModel]: return [ - GetTodoAllResponse.from_entity(todo_item) + TodoItemResponseModel.parse_obj(todo_item) for todo_item in todo_repository.get_all() if todo_item.user_id == user_id ] diff --git a/api/src/features/todo/use_cases/get_todo_by_id.py b/api/src/features/todo/use_cases/get_todo_by_id.py index 78b710c6..114f905e 100644 --- a/api/src/features/todo/use_cases/get_todo_by_id.py +++ b/api/src/features/todo/use_cases/get_todo_by_id.py @@ -1,26 +1,12 @@ -from typing import cast - -from pydantic import BaseModel, Field - from common.exceptions import MissingPrivilegeException from data_providers.repository_interfaces.TodoRepositoryInterface import ( TodoRepositoryInterface, ) -from entities.TodoItem import TodoItem - - -class GetTodoByIdResponse(BaseModel): - id: str = Field(...) - title: str = Field(...) - is_completed: bool = False - - @staticmethod - def from_entity(todo_item: TodoItem) -> "GetTodoByIdResponse": - return GetTodoByIdResponse(id=todo_item.id, title=todo_item.title, is_completed=todo_item.is_completed) +from features.todo.shared_models import TodoItemResponseModel -def get_todo_by_id_use_case(id: str, user_id: str, todo_repository: TodoRepositoryInterface) -> GetTodoByIdResponse: +def get_todo_by_id_use_case(id: str, user_id: str, todo_repository: TodoRepositoryInterface) -> TodoItemResponseModel: todo_item = todo_repository.get(id) if todo_item.user_id != user_id: raise MissingPrivilegeException - return GetTodoByIdResponse.from_entity(cast(TodoItem, todo_item)) + return TodoItemResponseModel.parse_obj(todo_item) diff --git a/api/src/features/todo/use_cases/update_todo.py b/api/src/features/todo/use_cases/update_todo.py index cc186e4e..7682cc8e 100644 --- a/api/src/features/todo/use_cases/update_todo.py +++ b/api/src/features/todo/use_cases/update_todo.py @@ -1,24 +1,18 @@ -from pydantic import BaseModel, Field - +from common.entity_mapper import filter_fields from common.exceptions import MissingPrivilegeException from data_providers.repository_interfaces.TodoRepositoryInterface import ( TodoRepositoryInterface, ) from entities.TodoItem import TodoItem +from features.todo.shared_models import TodoItemResponseModel -class UpdateTodoRequest(BaseModel): - title: str = Field( - "", - title="The title of the item", - max_length=300, - min_length=1, - ) - is_completed: bool - - -class UpdateTodoResponse(BaseModel): - success: bool = Field(...) +# An alternative solution is to use Pydantic BaseModel +# and to duplicate the title and is_completed fields +@filter_fields(name="UpdateTodo") +class UpdateTodoRequest(TodoItem): + class Config: + include = ["title", "is_completed"] def update_todo_use_case( @@ -26,12 +20,10 @@ def update_todo_use_case( data: UpdateTodoRequest, user_id: str, todo_repository: TodoRepositoryInterface, -) -> UpdateTodoResponse: +) -> TodoItemResponseModel: todo_item = todo_repository.get(id) if todo_item.user_id != user_id: raise MissingPrivilegeException - updated_todo_item = TodoItem(id=todo_item.id, title=data.title, is_completed=data.is_completed, user_id=user_id) - if todo_repository.update(updated_todo_item): - return UpdateTodoResponse(success=True) - return UpdateTodoResponse(success=False) + todo_repository.update(updated_todo_item) + return TodoItemResponseModel.parse_obj(updated_todo_item) diff --git a/api/src/tests/integration/features/todo/test_todo_feature.py b/api/src/tests/integration/features/todo/test_todo_feature.py index 362f56a5..e446869c 100644 --- a/api/src/tests/integration/features/todo/test_todo_feature.py +++ b/api/src/tests/integration/features/todo/test_todo_feature.py @@ -59,7 +59,7 @@ def test_update_todo(self, test_app): response = test_app.put("/todos/1", json={"title": "title 1 updated", "is_completed": False}) assert response.status_code == HTTP_200_OK - assert response.json()["success"] + assert response.json()["title"] == "title 1 updated" def test_update_todo_should_return_not_found(self, test_app): response = test_app.put("/todos/unknown", json={"title": "something", "is_completed": False}) @@ -74,7 +74,6 @@ def test_delete_todo(self, test_app: TestClient): response = test_app.delete("/todos/1") assert response.status_code == HTTP_200_OK - assert response.json()["success"] def test_delete_todo_should_return_not_found(self, test_app: TestClient): response = test_app.delete("/todos/unknown") diff --git a/api/src/tests/unit/common/test_entity_mapper.py b/api/src/tests/unit/common/test_entity_mapper.py new file mode 100644 index 00000000..06eeb881 --- /dev/null +++ b/api/src/tests/unit/common/test_entity_mapper.py @@ -0,0 +1,45 @@ +from dataclasses import dataclass + +from pydantic import BaseModel + +from common.entity_mapper import filter_fields + + +class MyEntity(BaseModel): + a: int + b: str + + +@dataclass +class InventoryItem: + a: int + + +def test_include_fields(): + @filter_fields() + class MyModel(MyEntity): + class Config: + include = ["a"] + + schema = MyModel.schema() + assert schema["properties"] == {"a": {"title": "A", "type": "integer"}} + + +def test_exclude_fields(): + @filter_fields() + class MyModel(MyEntity): + class Config: + exclude = ["b"] + + schema = MyModel.schema() + assert schema["properties"] == {"a": {"title": "A", "type": "integer"}} + + +def test_rename(): + @filter_fields(name="MySpecialModel") + class MyModel(MyEntity): + pass + + schema = MyModel.schema() + + assert schema["title"] == "MySpecialModel" diff --git a/api/src/tests/unit/features/todo/use_cases/test_add_todo.py b/api/src/tests/unit/features/todo/use_cases/test_add_todo.py index e2d0b7e2..15b98d31 100644 --- a/api/src/tests/unit/features/todo/use_cases/test_add_todo.py +++ b/api/src/tests/unit/features/todo/use_cases/test_add_todo.py @@ -4,16 +4,18 @@ from data_providers.repository_interfaces.TodoRepositoryInterface import ( TodoRepositoryInterface, ) -from features.todo.use_cases.add_todo import AddTodoRequest, add_todo_use_case +from features.todo.use_cases.add_todo import AddTodoRequestModel, add_todo_use_case def test_add_with_valid_title_should_return_todo(todo_repository: TodoRepositoryInterface): - data = AddTodoRequest(title="new todo") - result = add_todo_use_case(data, user_id="xyz", todo_repository=todo_repository) - assert result.title == data.title + title = "new todo" + data = AddTodoRequestModel(title=title) + result = add_todo_use_case(data=data, user_id="xyz", todo_repository=todo_repository) + assert result.title == title def test_add_with_empty_title_should_throw_validation_error(todo_repository: TodoRepositoryInterface): with pytest.raises(ValidationError): - data = AddTodoRequest(title="") - add_todo_use_case(data, user_id="xyz", todo_repository=todo_repository) + title = "" + data = AddTodoRequestModel(title=title) + add_todo_use_case(data=data, user_id="xyz", todo_repository=todo_repository) diff --git a/api/src/tests/unit/features/todo/use_cases/test_delete_todo_by_id.py b/api/src/tests/unit/features/todo/use_cases/test_delete_todo_by_id.py index 4faf142a..1b43f7b8 100644 --- a/api/src/tests/unit/features/todo/use_cases/test_delete_todo_by_id.py +++ b/api/src/tests/unit/features/todo/use_cases/test_delete_todo_by_id.py @@ -4,16 +4,15 @@ from data_providers.repository_interfaces.TodoRepositoryInterface import ( TodoRepositoryInterface, ) -from features.todo.use_cases.delete_todo_by_id import ( - DeleteTodoByIdResponse, - delete_todo_use_case, -) +from features.todo.use_cases.delete_todo_by_id import delete_todo_use_case def test_delete_todo_should_return_success(todo_repository: TodoRepositoryInterface): id = "dh2109" - result: DeleteTodoByIdResponse = delete_todo_use_case(id=id, user_id="xyz", todo_repository=todo_repository) - assert result.success + try: + delete_todo_use_case(id=id, user_id="xyz", todo_repository=todo_repository) + except Exception: + assert False def test_delete_todo_should_return_not_success(todo_repository: TodoRepositoryInterface): diff --git a/api/src/tests/unit/features/todo/use_cases/test_get_todo_by_id.py b/api/src/tests/unit/features/todo/use_cases/test_get_todo_by_id.py index 3eef9b66..396710e9 100644 --- a/api/src/tests/unit/features/todo/use_cases/test_get_todo_by_id.py +++ b/api/src/tests/unit/features/todo/use_cases/test_get_todo_by_id.py @@ -6,15 +6,12 @@ from data_providers.repository_interfaces.TodoRepositoryInterface import ( TodoRepositoryInterface, ) -from features.todo.use_cases.get_todo_by_id import ( - GetTodoByIdResponse, - get_todo_by_id_use_case, -) +from features.todo.use_cases.get_todo_by_id import get_todo_by_id_use_case def test_get_todo_by_id_should_return_todo(todo_repository: TodoRepositoryInterface, todo_test_data: Dict[str, dict]): id = "dh2109" - todo: GetTodoByIdResponse = get_todo_by_id_use_case(id, user_id="xyz", todo_repository=todo_repository) + todo = get_todo_by_id_use_case(id, user_id="xyz", todo_repository=todo_repository) assert todo.title == todo_test_data[id]["title"] diff --git a/api/src/tests/unit/features/todo/use_cases/test_update_todo.py b/api/src/tests/unit/features/todo/use_cases/test_update_todo.py index 47381b14..8006bea1 100644 --- a/api/src/tests/unit/features/todo/use_cases/test_update_todo.py +++ b/api/src/tests/unit/features/todo/use_cases/test_update_todo.py @@ -8,4 +8,4 @@ def test_update_todo_should_return_success(todo_repository: TodoRepositoryInterf id = "dh2109" data = UpdateTodoRequest(title="new title", is_completed=False) result = update_todo_use_case(id, data, user_id="xyz", todo_repository=todo_repository) - assert result.success + assert data.title == result.title diff --git a/generate-api-typescript-client.sh b/generate-api-typescript-client.sh index 5e6b7a2d..14f66be2 100755 --- a/generate-api-typescript-client.sh +++ b/generate-api-typescript-client.sh @@ -2,8 +2,8 @@ # This requires the API to be running on localhost port 5000 -docker run --ulimit nofile=122880:122880 --rm --network="host" -v ${PWD}/web/src/api:/local openapitools/openapi-generator-cli:v5.1.0 generate \ +docker run --ulimit nofile=122880:122880 --rm --network="host" -v ${PWD}/web/src/api:/local openapitools/openapi-generator-cli:v6.2.1 generate \ -i http://127.0.0.1:5000/openapi.json \ -g typescript-axios \ - --additional-properties=useSingleRequestParameter=true,withSeparateModelsAndApi=true,apiPackage=api,modelPackage=models \ + --additional-properties=withSeparateModelsAndApi=true,apiPackage=api,modelPackage=models \ -o /local/generated \ No newline at end of file diff --git a/web/src/api/generated/.openapi-generator/FILES b/web/src/api/generated/.openapi-generator/FILES index ef44509b..6c20cfb4 100644 --- a/web/src/api/generated/.openapi-generator/FILES +++ b/web/src/api/generated/.openapi-generator/FILES @@ -1,5 +1,6 @@ .gitignore .npmignore +.openapi-generator-ignore api.ts api/health-check-api.ts api/todos-api.ts @@ -9,12 +10,8 @@ common.ts configuration.ts git_push.sh index.ts -models/add-todo-request.ts -models/add-todo-response.ts -models/delete-todo-by-id-response.ts +models/add-todo.ts models/error-response.ts -models/get-todo-all-response.ts -models/get-todo-by-id-response.ts models/index.ts -models/update-todo-request.ts -models/update-todo-response.ts +models/todo-item.ts +models/update-todo.ts diff --git a/web/src/api/generated/.openapi-generator/VERSION b/web/src/api/generated/.openapi-generator/VERSION index acf69b48..0df17dd0 100644 --- a/web/src/api/generated/.openapi-generator/VERSION +++ b/web/src/api/generated/.openapi-generator/VERSION @@ -1 +1 @@ -5.1.0 \ No newline at end of file +6.2.1 \ No newline at end of file diff --git a/web/src/api/generated/api.ts b/web/src/api/generated/api.ts index 283196b8..a56d0fe0 100644 --- a/web/src/api/generated/api.ts +++ b/web/src/api/generated/api.ts @@ -2,9 +2,9 @@ /* eslint-disable */ /** * Template FastAPI React - * ### Description A RESTful API for handling todo items. Anyone in Equinor are authorized to run these calculations. * Click **Authorize** to login and start testing. ### Resources * [Docs](https://equinor.github.io/template-fastapi-react/) * [Github](https://github.com/equinor/template-fastapi-react) For questions about usage or expanding the API, create issue on Github or see docs. + * ### Description A RESTful API for handling todo items. Anyone in Equinor are authorized to use the API. * Click **Authorize** to login and start testing. ### Resources * [Docs](https://equinor.github.io/template-fastapi-react/) * [Github](https://github.com/equinor/template-fastapi-react) For questions about usage or expanding the API, create issue on Github or see docs. * - * The version of the OpenAPI document: 1.1.0 + * The version of the OpenAPI document: 1.3.0 * * * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). diff --git a/web/src/api/generated/api/health-check-api.ts b/web/src/api/generated/api/health-check-api.ts index ccdcaf1f..eb9cad1b 100644 --- a/web/src/api/generated/api/health-check-api.ts +++ b/web/src/api/generated/api/health-check-api.ts @@ -2,9 +2,9 @@ /* eslint-disable */ /** * Template FastAPI React - * ### Description A RESTful API for handling todo items. Anyone in Equinor are authorized to run these calculations. * Click **Authorize** to login and start testing. ### Resources * [Docs](https://equinor.github.io/template-fastapi-react/) * [Github](https://github.com/equinor/template-fastapi-react) For questions about usage or expanding the API, create issue on Github or see docs. + * ### Description A RESTful API for handling todo items. Anyone in Equinor are authorized to use the API. * Click **Authorize** to login and start testing. ### Resources * [Docs](https://equinor.github.io/template-fastapi-react/) * [Github](https://github.com/equinor/template-fastapi-react) For questions about usage or expanding the API, create issue on Github or see docs. * - * The version of the OpenAPI document: 1.1.0 + * The version of the OpenAPI document: 1.3.0 * * * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). @@ -13,7 +13,7 @@ */ -import globalAxios, { AxiosPromise, AxiosInstance } from 'axios'; +import globalAxios, { AxiosPromise, AxiosInstance, AxiosRequestConfig } from 'axios'; import { Configuration } from '../configuration'; // Some imports not used depending on template conditions // @ts-ignore @@ -34,7 +34,7 @@ export const HealthCheckApiAxiosParamCreator = function (configuration?: Configu * @param {*} [options] Override http request option. * @throws {RequiredError} */ - getHealthCheckGet: async (options: any = {}): Promise => { + getHealthCheckGet: async (options: AxiosRequestConfig = {}): Promise => { const localVarPath = `/health-check`; // use dummy base URL string because the URL constructor only accepts absolute URLs. const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL); @@ -49,7 +49,7 @@ export const HealthCheckApiAxiosParamCreator = function (configuration?: Configu - setSearchParams(localVarUrlObj, localVarQueryParameter, options.query); + setSearchParams(localVarUrlObj, localVarQueryParameter); let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {}; localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers}; @@ -74,7 +74,7 @@ export const HealthCheckApiFp = function(configuration?: Configuration) { * @param {*} [options] Override http request option. * @throws {RequiredError} */ - async getHealthCheckGet(options?: any): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise> { + async getHealthCheckGet(options?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise> { const localVarAxiosArgs = await localVarAxiosParamCreator.getHealthCheckGet(options); return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration); }, @@ -114,7 +114,7 @@ export class HealthCheckApi extends BaseAPI { * @throws {RequiredError} * @memberof HealthCheckApi */ - public getHealthCheckGet(options?: any) { + public getHealthCheckGet(options?: AxiosRequestConfig) { return HealthCheckApiFp(this.configuration).getHealthCheckGet(options).then((request) => request(this.axios, this.basePath)); } } diff --git a/web/src/api/generated/api/personal-access-token-api.ts b/web/src/api/generated/api/personal-access-token-api.ts deleted file mode 100644 index 48bc772c..00000000 --- a/web/src/api/generated/api/personal-access-token-api.ts +++ /dev/null @@ -1,459 +0,0 @@ -/* tslint:disable */ -/* eslint-disable */ -/** - * Boilerplate - * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) - * - * The version of the OpenAPI document: 0.1.0 - * - * - * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). - * https://openapi-generator.tech - * Do not edit the class manually. - */ - -import globalAxios, { AxiosPromise, AxiosInstance } from 'axios' -import { Configuration } from '../configuration' -// Some imports not used depending on template conditions -// @ts-ignore -import { - DUMMY_BASE_URL, - assertParamExists, - setApiKeyToObject, - setBasicAuthToObject, - setBearerAuthToObject, - setOAuthToObject, - setSearchParams, - serializeDataIfNeeded, - toPathString, - createRequestFunction, -} from '../common' -// @ts-ignore -import { - BASE_PATH, - COLLECTION_FORMATS, - RequestArgs, - BaseAPI, - RequiredError, -} from '../base' -// @ts-ignore -import { AccessLevel } from '../models' -// @ts-ignore -import { DeletePatResponse } from '../models' -// @ts-ignore -import { GetPatByUsernameResponse } from '../models' -// @ts-ignore -import { HTTPValidationError } from '../models' -/** - * PersonalAccessTokenApi - axios parameter creator - * @export - */ -export const PersonalAccessTokenApiAxiosParamCreator = function ( - configuration?: Configuration -) { - return { - /** - * - * @summary New Personal Access Token - * @param {AccessLevel} [scope] - * @param {number} [timeToLive] - * @param {*} [options] Override http request option. - * @throws {RequiredError} - */ - createToken: async ( - scope?: AccessLevel, - timeToLive?: number, - options: any = {} - ): Promise => { - const localVarPath = `/api/v1/token` - // use dummy base URL string because the URL constructor only accepts absolute URLs. - const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL) - let baseOptions - if (configuration) { - baseOptions = configuration.baseOptions - } - - const localVarRequestOptions = { - method: 'POST', - ...baseOptions, - ...options, - } - const localVarHeaderParameter = {} as any - const localVarQueryParameter = {} as any - - // authentication OAuth2AuthorizationCodeBearer required - // oauth required - await setOAuthToObject( - localVarHeaderParameter, - 'OAuth2AuthorizationCodeBearer', - [], - configuration - ) - - if (scope !== undefined) { - localVarQueryParameter['scope'] = scope - } - - if (timeToLive !== undefined) { - localVarQueryParameter['time_to_live'] = timeToLive - } - - setSearchParams(localVarUrlObj, localVarQueryParameter, options.query) - let headersFromBaseOptions = - baseOptions && baseOptions.headers ? baseOptions.headers : {} - localVarRequestOptions.headers = { - ...localVarHeaderParameter, - ...headersFromBaseOptions, - ...options.headers, - } - - return { - url: toPathString(localVarUrlObj), - options: localVarRequestOptions, - } - }, - /** - * - * @summary Revoke Personal Access Token - * @param {string} tokenId - * @param {*} [options] Override http request option. - * @throws {RequiredError} - */ - tokenDelete: async ( - tokenId: string, - options: any = {} - ): Promise => { - // verify required parameter 'tokenId' is not null or undefined - assertParamExists('tokenDelete', 'tokenId', tokenId) - const localVarPath = `/api/v1/token/token/{token_id}`.replace( - `{${'token_id'}}`, - encodeURIComponent(String(tokenId)) - ) - // use dummy base URL string because the URL constructor only accepts absolute URLs. - const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL) - let baseOptions - if (configuration) { - baseOptions = configuration.baseOptions - } - - const localVarRequestOptions = { - method: 'DELETE', - ...baseOptions, - ...options, - } - const localVarHeaderParameter = {} as any - const localVarQueryParameter = {} as any - - // authentication OAuth2AuthorizationCodeBearer required - // oauth required - await setOAuthToObject( - localVarHeaderParameter, - 'OAuth2AuthorizationCodeBearer', - [], - configuration - ) - - setSearchParams(localVarUrlObj, localVarQueryParameter, options.query) - let headersFromBaseOptions = - baseOptions && baseOptions.headers ? baseOptions.headers : {} - localVarRequestOptions.headers = { - ...localVarHeaderParameter, - ...headersFromBaseOptions, - ...options.headers, - } - - return { - url: toPathString(localVarUrlObj), - options: localVarRequestOptions, - } - }, - /** - * - * @summary List All Pats - * @param {*} [options] Override http request option. - * @throws {RequiredError} - */ - tokenListAll: async (options: any = {}): Promise => { - const localVarPath = `/api/v1/token/token` - // use dummy base URL string because the URL constructor only accepts absolute URLs. - const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL) - let baseOptions - if (configuration) { - baseOptions = configuration.baseOptions - } - - const localVarRequestOptions = { - method: 'GET', - ...baseOptions, - ...options, - } - const localVarHeaderParameter = {} as any - const localVarQueryParameter = {} as any - - // authentication OAuth2AuthorizationCodeBearer required - // oauth required - await setOAuthToObject( - localVarHeaderParameter, - 'OAuth2AuthorizationCodeBearer', - [], - configuration - ) - - setSearchParams(localVarUrlObj, localVarQueryParameter, options.query) - let headersFromBaseOptions = - baseOptions && baseOptions.headers ? baseOptions.headers : {} - localVarRequestOptions.headers = { - ...localVarHeaderParameter, - ...headersFromBaseOptions, - ...options.headers, - } - - return { - url: toPathString(localVarUrlObj), - options: localVarRequestOptions, - } - }, - } -} - -/** - * PersonalAccessTokenApi - functional programming interface - * @export - */ -export const PersonalAccessTokenApiFp = function ( - configuration?: Configuration -) { - const localVarAxiosParamCreator = - PersonalAccessTokenApiAxiosParamCreator(configuration) - return { - /** - * - * @summary New Personal Access Token - * @param {AccessLevel} [scope] - * @param {number} [timeToLive] - * @param {*} [options] Override http request option. - * @throws {RequiredError} - */ - async createToken( - scope?: AccessLevel, - timeToLive?: number, - options?: any - ): Promise< - (axios?: AxiosInstance, basePath?: string) => AxiosPromise - > { - const localVarAxiosArgs = await localVarAxiosParamCreator.createToken( - scope, - timeToLive, - options - ) - return createRequestFunction( - localVarAxiosArgs, - globalAxios, - BASE_PATH, - configuration - ) - }, - /** - * - * @summary Revoke Personal Access Token - * @param {string} tokenId - * @param {*} [options] Override http request option. - * @throws {RequiredError} - */ - async tokenDelete( - tokenId: string, - options?: any - ): Promise< - ( - axios?: AxiosInstance, - basePath?: string - ) => AxiosPromise - > { - const localVarAxiosArgs = await localVarAxiosParamCreator.tokenDelete( - tokenId, - options - ) - return createRequestFunction( - localVarAxiosArgs, - globalAxios, - BASE_PATH, - configuration - ) - }, - /** - * - * @summary List All Pats - * @param {*} [options] Override http request option. - * @throws {RequiredError} - */ - async tokenListAll( - options?: any - ): Promise< - ( - axios?: AxiosInstance, - basePath?: string - ) => AxiosPromise - > { - const localVarAxiosArgs = await localVarAxiosParamCreator.tokenListAll( - options - ) - return createRequestFunction( - localVarAxiosArgs, - globalAxios, - BASE_PATH, - configuration - ) - }, - } -} - -/** - * PersonalAccessTokenApi - factory interface - * @export - */ -export const PersonalAccessTokenApiFactory = function ( - configuration?: Configuration, - basePath?: string, - axios?: AxiosInstance -) { - const localVarFp = PersonalAccessTokenApiFp(configuration) - return { - /** - * - * @summary New Personal Access Token - * @param {AccessLevel} [scope] - * @param {number} [timeToLive] - * @param {*} [options] Override http request option. - * @throws {RequiredError} - */ - createToken( - scope?: AccessLevel, - timeToLive?: number, - options?: any - ): AxiosPromise { - return localVarFp - .createToken(scope, timeToLive, options) - .then((request) => request(axios, basePath)) - }, - /** - * - * @summary Revoke Personal Access Token - * @param {string} tokenId - * @param {*} [options] Override http request option. - * @throws {RequiredError} - */ - tokenDelete( - tokenId: string, - options?: any - ): AxiosPromise { - return localVarFp - .tokenDelete(tokenId, options) - .then((request) => request(axios, basePath)) - }, - /** - * - * @summary List All Pats - * @param {*} [options] Override http request option. - * @throws {RequiredError} - */ - tokenListAll(options?: any): AxiosPromise { - return localVarFp - .tokenListAll(options) - .then((request) => request(axios, basePath)) - }, - } -} - -/** - * Request parameters for createToken operation in PersonalAccessTokenApi. - * @export - * @interface PersonalAccessTokenApiCreateTokenRequest - */ -export interface PersonalAccessTokenApiCreateTokenRequest { - /** - * - * @type {AccessLevel} - * @memberof PersonalAccessTokenApiCreateToken - */ - readonly scope?: AccessLevel - - /** - * - * @type {number} - * @memberof PersonalAccessTokenApiCreateToken - */ - readonly timeToLive?: number -} - -/** - * Request parameters for tokenDelete operation in PersonalAccessTokenApi. - * @export - * @interface PersonalAccessTokenApiTokenDeleteRequest - */ -export interface PersonalAccessTokenApiTokenDeleteRequest { - /** - * - * @type {string} - * @memberof PersonalAccessTokenApiTokenDelete - */ - readonly tokenId: string -} - -/** - * PersonalAccessTokenApi - object-oriented interface - * @export - * @class PersonalAccessTokenApi - * @extends {BaseAPI} - */ -export class PersonalAccessTokenApi extends BaseAPI { - /** - * - * @summary New Personal Access Token - * @param {PersonalAccessTokenApiCreateTokenRequest} requestParameters Request parameters. - * @param {*} [options] Override http request option. - * @throws {RequiredError} - * @memberof PersonalAccessTokenApi - */ - public createToken( - requestParameters: PersonalAccessTokenApiCreateTokenRequest = {}, - options?: any - ) { - return PersonalAccessTokenApiFp(this.configuration) - .createToken( - requestParameters.scope, - requestParameters.timeToLive, - options - ) - .then((request) => request(this.axios, this.basePath)) - } - - /** - * - * @summary Revoke Personal Access Token - * @param {PersonalAccessTokenApiTokenDeleteRequest} requestParameters Request parameters. - * @param {*} [options] Override http request option. - * @throws {RequiredError} - * @memberof PersonalAccessTokenApi - */ - public tokenDelete( - requestParameters: PersonalAccessTokenApiTokenDeleteRequest, - options?: any - ) { - return PersonalAccessTokenApiFp(this.configuration) - .tokenDelete(requestParameters.tokenId, options) - .then((request) => request(this.axios, this.basePath)) - } - - /** - * - * @summary List All Pats - * @param {*} [options] Override http request option. - * @throws {RequiredError} - * @memberof PersonalAccessTokenApi - */ - public tokenListAll(options?: any) { - return PersonalAccessTokenApiFp(this.configuration) - .tokenListAll(options) - .then((request) => request(this.axios, this.basePath)) - } -} diff --git a/web/src/api/generated/api/todos-api.ts b/web/src/api/generated/api/todos-api.ts index 4602732e..214eb34f 100644 --- a/web/src/api/generated/api/todos-api.ts +++ b/web/src/api/generated/api/todos-api.ts @@ -2,9 +2,9 @@ /* eslint-disable */ /** * Template FastAPI React - * ### Description A RESTful API for handling todo items. Anyone in Equinor are authorized to run these calculations. * Click **Authorize** to login and start testing. ### Resources * [Docs](https://equinor.github.io/template-fastapi-react/) * [Github](https://github.com/equinor/template-fastapi-react) For questions about usage or expanding the API, create issue on Github or see docs. + * ### Description A RESTful API for handling todo items. Anyone in Equinor are authorized to use the API. * Click **Authorize** to login and start testing. ### Resources * [Docs](https://equinor.github.io/template-fastapi-react/) * [Github](https://github.com/equinor/template-fastapi-react) For questions about usage or expanding the API, create issue on Github or see docs. * - * The version of the OpenAPI document: 1.1.0 + * The version of the OpenAPI document: 1.3.0 * * * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). @@ -13,7 +13,7 @@ */ -import globalAxios, { AxiosPromise, AxiosInstance } from 'axios'; +import globalAxios, { AxiosPromise, AxiosInstance, AxiosRequestConfig } from 'axios'; import { Configuration } from '../configuration'; // Some imports not used depending on template conditions // @ts-ignore @@ -21,21 +21,13 @@ import { DUMMY_BASE_URL, assertParamExists, setApiKeyToObject, setBasicAuthToObj // @ts-ignore import { BASE_PATH, COLLECTION_FORMATS, RequestArgs, BaseAPI, RequiredError } from '../base'; // @ts-ignore -import { AddTodoRequest } from '../models'; -// @ts-ignore -import { AddTodoResponse } from '../models'; -// @ts-ignore -import { DeleteTodoByIdResponse } from '../models'; +import { AddTodo } from '../models'; // @ts-ignore import { ErrorResponse } from '../models'; // @ts-ignore -import { GetTodoAllResponse } from '../models'; -// @ts-ignore -import { GetTodoByIdResponse } from '../models'; +import { TodoItem } from '../models'; // @ts-ignore -import { UpdateTodoRequest } from '../models'; -// @ts-ignore -import { UpdateTodoResponse } from '../models'; +import { UpdateTodo } from '../models'; /** * TodosApi - axios parameter creator * @export @@ -45,13 +37,13 @@ export const TodosApiAxiosParamCreator = function (configuration?: Configuration /** * * @summary Add Todo - * @param {AddTodoRequest} addTodoRequest + * @param {AddTodo} addTodo * @param {*} [options] Override http request option. * @throws {RequiredError} */ - create: async (addTodoRequest: AddTodoRequest, options: any = {}): Promise => { - // verify required parameter 'addTodoRequest' is not null or undefined - assertParamExists('create', 'addTodoRequest', addTodoRequest) + create: async (addTodo: AddTodo, options: AxiosRequestConfig = {}): Promise => { + // verify required parameter 'addTodo' is not null or undefined + assertParamExists('create', 'addTodo', addTodo) const localVarPath = `/todos`; // use dummy base URL string because the URL constructor only accepts absolute URLs. const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL); @@ -72,10 +64,10 @@ export const TodosApiAxiosParamCreator = function (configuration?: Configuration localVarHeaderParameter['Content-Type'] = 'application/json'; - setSearchParams(localVarUrlObj, localVarQueryParameter, options.query); + setSearchParams(localVarUrlObj, localVarQueryParameter); let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {}; localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers}; - localVarRequestOptions.data = serializeDataIfNeeded(addTodoRequest, localVarRequestOptions, configuration) + localVarRequestOptions.data = serializeDataIfNeeded(addTodo, localVarRequestOptions, configuration) return { url: toPathString(localVarUrlObj), @@ -89,7 +81,7 @@ export const TodosApiAxiosParamCreator = function (configuration?: Configuration * @param {*} [options] Override http request option. * @throws {RequiredError} */ - deleteById: async (id: string, options: any = {}): Promise => { + deleteById: async (id: string, options: AxiosRequestConfig = {}): Promise => { // verify required parameter 'id' is not null or undefined assertParamExists('deleteById', 'id', id) const localVarPath = `/todos/{id}` @@ -111,7 +103,7 @@ export const TodosApiAxiosParamCreator = function (configuration?: Configuration - setSearchParams(localVarUrlObj, localVarQueryParameter, options.query); + setSearchParams(localVarUrlObj, localVarQueryParameter); let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {}; localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers}; @@ -126,7 +118,7 @@ export const TodosApiAxiosParamCreator = function (configuration?: Configuration * @param {*} [options] Override http request option. * @throws {RequiredError} */ - getAll: async (options: any = {}): Promise => { + getAll: async (options: AxiosRequestConfig = {}): Promise => { const localVarPath = `/todos`; // use dummy base URL string because the URL constructor only accepts absolute URLs. const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL); @@ -145,7 +137,7 @@ export const TodosApiAxiosParamCreator = function (configuration?: Configuration - setSearchParams(localVarUrlObj, localVarQueryParameter, options.query); + setSearchParams(localVarUrlObj, localVarQueryParameter); let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {}; localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers}; @@ -161,7 +153,7 @@ export const TodosApiAxiosParamCreator = function (configuration?: Configuration * @param {*} [options] Override http request option. * @throws {RequiredError} */ - getById: async (id: string, options: any = {}): Promise => { + getById: async (id: string, options: AxiosRequestConfig = {}): Promise => { // verify required parameter 'id' is not null or undefined assertParamExists('getById', 'id', id) const localVarPath = `/todos/{id}` @@ -183,7 +175,7 @@ export const TodosApiAxiosParamCreator = function (configuration?: Configuration - setSearchParams(localVarUrlObj, localVarQueryParameter, options.query); + setSearchParams(localVarUrlObj, localVarQueryParameter); let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {}; localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers}; @@ -196,15 +188,15 @@ export const TodosApiAxiosParamCreator = function (configuration?: Configuration * * @summary Update Todo * @param {string} id - * @param {UpdateTodoRequest} updateTodoRequest + * @param {UpdateTodo} updateTodo * @param {*} [options] Override http request option. * @throws {RequiredError} */ - updateById: async (id: string, updateTodoRequest: UpdateTodoRequest, options: any = {}): Promise => { + updateById: async (id: string, updateTodo: UpdateTodo, options: AxiosRequestConfig = {}): Promise => { // verify required parameter 'id' is not null or undefined assertParamExists('updateById', 'id', id) - // verify required parameter 'updateTodoRequest' is not null or undefined - assertParamExists('updateById', 'updateTodoRequest', updateTodoRequest) + // verify required parameter 'updateTodo' is not null or undefined + assertParamExists('updateById', 'updateTodo', updateTodo) const localVarPath = `/todos/{id}` .replace(`{${"id"}}`, encodeURIComponent(String(id))); // use dummy base URL string because the URL constructor only accepts absolute URLs. @@ -226,10 +218,10 @@ export const TodosApiAxiosParamCreator = function (configuration?: Configuration localVarHeaderParameter['Content-Type'] = 'application/json'; - setSearchParams(localVarUrlObj, localVarQueryParameter, options.query); + setSearchParams(localVarUrlObj, localVarQueryParameter); let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {}; localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers}; - localVarRequestOptions.data = serializeDataIfNeeded(updateTodoRequest, localVarRequestOptions, configuration) + localVarRequestOptions.data = serializeDataIfNeeded(updateTodo, localVarRequestOptions, configuration) return { url: toPathString(localVarUrlObj), @@ -249,12 +241,12 @@ export const TodosApiFp = function(configuration?: Configuration) { /** * * @summary Add Todo - * @param {AddTodoRequest} addTodoRequest + * @param {AddTodo} addTodo * @param {*} [options] Override http request option. * @throws {RequiredError} */ - async create(addTodoRequest: AddTodoRequest, options?: any): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise> { - const localVarAxiosArgs = await localVarAxiosParamCreator.create(addTodoRequest, options); + async create(addTodo: AddTodo, options?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise> { + const localVarAxiosArgs = await localVarAxiosParamCreator.create(addTodo, options); return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration); }, /** @@ -264,7 +256,7 @@ export const TodosApiFp = function(configuration?: Configuration) { * @param {*} [options] Override http request option. * @throws {RequiredError} */ - async deleteById(id: string, options?: any): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise> { + async deleteById(id: string, options?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise> { const localVarAxiosArgs = await localVarAxiosParamCreator.deleteById(id, options); return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration); }, @@ -274,7 +266,7 @@ export const TodosApiFp = function(configuration?: Configuration) { * @param {*} [options] Override http request option. * @throws {RequiredError} */ - async getAll(options?: any): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise>> { + async getAll(options?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise>> { const localVarAxiosArgs = await localVarAxiosParamCreator.getAll(options); return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration); }, @@ -285,7 +277,7 @@ export const TodosApiFp = function(configuration?: Configuration) { * @param {*} [options] Override http request option. * @throws {RequiredError} */ - async getById(id: string, options?: any): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise> { + async getById(id: string, options?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise> { const localVarAxiosArgs = await localVarAxiosParamCreator.getById(id, options); return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration); }, @@ -293,12 +285,12 @@ export const TodosApiFp = function(configuration?: Configuration) { * * @summary Update Todo * @param {string} id - * @param {UpdateTodoRequest} updateTodoRequest + * @param {UpdateTodo} updateTodo * @param {*} [options] Override http request option. * @throws {RequiredError} */ - async updateById(id: string, updateTodoRequest: UpdateTodoRequest, options?: any): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise> { - const localVarAxiosArgs = await localVarAxiosParamCreator.updateById(id, updateTodoRequest, options); + async updateById(id: string, updateTodo: UpdateTodo, options?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise> { + const localVarAxiosArgs = await localVarAxiosParamCreator.updateById(id, updateTodo, options); return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration); }, } @@ -314,12 +306,12 @@ export const TodosApiFactory = function (configuration?: Configuration, basePath /** * * @summary Add Todo - * @param {AddTodoRequest} addTodoRequest + * @param {AddTodo} addTodo * @param {*} [options] Override http request option. * @throws {RequiredError} */ - create(addTodoRequest: AddTodoRequest, options?: any): AxiosPromise { - return localVarFp.create(addTodoRequest, options).then((request) => request(axios, basePath)); + create(addTodo: AddTodo, options?: any): AxiosPromise { + return localVarFp.create(addTodo, options).then((request) => request(axios, basePath)); }, /** * @@ -328,7 +320,7 @@ export const TodosApiFactory = function (configuration?: Configuration, basePath * @param {*} [options] Override http request option. * @throws {RequiredError} */ - deleteById(id: string, options?: any): AxiosPromise { + deleteById(id: string, options?: any): AxiosPromise { return localVarFp.deleteById(id, options).then((request) => request(axios, basePath)); }, /** @@ -337,7 +329,7 @@ export const TodosApiFactory = function (configuration?: Configuration, basePath * @param {*} [options] Override http request option. * @throws {RequiredError} */ - getAll(options?: any): AxiosPromise> { + getAll(options?: any): AxiosPromise> { return localVarFp.getAll(options).then((request) => request(axios, basePath)); }, /** @@ -347,86 +339,23 @@ export const TodosApiFactory = function (configuration?: Configuration, basePath * @param {*} [options] Override http request option. * @throws {RequiredError} */ - getById(id: string, options?: any): AxiosPromise { + getById(id: string, options?: any): AxiosPromise { return localVarFp.getById(id, options).then((request) => request(axios, basePath)); }, /** * * @summary Update Todo * @param {string} id - * @param {UpdateTodoRequest} updateTodoRequest + * @param {UpdateTodo} updateTodo * @param {*} [options] Override http request option. * @throws {RequiredError} */ - updateById(id: string, updateTodoRequest: UpdateTodoRequest, options?: any): AxiosPromise { - return localVarFp.updateById(id, updateTodoRequest, options).then((request) => request(axios, basePath)); + updateById(id: string, updateTodo: UpdateTodo, options?: any): AxiosPromise { + return localVarFp.updateById(id, updateTodo, options).then((request) => request(axios, basePath)); }, }; }; -/** - * Request parameters for create operation in TodosApi. - * @export - * @interface TodosApiCreateRequest - */ -export interface TodosApiCreateRequest { - /** - * - * @type {AddTodoRequest} - * @memberof TodosApiCreate - */ - readonly addTodoRequest: AddTodoRequest -} - -/** - * Request parameters for deleteById operation in TodosApi. - * @export - * @interface TodosApiDeleteByIdRequest - */ -export interface TodosApiDeleteByIdRequest { - /** - * - * @type {string} - * @memberof TodosApiDeleteById - */ - readonly id: string -} - -/** - * Request parameters for getById operation in TodosApi. - * @export - * @interface TodosApiGetByIdRequest - */ -export interface TodosApiGetByIdRequest { - /** - * - * @type {string} - * @memberof TodosApiGetById - */ - readonly id: string -} - -/** - * Request parameters for updateById operation in TodosApi. - * @export - * @interface TodosApiUpdateByIdRequest - */ -export interface TodosApiUpdateByIdRequest { - /** - * - * @type {string} - * @memberof TodosApiUpdateById - */ - readonly id: string - - /** - * - * @type {UpdateTodoRequest} - * @memberof TodosApiUpdateById - */ - readonly updateTodoRequest: UpdateTodoRequest -} - /** * TodosApi - object-oriented interface * @export @@ -437,25 +366,25 @@ export class TodosApi extends BaseAPI { /** * * @summary Add Todo - * @param {TodosApiCreateRequest} requestParameters Request parameters. + * @param {AddTodo} addTodo * @param {*} [options] Override http request option. * @throws {RequiredError} * @memberof TodosApi */ - public create(requestParameters: TodosApiCreateRequest, options?: any) { - return TodosApiFp(this.configuration).create(requestParameters.addTodoRequest, options).then((request) => request(this.axios, this.basePath)); + public create(addTodo: AddTodo, options?: AxiosRequestConfig) { + return TodosApiFp(this.configuration).create(addTodo, options).then((request) => request(this.axios, this.basePath)); } /** * * @summary Delete Todo By Id - * @param {TodosApiDeleteByIdRequest} requestParameters Request parameters. + * @param {string} id * @param {*} [options] Override http request option. * @throws {RequiredError} * @memberof TodosApi */ - public deleteById(requestParameters: TodosApiDeleteByIdRequest, options?: any) { - return TodosApiFp(this.configuration).deleteById(requestParameters.id, options).then((request) => request(this.axios, this.basePath)); + public deleteById(id: string, options?: AxiosRequestConfig) { + return TodosApiFp(this.configuration).deleteById(id, options).then((request) => request(this.axios, this.basePath)); } /** @@ -465,31 +394,32 @@ export class TodosApi extends BaseAPI { * @throws {RequiredError} * @memberof TodosApi */ - public getAll(options?: any) { + public getAll(options?: AxiosRequestConfig) { return TodosApiFp(this.configuration).getAll(options).then((request) => request(this.axios, this.basePath)); } /** * * @summary Get Todo By Id - * @param {TodosApiGetByIdRequest} requestParameters Request parameters. + * @param {string} id * @param {*} [options] Override http request option. * @throws {RequiredError} * @memberof TodosApi */ - public getById(requestParameters: TodosApiGetByIdRequest, options?: any) { - return TodosApiFp(this.configuration).getById(requestParameters.id, options).then((request) => request(this.axios, this.basePath)); + public getById(id: string, options?: AxiosRequestConfig) { + return TodosApiFp(this.configuration).getById(id, options).then((request) => request(this.axios, this.basePath)); } /** * * @summary Update Todo - * @param {TodosApiUpdateByIdRequest} requestParameters Request parameters. + * @param {string} id + * @param {UpdateTodo} updateTodo * @param {*} [options] Override http request option. * @throws {RequiredError} * @memberof TodosApi */ - public updateById(requestParameters: TodosApiUpdateByIdRequest, options?: any) { - return TodosApiFp(this.configuration).updateById(requestParameters.id, requestParameters.updateTodoRequest, options).then((request) => request(this.axios, this.basePath)); + public updateById(id: string, updateTodo: UpdateTodo, options?: AxiosRequestConfig) { + return TodosApiFp(this.configuration).updateById(id, updateTodo, options).then((request) => request(this.axios, this.basePath)); } } diff --git a/web/src/api/generated/api/whoami-api.ts b/web/src/api/generated/api/whoami-api.ts index c20ed6af..596b51fa 100644 --- a/web/src/api/generated/api/whoami-api.ts +++ b/web/src/api/generated/api/whoami-api.ts @@ -2,9 +2,9 @@ /* eslint-disable */ /** * Template FastAPI React - * ### Description A RESTful API for handling todo items. Anyone in Equinor are authorized to run these calculations. * Click **Authorize** to login and start testing. ### Resources * [Docs](https://equinor.github.io/template-fastapi-react/) * [Github](https://github.com/equinor/template-fastapi-react) For questions about usage or expanding the API, create issue on Github or see docs. + * ### Description A RESTful API for handling todo items. Anyone in Equinor are authorized to use the API. * Click **Authorize** to login and start testing. ### Resources * [Docs](https://equinor.github.io/template-fastapi-react/) * [Github](https://github.com/equinor/template-fastapi-react) For questions about usage or expanding the API, create issue on Github or see docs. * - * The version of the OpenAPI document: 1.1.0 + * The version of the OpenAPI document: 1.3.0 * * * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). @@ -13,7 +13,7 @@ */ -import globalAxios, { AxiosPromise, AxiosInstance } from 'axios'; +import globalAxios, { AxiosPromise, AxiosInstance, AxiosRequestConfig } from 'axios'; import { Configuration } from '../configuration'; // Some imports not used depending on template conditions // @ts-ignore @@ -34,7 +34,7 @@ export const WhoamiApiAxiosParamCreator = function (configuration?: Configuratio * @param {*} [options] Override http request option. * @throws {RequiredError} */ - whoami: async (options: any = {}): Promise => { + whoami: async (options: AxiosRequestConfig = {}): Promise => { const localVarPath = `/whoami`; // use dummy base URL string because the URL constructor only accepts absolute URLs. const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL); @@ -53,7 +53,7 @@ export const WhoamiApiAxiosParamCreator = function (configuration?: Configuratio - setSearchParams(localVarUrlObj, localVarQueryParameter, options.query); + setSearchParams(localVarUrlObj, localVarQueryParameter); let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {}; localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers}; @@ -78,7 +78,7 @@ export const WhoamiApiFp = function(configuration?: Configuration) { * @param {*} [options] Override http request option. * @throws {RequiredError} */ - async whoami(options?: any): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise> { + async whoami(options?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise> { const localVarAxiosArgs = await localVarAxiosParamCreator.whoami(options); return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration); }, @@ -118,7 +118,7 @@ export class WhoamiApi extends BaseAPI { * @throws {RequiredError} * @memberof WhoamiApi */ - public whoami(options?: any) { + public whoami(options?: AxiosRequestConfig) { return WhoamiApiFp(this.configuration).whoami(options).then((request) => request(this.axios, this.basePath)); } } diff --git a/web/src/api/generated/base.ts b/web/src/api/generated/base.ts index 1e702006..f5bd8e9f 100644 --- a/web/src/api/generated/base.ts +++ b/web/src/api/generated/base.ts @@ -2,9 +2,9 @@ /* eslint-disable */ /** * Template FastAPI React - * ### Description A RESTful API for handling todo items. Anyone in Equinor are authorized to run these calculations. * Click **Authorize** to login and start testing. ### Resources * [Docs](https://equinor.github.io/template-fastapi-react/) * [Github](https://github.com/equinor/template-fastapi-react) For questions about usage or expanding the API, create issue on Github or see docs. + * ### Description A RESTful API for handling todo items. Anyone in Equinor are authorized to use the API. * Click **Authorize** to login and start testing. ### Resources * [Docs](https://equinor.github.io/template-fastapi-react/) * [Github](https://github.com/equinor/template-fastapi-react) For questions about usage or expanding the API, create issue on Github or see docs. * - * The version of the OpenAPI document: 1.1.0 + * The version of the OpenAPI document: 1.3.0 * * * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). @@ -16,7 +16,7 @@ import { Configuration } from "./configuration"; // Some imports not used depending on template conditions // @ts-ignore -import globalAxios, { AxiosPromise, AxiosInstance } from 'axios'; +import globalAxios, { AxiosPromise, AxiosInstance, AxiosRequestConfig } from 'axios'; export const BASE_PATH = "http://127.0.0.1:5000/api".replace(/\/+$/, ""); @@ -38,7 +38,7 @@ export const COLLECTION_FORMATS = { */ export interface RequestArgs { url: string; - options: any; + options: AxiosRequestConfig; } /** diff --git a/web/src/api/generated/common.ts b/web/src/api/generated/common.ts index e17affb3..6ff9f89c 100644 --- a/web/src/api/generated/common.ts +++ b/web/src/api/generated/common.ts @@ -2,9 +2,9 @@ /* eslint-disable */ /** * Template FastAPI React - * ### Description A RESTful API for handling todo items. Anyone in Equinor are authorized to run these calculations. * Click **Authorize** to login and start testing. ### Resources * [Docs](https://equinor.github.io/template-fastapi-react/) * [Github](https://github.com/equinor/template-fastapi-react) For questions about usage or expanding the API, create issue on Github or see docs. + * ### Description A RESTful API for handling todo items. Anyone in Equinor are authorized to use the API. * Click **Authorize** to login and start testing. ### Resources * [Docs](https://equinor.github.io/template-fastapi-react/) * [Github](https://github.com/equinor/template-fastapi-react) For questions about usage or expanding the API, create issue on Github or see docs. * - * The version of the OpenAPI document: 1.1.0 + * The version of the OpenAPI document: 1.3.0 * * * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). @@ -14,8 +14,8 @@ import { Configuration } from "./configuration"; -import { RequiredError, RequestArgs } from "./base"; -import { AxiosInstance } from 'axios'; +import { RequiredError, RequestArgs } from "./base"; +import { AxiosInstance, AxiosResponse } from 'axios'; /** * @@ -83,24 +83,34 @@ export const setOAuthToObject = async function (object: any, name: string, scope } } +function setFlattenedQueryParams(urlSearchParams: URLSearchParams, parameter: any, key: string = ""): void { + if (typeof parameter === "object") { + if (Array.isArray(parameter)) { + (parameter as any[]).forEach(item => setFlattenedQueryParams(urlSearchParams, item, key)); + } + else { + Object.keys(parameter).forEach(currentKey => + setFlattenedQueryParams(urlSearchParams, parameter[currentKey], `${key}${key !== '' ? '.' : ''}${currentKey}`) + ); + } + } + else { + if (urlSearchParams.has(key)) { + urlSearchParams.append(key, parameter); + } + else { + urlSearchParams.set(key, parameter); + } + } +} + /** * * @export */ export const setSearchParams = function (url: URL, ...objects: any[]) { const searchParams = new URLSearchParams(url.search); - for (const object of objects) { - for (const key in object) { - if (Array.isArray(object[key])) { - searchParams.delete(key); - for (const item of object[key]) { - searchParams.append(key, item); - } - } else { - searchParams.set(key, object[key]); - } - } - } + setFlattenedQueryParams(searchParams, objects); url.search = searchParams.toString(); } @@ -131,8 +141,8 @@ export const toPathString = function (url: URL) { * @export */ export const createRequestFunction = function (axiosArgs: RequestArgs, globalAxios: AxiosInstance, BASE_PATH: string, configuration?: Configuration) { - return (axios: AxiosInstance = globalAxios, basePath: string = BASE_PATH) => { + return >(axios: AxiosInstance = globalAxios, basePath: string = BASE_PATH) => { const axiosRequestArgs = {...axiosArgs.options, url: (configuration?.basePath || basePath) + axiosArgs.url}; - return axios.request(axiosRequestArgs); + return axios.request(axiosRequestArgs); }; } diff --git a/web/src/api/generated/configuration.ts b/web/src/api/generated/configuration.ts index 0839251f..f440e35a 100644 --- a/web/src/api/generated/configuration.ts +++ b/web/src/api/generated/configuration.ts @@ -2,9 +2,9 @@ /* eslint-disable */ /** * Template FastAPI React - * ### Description A RESTful API for handling todo items. Anyone in Equinor are authorized to run these calculations. * Click **Authorize** to login and start testing. ### Resources * [Docs](https://equinor.github.io/template-fastapi-react/) * [Github](https://github.com/equinor/template-fastapi-react) For questions about usage or expanding the API, create issue on Github or see docs. + * ### Description A RESTful API for handling todo items. Anyone in Equinor are authorized to use the API. * Click **Authorize** to login and start testing. ### Resources * [Docs](https://equinor.github.io/template-fastapi-react/) * [Github](https://github.com/equinor/template-fastapi-react) For questions about usage or expanding the API, create issue on Github or see docs. * - * The version of the OpenAPI document: 1.1.0 + * The version of the OpenAPI document: 1.3.0 * * * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). diff --git a/web/src/api/generated/git_push.sh b/web/src/api/generated/git_push.sh index ced3be2b..f53a75d4 100644 --- a/web/src/api/generated/git_push.sh +++ b/web/src/api/generated/git_push.sh @@ -1,7 +1,7 @@ #!/bin/sh # ref: https://help.github.com/articles/adding-an-existing-project-to-github-using-the-command-line/ # -# Usage example: /bin/sh ./git_push.sh wing328 openapi-pestore-perl "minor update" "gitlab.com" +# Usage example: /bin/sh ./git_push.sh wing328 openapi-petstore-perl "minor update" "gitlab.com" git_user_id=$1 git_repo_id=$2 @@ -38,14 +38,14 @@ git add . git commit -m "$release_note" # Sets the new remote -git_remote=`git remote` +git_remote=$(git remote) if [ "$git_remote" = "" ]; then # git remote not defined if [ "$GIT_TOKEN" = "" ]; then echo "[INFO] \$GIT_TOKEN (environment variable) is not set. Using the git credential in your environment." git remote add origin https://${git_host}/${git_user_id}/${git_repo_id}.git else - git remote add origin https://${git_user_id}:${GIT_TOKEN}@${git_host}/${git_user_id}/${git_repo_id}.git + git remote add origin https://${git_user_id}:"${GIT_TOKEN}"@${git_host}/${git_user_id}/${git_repo_id}.git fi fi @@ -55,4 +55,3 @@ git pull origin master # Pushes (Forces) the changes in the local repository up to the remote repository echo "Git pushing to https://${git_host}/${git_user_id}/${git_repo_id}.git" git push origin master 2>&1 | grep -v 'To https' - diff --git a/web/src/api/generated/index.ts b/web/src/api/generated/index.ts index 530ea503..b540f711 100644 --- a/web/src/api/generated/index.ts +++ b/web/src/api/generated/index.ts @@ -2,9 +2,9 @@ /* eslint-disable */ /** * Template FastAPI React - * ### Description A RESTful API for handling todo items. Anyone in Equinor are authorized to run these calculations. * Click **Authorize** to login and start testing. ### Resources * [Docs](https://equinor.github.io/template-fastapi-react/) * [Github](https://github.com/equinor/template-fastapi-react) For questions about usage or expanding the API, create issue on Github or see docs. + * ### Description A RESTful API for handling todo items. Anyone in Equinor are authorized to use the API. * Click **Authorize** to login and start testing. ### Resources * [Docs](https://equinor.github.io/template-fastapi-react/) * [Github](https://github.com/equinor/template-fastapi-react) For questions about usage or expanding the API, create issue on Github or see docs. * - * The version of the OpenAPI document: 1.1.0 + * The version of the OpenAPI document: 1.3.0 * * * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). diff --git a/web/src/api/generated/models/access-level.ts b/web/src/api/generated/models/access-level.ts deleted file mode 100644 index 86df01a6..00000000 --- a/web/src/api/generated/models/access-level.ts +++ /dev/null @@ -1,24 +0,0 @@ -/* tslint:disable */ -/* eslint-disable */ -/** - * Boilerplate - * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) - * - * The version of the OpenAPI document: 0.1.0 - * - * - * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). - * https://openapi-generator.tech - * Do not edit the class manually. - */ - -/** - * An enumeration. - * @export - * @enum {string} - */ -export enum AccessLevel { - WRITE = 2, - READ = 1, - NONE = 0, -} diff --git a/web/src/api/generated/models/add-todo-request.ts b/web/src/api/generated/models/add-todo-request.ts deleted file mode 100644 index df7b5cbf..00000000 --- a/web/src/api/generated/models/add-todo-request.ts +++ /dev/null @@ -1,31 +0,0 @@ -/* tslint:disable */ -/* eslint-disable */ -/** - * Template FastAPI React - * ### Description A RESTful API for handling todo items. Anyone in Equinor are authorized to run these calculations. * Click **Authorize** to login and start testing. ### Resources * [Docs](https://equinor.github.io/template-fastapi-react/) * [Github](https://github.com/equinor/template-fastapi-react) For questions about usage or expanding the API, create issue on Github or see docs. - * - * The version of the OpenAPI document: 1.1.0 - * - * - * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). - * https://openapi-generator.tech - * Do not edit the class manually. - */ - - - -/** - * - * @export - * @interface AddTodoRequest - */ -export interface AddTodoRequest { - /** - * - * @type {string} - * @memberof AddTodoRequest - */ - title?: string; -} - - diff --git a/web/src/api/generated/models/add-todo-response.ts b/web/src/api/generated/models/add-todo-response.ts deleted file mode 100644 index 7fb60a77..00000000 --- a/web/src/api/generated/models/add-todo-response.ts +++ /dev/null @@ -1,43 +0,0 @@ -/* tslint:disable */ -/* eslint-disable */ -/** - * Template FastAPI React - * ### Description A RESTful API for handling todo items. Anyone in Equinor are authorized to run these calculations. * Click **Authorize** to login and start testing. ### Resources * [Docs](https://equinor.github.io/template-fastapi-react/) * [Github](https://github.com/equinor/template-fastapi-react) For questions about usage or expanding the API, create issue on Github or see docs. - * - * The version of the OpenAPI document: 1.1.0 - * - * - * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). - * https://openapi-generator.tech - * Do not edit the class manually. - */ - - - -/** - * - * @export - * @interface AddTodoResponse - */ -export interface AddTodoResponse { - /** - * - * @type {string} - * @memberof AddTodoResponse - */ - id: string; - /** - * - * @type {string} - * @memberof AddTodoResponse - */ - title: string; - /** - * - * @type {boolean} - * @memberof AddTodoResponse - */ - is_completed?: boolean; -} - - diff --git a/web/src/api/generated/models/add-todo.ts b/web/src/api/generated/models/add-todo.ts new file mode 100644 index 00000000..c3c840aa --- /dev/null +++ b/web/src/api/generated/models/add-todo.ts @@ -0,0 +1,30 @@ +/* tslint:disable */ +/* eslint-disable */ +/** + * Template FastAPI React + * ### Description A RESTful API for handling todo items. Anyone in Equinor are authorized to use the API. * Click **Authorize** to login and start testing. ### Resources * [Docs](https://equinor.github.io/template-fastapi-react/) * [Github](https://github.com/equinor/template-fastapi-react) For questions about usage or expanding the API, create issue on Github or see docs. + * + * The version of the OpenAPI document: 1.3.0 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + + +/** + * + * @export + * @interface AddTodo + */ +export interface AddTodo { + /** + * + * @type {string} + * @memberof AddTodo + */ + 'title': string; +} + diff --git a/web/src/api/generated/models/delete-pat-response.ts b/web/src/api/generated/models/delete-pat-response.ts deleted file mode 100644 index 03ccdd1d..00000000 --- a/web/src/api/generated/models/delete-pat-response.ts +++ /dev/null @@ -1,27 +0,0 @@ -/* tslint:disable */ -/* eslint-disable */ -/** - * Boilerplate - * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) - * - * The version of the OpenAPI document: 0.1.0 - * - * - * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). - * https://openapi-generator.tech - * Do not edit the class manually. - */ - -/** - * - * @export - * @interface DeletePatResponse - */ -export interface DeletePatResponse { - /** - * - * @type {boolean} - * @memberof DeletePatResponse - */ - success: boolean -} diff --git a/web/src/api/generated/models/delete-todo-by-id-response.ts b/web/src/api/generated/models/delete-todo-by-id-response.ts deleted file mode 100644 index 5fc0151a..00000000 --- a/web/src/api/generated/models/delete-todo-by-id-response.ts +++ /dev/null @@ -1,31 +0,0 @@ -/* tslint:disable */ -/* eslint-disable */ -/** - * Template FastAPI React - * ### Description A RESTful API for handling todo items. Anyone in Equinor are authorized to run these calculations. * Click **Authorize** to login and start testing. ### Resources * [Docs](https://equinor.github.io/template-fastapi-react/) * [Github](https://github.com/equinor/template-fastapi-react) For questions about usage or expanding the API, create issue on Github or see docs. - * - * The version of the OpenAPI document: 1.1.0 - * - * - * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). - * https://openapi-generator.tech - * Do not edit the class manually. - */ - - - -/** - * - * @export - * @interface DeleteTodoByIdResponse - */ -export interface DeleteTodoByIdResponse { - /** - * - * @type {boolean} - * @memberof DeleteTodoByIdResponse - */ - success: boolean; -} - - diff --git a/web/src/api/generated/models/error-response.ts b/web/src/api/generated/models/error-response.ts index 6cccf46f..db650609 100644 --- a/web/src/api/generated/models/error-response.ts +++ b/web/src/api/generated/models/error-response.ts @@ -2,9 +2,9 @@ /* eslint-disable */ /** * Template FastAPI React - * ### Description A RESTful API for handling todo items. Anyone in Equinor are authorized to run these calculations. * Click **Authorize** to login and start testing. ### Resources * [Docs](https://equinor.github.io/template-fastapi-react/) * [Github](https://github.com/equinor/template-fastapi-react) For questions about usage or expanding the API, create issue on Github or see docs. + * ### Description A RESTful API for handling todo items. Anyone in Equinor are authorized to use the API. * Click **Authorize** to login and start testing. ### Resources * [Docs](https://equinor.github.io/template-fastapi-react/) * [Github](https://github.com/equinor/template-fastapi-react) For questions about usage or expanding the API, create issue on Github or see docs. * - * The version of the OpenAPI document: 1.1.0 + * The version of the OpenAPI document: 1.3.0 * * * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). @@ -25,31 +25,30 @@ export interface ErrorResponse { * @type {number} * @memberof ErrorResponse */ - status?: number; + 'status'?: number; /** * * @type {string} * @memberof ErrorResponse */ - type?: string; + 'type'?: string; /** * * @type {string} * @memberof ErrorResponse */ - message?: string; + 'message'?: string; /** * * @type {string} * @memberof ErrorResponse */ - debug?: string; + 'debug'?: string; /** * * @type {object} * @memberof ErrorResponse */ - extra?: object; + 'extra'?: object; } - diff --git a/web/src/api/generated/models/get-pat-by-username-response.ts b/web/src/api/generated/models/get-pat-by-username-response.ts deleted file mode 100644 index 7911580d..00000000 --- a/web/src/api/generated/models/get-pat-by-username-response.ts +++ /dev/null @@ -1,33 +0,0 @@ -/* tslint:disable */ -/* eslint-disable */ -/** - * Boilerplate - * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) - * - * The version of the OpenAPI document: 0.1.0 - * - * - * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). - * https://openapi-generator.tech - * Do not edit the class manually. - */ - -/** - * - * @export - * @interface GetPatByUsernameResponse - */ -export interface GetPatByUsernameResponse { - /** - * - * @type {string} - * @memberof GetPatByUsernameResponse - */ - id: string - /** - * - * @type {string} - * @memberof GetPatByUsernameResponse - */ - title: string -} diff --git a/web/src/api/generated/models/get-todo-all-response.ts b/web/src/api/generated/models/get-todo-all-response.ts deleted file mode 100644 index b7f153c3..00000000 --- a/web/src/api/generated/models/get-todo-all-response.ts +++ /dev/null @@ -1,43 +0,0 @@ -/* tslint:disable */ -/* eslint-disable */ -/** - * Template FastAPI React - * ### Description A RESTful API for handling todo items. Anyone in Equinor are authorized to run these calculations. * Click **Authorize** to login and start testing. ### Resources * [Docs](https://equinor.github.io/template-fastapi-react/) * [Github](https://github.com/equinor/template-fastapi-react) For questions about usage or expanding the API, create issue on Github or see docs. - * - * The version of the OpenAPI document: 1.1.0 - * - * - * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). - * https://openapi-generator.tech - * Do not edit the class manually. - */ - - - -/** - * - * @export - * @interface GetTodoAllResponse - */ -export interface GetTodoAllResponse { - /** - * - * @type {string} - * @memberof GetTodoAllResponse - */ - id: string; - /** - * - * @type {string} - * @memberof GetTodoAllResponse - */ - title: string; - /** - * - * @type {boolean} - * @memberof GetTodoAllResponse - */ - is_completed: boolean; -} - - diff --git a/web/src/api/generated/models/get-todo-by-id-response.ts b/web/src/api/generated/models/get-todo-by-id-response.ts deleted file mode 100644 index 34b931c1..00000000 --- a/web/src/api/generated/models/get-todo-by-id-response.ts +++ /dev/null @@ -1,43 +0,0 @@ -/* tslint:disable */ -/* eslint-disable */ -/** - * Template FastAPI React - * ### Description A RESTful API for handling todo items. Anyone in Equinor are authorized to run these calculations. * Click **Authorize** to login and start testing. ### Resources * [Docs](https://equinor.github.io/template-fastapi-react/) * [Github](https://github.com/equinor/template-fastapi-react) For questions about usage or expanding the API, create issue on Github or see docs. - * - * The version of the OpenAPI document: 1.1.0 - * - * - * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). - * https://openapi-generator.tech - * Do not edit the class manually. - */ - - - -/** - * - * @export - * @interface GetTodoByIdResponse - */ -export interface GetTodoByIdResponse { - /** - * - * @type {string} - * @memberof GetTodoByIdResponse - */ - id: string; - /** - * - * @type {string} - * @memberof GetTodoByIdResponse - */ - title: string; - /** - * - * @type {boolean} - * @memberof GetTodoByIdResponse - */ - is_completed?: boolean; -} - - diff --git a/web/src/api/generated/models/httpvalidation-error.ts b/web/src/api/generated/models/httpvalidation-error.ts deleted file mode 100644 index 29a00744..00000000 --- a/web/src/api/generated/models/httpvalidation-error.ts +++ /dev/null @@ -1,29 +0,0 @@ -/* tslint:disable */ -/* eslint-disable */ -/** - * Boilerplate - * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) - * - * The version of the OpenAPI document: 0.1.0 - * - * - * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). - * https://openapi-generator.tech - * Do not edit the class manually. - */ - -import { ValidationError } from './validation-error' - -/** - * - * @export - * @interface HTTPValidationError - */ -export interface HTTPValidationError { - /** - * - * @type {Array} - * @memberof HTTPValidationError - */ - detail?: Array -} diff --git a/web/src/api/generated/models/index.ts b/web/src/api/generated/models/index.ts index 3954695d..d6056586 100644 --- a/web/src/api/generated/models/index.ts +++ b/web/src/api/generated/models/index.ts @@ -1,8 +1,4 @@ -export * from './add-todo-request'; -export * from './add-todo-response'; -export * from './delete-todo-by-id-response'; +export * from './add-todo'; export * from './error-response'; -export * from './get-todo-all-response'; -export * from './get-todo-by-id-response'; -export * from './update-todo-request'; -export * from './update-todo-response'; +export * from './todo-item'; +export * from './update-todo'; diff --git a/web/src/api/generated/models/todo-item.ts b/web/src/api/generated/models/todo-item.ts new file mode 100644 index 00000000..bbad6885 --- /dev/null +++ b/web/src/api/generated/models/todo-item.ts @@ -0,0 +1,42 @@ +/* tslint:disable */ +/* eslint-disable */ +/** + * Template FastAPI React + * ### Description A RESTful API for handling todo items. Anyone in Equinor are authorized to use the API. * Click **Authorize** to login and start testing. ### Resources * [Docs](https://equinor.github.io/template-fastapi-react/) * [Github](https://github.com/equinor/template-fastapi-react) For questions about usage or expanding the API, create issue on Github or see docs. + * + * The version of the OpenAPI document: 1.3.0 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + + +/** + * + * @export + * @interface TodoItem + */ +export interface TodoItem { + /** + * + * @type {string} + * @memberof TodoItem + */ + 'id': string; + /** + * + * @type {string} + * @memberof TodoItem + */ + 'title': string; + /** + * + * @type {boolean} + * @memberof TodoItem + */ + 'is_completed'?: boolean; +} + diff --git a/web/src/api/generated/models/update-todo-request.ts b/web/src/api/generated/models/update-todo-request.ts deleted file mode 100644 index 9a5aae30..00000000 --- a/web/src/api/generated/models/update-todo-request.ts +++ /dev/null @@ -1,37 +0,0 @@ -/* tslint:disable */ -/* eslint-disable */ -/** - * Template FastAPI React - * ### Description A RESTful API for handling todo items. Anyone in Equinor are authorized to run these calculations. * Click **Authorize** to login and start testing. ### Resources * [Docs](https://equinor.github.io/template-fastapi-react/) * [Github](https://github.com/equinor/template-fastapi-react) For questions about usage or expanding the API, create issue on Github or see docs. - * - * The version of the OpenAPI document: 1.1.0 - * - * - * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). - * https://openapi-generator.tech - * Do not edit the class manually. - */ - - - -/** - * - * @export - * @interface UpdateTodoRequest - */ -export interface UpdateTodoRequest { - /** - * - * @type {string} - * @memberof UpdateTodoRequest - */ - title?: string; - /** - * - * @type {boolean} - * @memberof UpdateTodoRequest - */ - is_completed: boolean; -} - - diff --git a/web/src/api/generated/models/update-todo-response.ts b/web/src/api/generated/models/update-todo-response.ts deleted file mode 100644 index 4b7fd830..00000000 --- a/web/src/api/generated/models/update-todo-response.ts +++ /dev/null @@ -1,31 +0,0 @@ -/* tslint:disable */ -/* eslint-disable */ -/** - * Template FastAPI React - * ### Description A RESTful API for handling todo items. Anyone in Equinor are authorized to run these calculations. * Click **Authorize** to login and start testing. ### Resources * [Docs](https://equinor.github.io/template-fastapi-react/) * [Github](https://github.com/equinor/template-fastapi-react) For questions about usage or expanding the API, create issue on Github or see docs. - * - * The version of the OpenAPI document: 1.1.0 - * - * - * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). - * https://openapi-generator.tech - * Do not edit the class manually. - */ - - - -/** - * - * @export - * @interface UpdateTodoResponse - */ -export interface UpdateTodoResponse { - /** - * - * @type {boolean} - * @memberof UpdateTodoResponse - */ - success: boolean; -} - - diff --git a/web/src/api/generated/models/update-todo.ts b/web/src/api/generated/models/update-todo.ts new file mode 100644 index 00000000..dd727fb1 --- /dev/null +++ b/web/src/api/generated/models/update-todo.ts @@ -0,0 +1,36 @@ +/* tslint:disable */ +/* eslint-disable */ +/** + * Template FastAPI React + * ### Description A RESTful API for handling todo items. Anyone in Equinor are authorized to use the API. * Click **Authorize** to login and start testing. ### Resources * [Docs](https://equinor.github.io/template-fastapi-react/) * [Github](https://github.com/equinor/template-fastapi-react) For questions about usage or expanding the API, create issue on Github or see docs. + * + * The version of the OpenAPI document: 1.3.0 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + + +/** + * + * @export + * @interface UpdateTodo + */ +export interface UpdateTodo { + /** + * + * @type {string} + * @memberof UpdateTodo + */ + 'title': string; + /** + * + * @type {boolean} + * @memberof UpdateTodo + */ + 'is_completed'?: boolean; +} + diff --git a/web/src/api/generated/models/validation-error.ts b/web/src/api/generated/models/validation-error.ts deleted file mode 100644 index b902a124..00000000 --- a/web/src/api/generated/models/validation-error.ts +++ /dev/null @@ -1,39 +0,0 @@ -/* tslint:disable */ -/* eslint-disable */ -/** - * Boilerplate - * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) - * - * The version of the OpenAPI document: 0.1.0 - * - * - * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). - * https://openapi-generator.tech - * Do not edit the class manually. - */ - -/** - * - * @export - * @interface ValidationError - */ -export interface ValidationError { - /** - * - * @type {Array} - * @memberof ValidationError - */ - loc: Array - /** - * - * @type {string} - * @memberof ValidationError - */ - msg: string - /** - * - * @type {string} - * @memberof ValidationError - */ - type: string -} diff --git a/web/src/features/todos/todo-list/TodoItem.tsx b/web/src/features/todos/todo-list/TodoItemCard.tsx similarity index 91% rename from web/src/features/todos/todo-list/TodoItem.tsx rename to web/src/features/todos/todo-list/TodoItemCard.tsx index eb623988..39614ef7 100644 --- a/web/src/features/todos/todo-list/TodoItem.tsx +++ b/web/src/features/todos/todo-list/TodoItemCard.tsx @@ -7,10 +7,10 @@ import { Tooltip, } from '@equinor/eds-core-react' import { undo, done, remove_outlined } from '@equinor/eds-icons' -import { AddTodoResponse } from '../../../api/generated' +import { TodoItem } from '../../../api/generated' -const TodoItem = (props: { - todo: AddTodoResponse +const TodoItemCard = (props: { + todo: TodoItem onToggle: (id: string) => void onRemove: (id: string) => void }) => { @@ -49,4 +49,4 @@ const TodoItem = (props: { ) } -export default TodoItem +export default TodoItemCard diff --git a/web/src/features/todos/todo-list/TodoList.tsx b/web/src/features/todos/todo-list/TodoList.tsx index 34084e58..a59c77ac 100644 --- a/web/src/features/todos/todo-list/TodoList.tsx +++ b/web/src/features/todos/todo-list/TodoList.tsx @@ -1,8 +1,8 @@ import useTodos from '../../../hooks/useTodos' import { FormEventHandler, useState } from 'react' import { Button, Input, Progress } from '@equinor/eds-core-react' -import TodoItem from './TodoItem' -import { AddTodoResponse } from '../../../api/generated' +import TodoItemCard from './TodoItemCard' +import { TodoItem } from '../../../api/generated' import { StyledTodoList, StyledInput, @@ -48,8 +48,8 @@ const TodoList = () => { return ( - {todos?.map((todo: AddTodoResponse) => ( - ( + void removeItem: (id: string) => void toggleItem: (id: string) => void error: AxiosError | null } => { - const [todos, setTodos] = useState([]) + const [todos, setTodos] = useState([]) const [isLoading, setLoading] = useState(true) const [error, setError] = useState | null>(null) const todoAPI = useTodoAPI() @@ -28,13 +28,9 @@ const useTodos = (): { const addItem = (title: string) => { setLoading(true) todoAPI - .create({ - addTodoRequest: { - title: title, - }, - }) + .create({ title: title }) .then((response) => { - const item: AddTodoResponse = response.data + const item: TodoItem = response.data setTodos([...todos, item]) }) .catch((error: AxiosError) => { @@ -46,10 +42,10 @@ const useTodos = (): { const removeItem = (id: string) => { setLoading(true) todoAPI - .deleteById({ id: id }) + .deleteById(id) .then(() => { const tmpTodos = todos.filter( - (todoItem: AddTodoResponse) => todoItem.id !== id + (todoItem: TodoItem) => todoItem.id !== id ) setTodos(tmpTodos) }) @@ -59,17 +55,12 @@ const useTodos = (): { const toggleItem = (id: string) => { setLoading(true) - const index: number = todos.findIndex( - (item: AddTodoResponse) => item.id === id - ) + const index: number = todos.findIndex((item: TodoItem) => item.id === id) const todoItem = todos[index] todoAPI - .updateById({ - id: id, - updateTodoRequest: { - is_completed: !todoItem.is_completed, - title: todoItem.title, - }, + .updateById(id, { + is_completed: !todoItem.is_completed, + title: todoItem.title, }) .then(() => { const items = todos