Skip to content

Commit ae06f30

Browse files
authored
Fix handling of multiple nested types for the example config spec consumer (DataDog#8465)
1 parent 18dbd34 commit ae06f30

File tree

2 files changed

+54
-6
lines changed
  • datadog_checks_dev

2 files changed

+54
-6
lines changed

datadog_checks_dev/datadog_checks/dev/tooling/specs/configuration/consumers/example.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,17 @@ def value_type_string(value):
4444
if value_type == 'object':
4545
return 'mapping'
4646
elif value_type == 'array':
47-
item_type = value['items']['type']
48-
if item_type == 'object':
49-
return 'list of mappings'
50-
elif item_type == 'array':
51-
return 'list of lists'
47+
items = value['items']
48+
if 'oneOf' in items:
49+
return f'(list of {value_type_string(items)})'
5250
else:
53-
return f'list of {item_type}s'
51+
item_type = items['type']
52+
if item_type == 'object':
53+
return 'list of mappings'
54+
elif item_type == 'array':
55+
return 'list of lists'
56+
else:
57+
return f'list of {item_type}s'
5458
else:
5559
return value_type
5660

datadog_checks_dev/tests/tooling/configuration/consumers/test_example.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1467,3 +1467,47 @@ def test_option_multiple_types():
14671467
# foo: <FOO>
14681468
"""
14691469
)
1470+
1471+
1472+
def test_option_multiple_types_nested():
1473+
consumer = get_example_consumer(
1474+
"""
1475+
name: foo
1476+
version: 0.0.0
1477+
files:
1478+
- name: test.yaml
1479+
example_name: test.yaml.example
1480+
options:
1481+
- template: instances
1482+
options:
1483+
- name: foo
1484+
description: words
1485+
value:
1486+
oneOf:
1487+
- type: string
1488+
- type: array
1489+
items:
1490+
oneOf:
1491+
- type: string
1492+
- type: object
1493+
required:
1494+
- foo
1495+
"""
1496+
)
1497+
1498+
files = consumer.render()
1499+
contents, errors = files['test.yaml.example']
1500+
assert not errors
1501+
assert contents == normalize_yaml(
1502+
"""
1503+
## Every instance is scheduled independent of the others.
1504+
#
1505+
instances:
1506+
1507+
-
1508+
## @param foo - string or (list of string or mapping) - optional
1509+
## words
1510+
#
1511+
# foo: <FOO>
1512+
"""
1513+
)

0 commit comments

Comments
 (0)