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

validate #4435 #5742

Merged
merged 3 commits into from
Nov 10, 2024
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
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"}'
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
Loading