Skip to content

Commit 155fc4f

Browse files
author
Anton Benkevich
committed
Backup, adding more tests
1 parent 6205ec5 commit 155fc4f

File tree

3 files changed

+45
-3
lines changed

3 files changed

+45
-3
lines changed

almdrlib/client.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -799,6 +799,7 @@ def _normalize_schema(name, schema, required=False):
799799
return schema
800800

801801
if compound_schema:
802+
# TODO move to alertlogic-sdk-definitions normalize_node
802803
if oneof:
803804
xof = OpenAPIKeyWord.ONE_OF
804805
elif anyof:
@@ -829,10 +830,11 @@ def add_xof(item):
829830
else:
830831
return item
831832

832-
allprops = reduce(lambda acc, s: acc + list(s.get(OpenAPIKeyWord.PROPERTIES).items()), compound_schema, [])
833+
allprops = reduce(lambda acc, s: acc + list(s.get(OpenAPIKeyWord.PROPERTIES, OrderedDict()).items()),
834+
compound_schema, [])
833835
reduced = reduce(reduce_props, allprops, OrderedDict())
834836
compound_props = OrderedDict(map(add_xof, reduced.items()))
835-
properties = compound_props
837+
properties = compound_props
836838

837839
if not properties:
838840
properties = OrderedDict({

tests/apis/testapi/testapi.v1.yaml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,35 @@ servers:
1616
description: integration
1717
x-alertlogic-session-endpoint: true
1818
paths:
19+
'/testapi/v1/postdata':
20+
post:
21+
operationId: post_data_compound
22+
requestBody:
23+
content:
24+
application/json:
25+
schema:
26+
oneOf:
27+
- type: object
28+
properties:
29+
prop:
30+
type: string
31+
additionalProperties: true
32+
- type: object
33+
properties:
34+
prop:
35+
type: integer
36+
- type: string
37+
responses:
38+
'200':
39+
description: 200 resp
40+
content:
41+
application/json:
42+
schema:
43+
type: object
44+
properties:
45+
prop:
46+
type: string
47+
1948
'/testapi/v1/{account_id}/test_get_data':
2049
get:
2150
summary: Test Get Data Operation

tests/test_open_api_support.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from almdrlib.client import Config
1212
from almdrlib.client import Operation
1313
from alsdkdefs import OpenAPIKeyWord
14-
14+
from collections import OrderedDict
1515

1616
class TestSdk_open_api_support(unittest.TestCase):
1717
"""Tests for `python_boilerplate` package."""
@@ -83,3 +83,14 @@ def test_003_default_objects_creation(self):
8383
self.assertIsInstance(Session(), Session)
8484
self.assertIsInstance(Config(), Config)
8585
self.assertIsInstance(Client(self._service_name), Client)
86+
87+
def test_004_test_operations_compound_schema(self):
88+
"""Test request body properties are properly normalized when schema is compound at the top level"""
89+
client = Client(self._service_name)
90+
operation = client.operations.get('post_data_compound')
91+
self.assertEqual(OrderedDict([('prop',
92+
OrderedDict([('oneOf', [
93+
OrderedDict([('type', 'integer')]),
94+
OrderedDict([('type', 'string')])
95+
])]))]),
96+
operation.body._content['application/json']._properties)

0 commit comments

Comments
 (0)