Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/code reduction #82

Merged
merged 5 commits into from
Jun 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.5.4] - 2023-06-22

### Added

- Added a base request builder and a request configuration class to reduce the amount of code being generated.

### Changed

## [0.5.2] - 2023-06-05

Expand Down
2 changes: 1 addition & 1 deletion kiota_abstractions/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
VERSION: str = '0.5.3'
VERSION: str = '0.5.4'
32 changes: 32 additions & 0 deletions kiota_abstractions/base_request_builder.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# ------------------------------------
# Copyright (c) Microsoft Corporation. All Rights Reserved.
# Licensed under the MIT License.
# See License in the project root for license information.
# ------------------------------------
from abc import ABC
from typing import Any, Dict, Union

from .request_adapter import RequestAdapter


class BaseRequestBuilder(ABC):
"""Base class for all request builders"""

def __init__(
self, request_adapter: RequestAdapter, url_template: str,
path_parameters: Union[Dict[str, Any], str]
) -> None:
"""Initializes a new instance of the BaseRequestBuilder class."""
if path_parameters is None:
path_parameters = {}
if request_adapter is None:
raise TypeError("request_adapter cannot be null.")
if url_template is None:
raise TypeError("url_template cannot be null.") # Empty string is allowed

# Path parameters for the request
self.path_parameters: Union[Dict[str, Any], str] = path_parameters
# Url template to use to build the URL for the current request builder
self.url_template: str = url_template
# The request adapter to use to execute the requests.
self.request_adapter = request_adapter
13 changes: 13 additions & 0 deletions kiota_abstractions/default_query_parameters.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# ------------------------------------
# Copyright (c) Microsoft Corporation. All Rights Reserved.
# Licensed under the MIT License.
# See License in the project root for license information.
# ------------------------------------
from dataclasses import dataclass


@dataclass
class GetQueryParameters:
"""
Default placeholder class for query parameters.
"""
21 changes: 21 additions & 0 deletions kiota_abstractions/request_configuration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# ------------------------------------
# Copyright (c) Microsoft Corporation. All Rights Reserved.
# Licensed under the MIT License.
# See License in the project root for license information.
# ------------------------------------
from dataclasses import dataclass
from typing import Dict, List, Optional, Union

from .request_option import RequestOption


@dataclass
class RequestConfiguration:
"""
Configuration for the request such as headers, query parameters, and middleware options.
"""
# Request headers
headers: Optional[Dict[str, Union[str, List[str]]]] = None

# Request options
options: Optional[List[RequestOption]] = None
3 changes: 2 additions & 1 deletion kiota_abstractions/serialization/parse_node_helper.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations
from typing import Callable, Dict, TYPE_CHECKING

from typing import TYPE_CHECKING, Callable, Dict

if TYPE_CHECKING:
from . import Parsable, ParseNode
Expand Down