Skip to content

Commit 6465520

Browse files
author
Andrew Omondi
committed
adds validation with generated project
1 parent b02c779 commit 6465520

File tree

94 files changed

+10563
-28
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

94 files changed

+10563
-28
lines changed

.github/workflows/build.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,29 @@ jobs:
6767
working-directory: ${{ matrix.library.path }}
6868
run: |
6969
poetry run pytest
70+
71+
validation-workflow-with-generated-code:
72+
runs-on: ubuntu-latest
73+
timeout-minutes: 40
74+
strategy:
75+
max-parallel: 10
76+
matrix:
77+
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
78+
79+
steps:
80+
- name: Checkout
81+
uses: actions/checkout@v4
82+
- name: Set up Python ${{ matrix.python-version }}
83+
uses: actions/setup-python@v5
84+
with:
85+
python-version: ${{ matrix.python-version }}
86+
- name: Install dependencies
87+
working-directory: "./tests/validation"
88+
run: |
89+
python -m pip install --upgrade poetry
90+
poetry install
91+
- name: Static type checking with Mypy
92+
working-directory: "./tests/validation"
93+
run: |
94+
poetry run mypy validation
95+

packages/abstractions/kiota_abstractions/request_adapter.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from __future__ import annotations
12
from abc import ABC, abstractmethod
23
from datetime import datetime
34
from io import BytesIO
@@ -31,7 +32,7 @@ def get_serialization_writer_factory(self) -> SerializationWriterFactory:
3132
@abstractmethod
3233
async def send_async(
3334
self, request_info: RequestInformation, parsable_factory: ParsableFactory[ModelType],
34-
error_map: Optional[Dict[str, ParsableFactory]]
35+
error_map: Optional[Dict[str, type[ParsableFactory]]]
3536
) -> Optional[ModelType]:
3637
"""Excutes the HTTP request specified by the given RequestInformation and returns the
3738
deserialized response model.
@@ -40,7 +41,7 @@ async def send_async(
4041
request_info (RequestInformation): the request info to execute.
4142
parsable_factory (ParsableFactory): the class of response model to
4243
deserialize the response into.
43-
error_map (Optional[Dict[str, ParsableFactory]]): the error dict to use in case
44+
error_map (Optional[Dict[str, type[ParsableFactory]]]): the error dict to use in case
4445
of a failed request.
4546
4647
Returns:
@@ -52,8 +53,8 @@ async def send_async(
5253
async def send_collection_async(
5354
self,
5455
request_info: RequestInformation,
55-
parsable_factory: ParsableFactory,
56-
error_map: Optional[Dict[str, ParsableFactory]],
56+
parsable_factory: ParsableFactory[ModelType],
57+
error_map: Optional[Dict[str, type[ParsableFactory]]],
5758
) -> Optional[List[ModelType]]:
5859
"""Excutes the HTTP request specified by the given RequestInformation and returns the
5960
deserialized response model collection.
@@ -62,7 +63,7 @@ async def send_collection_async(
6263
request_info (RequestInformation): the request info to execute.
6364
parsable_factory (ParsableFactory): the class of response model to
6465
deserialize the response into.
65-
error_map (Optional[Dict[str, ParsableFactory]]): the error dict to use in
66+
error_map (Optional[Dict[str, type[ParsableFactory]]]): the error dict to use in
6667
case of a failed request.
6768
6869
Returns:
@@ -75,7 +76,7 @@ async def send_collection_of_primitive_async(
7576
self,
7677
request_info: RequestInformation,
7778
response_type: ResponseType,
78-
error_map: Optional[Dict[str, ParsableFactory]],
79+
error_map: Optional[Dict[str, type[ParsableFactory]]],
7980
) -> Optional[List[ResponseType]]:
8081
"""Excutes the HTTP request specified by the given RequestInformation and returns the
8182
deserialized response model collection.
@@ -84,7 +85,7 @@ async def send_collection_of_primitive_async(
8485
request_info (RequestInformation): the request info to execute.
8586
response_type (ResponseType): the class of the response model to deserialize the
8687
response into.
87-
error_map (Optional[Dict[str, ParsableFactory]]): the error dict to use in
88+
error_map (Optional[Dict[str, type[ParsableFactory]]]): the error dict to use in
8889
case of a failed request.
8990
9091
Returns:
@@ -95,7 +96,7 @@ async def send_collection_of_primitive_async(
9596
@abstractmethod
9697
async def send_primitive_async(
9798
self, request_info: RequestInformation, response_type: str,
98-
error_map: Optional[Dict[str, ParsableFactory]]
99+
error_map: Optional[Dict[str, type[ParsableFactory]]]
99100
) -> Optional[ResponseType]:
100101
"""Excutes the HTTP request specified by the given RequestInformation and returns the
101102
deserialized primitive response model.
@@ -104,7 +105,7 @@ async def send_primitive_async(
104105
request_info (RequestInformation): the request info to execute.
105106
response_type (str): the class name of the response model to deserialize the
106107
response into.
107-
error_map (Optional[Dict[str, ParsableFactory]]): the error dict to use in
108+
error_map (Optional[Dict[str, type[ParsableFactory]]]): the error dict to use in
108109
case of a failed request.
109110
110111
Returns:
@@ -114,14 +115,15 @@ async def send_primitive_async(
114115

115116
@abstractmethod
116117
async def send_no_response_content_async(
117-
self, request_info: RequestInformation, error_map: Optional[Dict[str, ParsableFactory]]
118+
self, request_info: RequestInformation, error_map: Optional[Dict[str,
119+
type[ParsableFactory]]]
118120
) -> None:
119121
"""Excutes the HTTP request specified by the given RequestInformation and returns the
120122
deserialized primitive response model.
121123
122124
Args:
123125
request_info (RequestInformation):the request info to execute.
124-
error_map (Optional[Dict[str, ParsableFactory]]): the error dict to use in
126+
error_map (Optional[Dict[str, type[ParsableFactory]]]): the error dict to use in
125127
case of a failed request.
126128
"""
127129
pass

packages/abstractions/kiota_abstractions/serialization/parsable_factory.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
from abc import abstractmethod
2-
from typing import Generic, Optional, TypeVar
2+
from typing import Generic, Optional, Protocol, TypeVar
33

44
from .parsable import Parsable
55
from .parse_node import ParseNode
66

7-
U = TypeVar("U", bound=Parsable)
7+
U_co = TypeVar("U_co", bound="Parsable", covariant=True)
88

99

10-
class ParsableFactory(Generic[U]):
10+
class ParsableFactory(Protocol, Generic[U_co]):
1111
"""Defines the factory for creating parsable objects.
1212
"""
1313

1414
@staticmethod
1515
@abstractmethod
16-
def create_from_discriminator_value(parse_node: Optional[ParseNode]) -> U:
16+
def create_from_discriminator_value(parse_node: ParseNode) -> U_co:
1717
"""Create a new parsable object from the given serialized data.
1818
1919
Args:

packages/http/httpx/kiota_http/httpx_request_adapter.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""HTTPX client request adapter."""
2+
from __future__ import annotations
23
import re
34
from datetime import datetime
45
from typing import Any, Dict, Generic, List, Optional, TypeVar, Union
@@ -152,15 +153,15 @@ async def send_async(
152153
self,
153154
request_info: RequestInformation,
154155
parsable_factory: ParsableFactory[ModelType],
155-
error_map: Optional[Dict[str, ParsableFactory]],
156+
error_map: Optional[Dict[str, type[ParsableFactory]]],
156157
) -> Optional[ModelType]:
157158
"""Excutes the HTTP request specified by the given RequestInformation and returns the
158159
deserialized response model.
159160
Args:
160161
request_info (RequestInformation): the request info to execute.
161162
parsable_factory (ParsableFactory): the class of the response model
162163
to deserialize the response into.
163-
error_map (Dict[str, ParsableFactory]): the error dict to use in
164+
error_map (Dict[str, type[ParsableFactory]]): the error dict to use in
164165
case of a failed request.
165166
166167
Returns:
@@ -197,15 +198,15 @@ async def send_collection_async(
197198
self,
198199
request_info: RequestInformation,
199200
parsable_factory: ParsableFactory,
200-
error_map: Optional[Dict[str, ParsableFactory]],
201+
error_map: Optional[Dict[str, type[ParsableFactory]]],
201202
) -> Optional[List[ModelType]]:
202203
"""Excutes the HTTP request specified by the given RequestInformation and returns the
203204
deserialized response model collection.
204205
Args:
205206
request_info (RequestInformation): the request info to execute.
206207
parsable_factory (ParsableFactory): the class of the response model
207208
to deserialize the response into.
208-
error_map (Dict[str, ParsableFactory]): the error dict to use in
209+
error_map (Dict[str, type[ParsableFactory]]): the error dict to use in
209210
case of a failed request.
210211
211212
Returns:
@@ -244,15 +245,15 @@ async def send_collection_of_primitive_async(
244245
self,
245246
request_info: RequestInformation,
246247
response_type: ResponseType,
247-
error_map: Optional[Dict[str, ParsableFactory]],
248+
error_map: Optional[Dict[str, type[ParsableFactory]]],
248249
) -> Optional[List[ResponseType]]:
249250
"""Excutes the HTTP request specified by the given RequestInformation and returns the
250251
deserialized response model collection.
251252
Args:
252253
request_info (RequestInformation): the request info to execute.
253254
response_type (ResponseType): the class of the response model
254255
to deserialize the response into.
255-
error_map (Dict[str, ParsableFactory]): the error dict to use in
256+
error_map (Dict[str, type[ParsableFactory]]): the error dict to use in
256257
case of a failed request.
257258
258259
Returns:
@@ -291,15 +292,15 @@ async def send_primitive_async(
291292
self,
292293
request_info: RequestInformation,
293294
response_type: str,
294-
error_map: Optional[Dict[str, ParsableFactory]],
295+
error_map: Optional[Dict[str, type[ParsableFactory]]],
295296
) -> Optional[ResponseType]:
296297
"""Excutes the HTTP request specified by the given RequestInformation and returns the
297298
deserialized primitive response model.
298299
Args:
299300
request_info (RequestInformation): the request info to execute.
300301
response_type (str): the class name of the response model to deserialize the
301302
response into.
302-
error_map (Dict[str, ParsableFactory]): the error dict to use in case
303+
error_map (Dict[str, type[ParsableFactory]]): the error dict to use in case
303304
of a failed request.
304305
305306
Returns:
@@ -352,13 +353,14 @@ async def send_primitive_async(
352353
parent_span.end()
353354

354355
async def send_no_response_content_async(
355-
self, request_info: RequestInformation, error_map: Optional[Dict[str, ParsableFactory]]
356+
self, request_info: RequestInformation, error_map: Optional[Dict[str,
357+
type[ParsableFactory]]]
356358
) -> None:
357359
"""Excutes the HTTP request specified by the given RequestInformation and returns the
358360
deserialized primitive response model.
359361
Args:
360362
request_info (RequestInformation):the request info to execute.
361-
error_map (Dict[str, ParsableFactory]): the error dict to use in case
363+
error_map (Dict[str, type[ParsableFactory]]): the error dict to use in case
362364
of a failed request.
363365
"""
364366
parent_span = self.start_tracing_span(request_info, "send_no_response_content_async")
@@ -418,7 +420,7 @@ def _should_return_none(self, response: httpx.Response) -> bool:
418420
async def throw_failed_responses(
419421
self,
420422
response: httpx.Response,
421-
error_map: Optional[Dict[str, ParsableFactory]],
423+
error_map: Optional[Dict[str, type[ParsableFactory]]],
422424
parent_span: trace.Span,
423425
attribute_span: trace.Span,
424426
) -> None:
@@ -644,13 +646,13 @@ async def convert_to_native_async(self, request_info: RequestInformation) -> htt
644646
parent_span.end()
645647

646648
def _error_class_not_in_error_mapping(
647-
self, error_map: Dict[str, ParsableFactory], status_code: int
649+
self, error_map: Dict[str, type[ParsableFactory]], status_code: int
648650
) -> bool:
649651
"""Helper function to check if the error class corresponding to a response status code
650652
is not in the error mapping.
651653
652654
Args:
653-
error_map (Dict[str, ParsableFactory]): The error mapping.
655+
error_map (Dict[str, type[ParsableFactory]]): The error mapping.
654656
status_code (int): The response status code.
655657
656658
Returns:

packages/serialization/text/kiota_serialization_text/py.typed

Whitespace-only changes.

0 commit comments

Comments
 (0)