-
Notifications
You must be signed in to change notification settings - Fork 210
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/main' into andrueastman/pythonFix
- Loading branch information
Showing
5 changed files
with
122 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"}' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
tests/Kiota.Builder.IntegrationTests/DiscriminatorSample.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |