Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into andrueastman/pythonFix
Browse files Browse the repository at this point in the history
  • Loading branch information
andrueastman committed Nov 11, 2024
2 parents 5be6680 + 34eff4c commit 37f30cf
Show file tree
Hide file tree
Showing 5 changed files with 122 additions and 1 deletion.
1 change: 1 addition & 0 deletions .github/workflows/integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ jobs:
- "./tests/Kiota.Builder.IntegrationTests/NoUnderscoresInModel.yaml"
- "./tests/Kiota.Builder.IntegrationTests/ToDoApi.yaml"
- "./tests/Kiota.Builder.IntegrationTests/GeneratesUritemplateHints.yaml"
- "./tests/Kiota.Builder.IntegrationTests/DiscriminatorSample.yaml"
- "oas::petstore"
- "apisguru::twitter.com:current"
- "apisguru::notion.com"
Expand Down
9 changes: 9 additions & 0 deletions it/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@
}
]
},
"./tests/Kiota.Builder.IntegrationTests/DiscriminatorSample.yaml": {
"MockServerITFolder": "discriminator",
"Suppressions": [
{
"Language": "ruby",
"Rationale": "https://github.com/microsoft/kiota/issues/2484"
}
]
},
"apisguru::github.com:api.github.com": {
"MockServerITFolder": "gh",
"Suppressions": [
Expand Down
60 changes: 60 additions & 0 deletions it/python/discriminator/test_serdeser.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import pytest

from kiota_serialization_json.json_parse_node_factory import JsonParseNodeFactory
from kiota_serialization_json.json_serialization_writer_factory import JsonSerializationWriterFactory

from client.discriminateme.component import Component
from client.models.component1 import Component1
from client.models.component2 import Component2

@pytest.mark.asyncio
async def test_component1_deser():
factory = JsonParseNodeFactory()
root = factory.get_root_parse_node('application/json', '{"objectType": "obj1", "one": "foo"}'.encode('utf-8'))
result = root.get_object_value(Component)
assert hasattr(result, "component1")
assert hasattr(result, "component2")
assert result.component2 is None
assert result.component1 is not None
assert isinstance(result.component1, Component1)
assert result.component1.object_type == "obj1"
assert result.component1.one == "foo"

@pytest.mark.asyncio
async def test_component2_deser():
factory = JsonParseNodeFactory()
root = factory.get_root_parse_node('application/json', '{"objectType": "obj2", "two": "bar"}'.encode('utf-8'))
result = root.get_object_value(Component)
assert hasattr(result, "component2")
assert hasattr(result, "component1")
assert result.component1 is None
assert result.component2 is not None
assert isinstance(result.component2, Component2)
assert result.component2.object_type == "obj2"
assert result.component2.two == "bar"

@pytest.mark.asyncio
async def test_component1_ser():
obj = Component()
obj1 = Component1()
obj1.object_type = "obj1"
obj1.one = "foo"
obj.component1 = obj1
factory = JsonSerializationWriterFactory()
writer = factory.get_serialization_writer('application/json')
obj.serialize(writer)
content = writer.get_serialized_content().decode('utf-8')
assert content == '{"objectType": "obj1", "one": "foo"}'

@pytest.mark.asyncio
async def test_component2_ser():
obj = Component()
obj2 = Component2()
obj2.object_type = "obj2"
obj2.two = "bar"
obj.component2 = obj2
factory = JsonSerializationWriterFactory()
writer = factory.get_serialization_writer('application/json')
obj.serialize(writer)
content = writer.get_serialized_content().decode('utf-8')
assert content == '{"objectType": "obj2", "two": "bar"}'
2 changes: 1 addition & 1 deletion src/Kiota.Builder/Kiota.Builder.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
<NoWarn>$(NoWarn);CS8785;NU5048;NU5104;CA1724;CA1055;CA1848;CA1308;CA1822</NoWarn>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="AsyncKeyedLock" Version="7.0.2" />
<PackageReference Include="AsyncKeyedLock" Version="7.1.3" />
<PackageReference Include="DotNet.Glob" Version="3.1.3" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.2" />
<PackageReference Include="Microsoft.Kiota.Abstractions" Version="1.14.0" />
Expand Down
51 changes: 51 additions & 0 deletions tests/Kiota.Builder.IntegrationTests/DiscriminatorSample.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
openapi: 3.0.0
info:
title: "Discriminator API"
version: "1.0.0"
servers:
- url: https://mytodos.doesnotexist/
paths:
/discriminateme:
post:
description: Return something
responses:
"200":
description: OK
content:
application/json:
schema:
$ref: "#/components/schemas/Component"
requestBody:
content:
application/json:
schema:
$ref: "#/components/schemas/Component"
components:
schemas:
Component:
oneOf:
- $ref: "#/components/schemas/Component1"
- $ref: "#/components/schemas/Component2"
discriminator:
propertyName: objectType
mapping:
obj1: "#/components/schemas/Component1"
obj2: "#/components/schemas/Component2"
Component1:
type: object
required:
- objectType
properties:
objectType:
type: string
one:
type: string
Component2:
type: object
required:
- objectType
properties:
objectType:
type: string
two:
type: string

0 comments on commit 37f30cf

Please sign in to comment.