@@ -1492,7 +1492,7 @@ def _base_api_data():
1492
1492
content:
1493
1493
application/json:
1494
1494
schema:
1495
- $ref: '#/components/schemas/fooBarModel '
1495
+ $ref: '#/components/schemas/fooBar '
1496
1496
"""
1497
1497
1498
1498
@@ -1607,93 +1607,7 @@ def test_build_schemas_resolve_inner_property_remote_reference():
1607
1607
)
1608
1608
1609
1609
1610
- def test_build_schemas_lazy_resolve_known_inner_property_local_reference ():
1611
- import yaml
1612
-
1613
- import openapi_python_client .schema as oai
1614
- from openapi_python_client .parser .properties import Schemas , build_schemas
1615
-
1616
- data = yaml .safe_load (
1617
- f"""
1618
- { _base_api_data ()}
1619
- components:
1620
- schemas:
1621
- fooBar:
1622
- type: object
1623
- properties:
1624
- childSettings:
1625
- type: array
1626
- items:
1627
- $ref: '#/components/schemas/bar'
1628
- bar:
1629
- type: object
1630
- properties:
1631
- a_prop:
1632
- type: number
1633
- """
1634
- )
1635
- openapi = oai .OpenAPI .parse_obj (data )
1636
-
1637
- schemas = build_schemas (components = openapi .components .schemas )
1638
-
1639
- foo_bar = schemas .models .get ("FooBar" )
1640
- bar = schemas .models .get ("Bar" )
1641
- assert len (schemas .errors ) == 0
1642
- assert foo_bar and bar
1643
- child_settings = foo_bar .optional_properties [0 ]
1644
- assert child_settings .inner_property .reference == bar .reference
1645
-
1646
-
1647
- def test_build_schemas_lazy_resolve_known_inner_property_local_reference_with_loop ():
1648
- import yaml
1649
-
1650
- import openapi_python_client .schema as oai
1651
- from openapi_python_client .parser .properties import Schemas , build_schemas
1652
-
1653
- data = yaml .safe_load (
1654
- f"""
1655
- { _base_api_data ()}
1656
- components:
1657
- schemas:
1658
- fooBar:
1659
- type: object
1660
- properties:
1661
- childSettings:
1662
- type: array
1663
- items:
1664
- $ref: '#/components/schemas/barDeeperLoop'
1665
-
1666
- barDeeperLoop:
1667
- $ref: '#/components/schemas/barLoop'
1668
- barLoop:
1669
- $ref: '#/components/schemas/bar'
1670
- bar:
1671
- type: object
1672
- properties:
1673
- a_prop:
1674
- type: number
1675
-
1676
- """
1677
- )
1678
- openapi = oai .OpenAPI .parse_obj (data )
1679
-
1680
- schemas = build_schemas (components = openapi .components .schemas )
1681
-
1682
- foo_bar = schemas .models .get ("FooBar" )
1683
- bar_deeper_loop = schemas .models .get ("BarDeeperLoop" )
1684
- bar_loop = schemas .models .get ("BarLoop" )
1685
- bar = schemas .models .get ("Bar" )
1686
- assert len (schemas .errors ) == 0
1687
- assert foo_bar and bar_deeper_loop and bar_loop and bar
1688
- assert bar == bar_deeper_loop == bar_loop
1689
-
1690
- child_settings = foo_bar .optional_properties [0 ]
1691
- assert child_settings .inner_property .reference == bar .reference
1692
- assert child_settings .inner_property .reference == bar_loop .reference
1693
- assert child_settings .inner_property .reference == bar_deeper_loop .reference
1694
-
1695
-
1696
- def test_build_schemas_lazy_resolve_inner_property_self_local_reference ():
1610
+ def test_build_schemas_lazy_resolve_inner_property_self_direct_reference ():
1697
1611
import yaml
1698
1612
1699
1613
import openapi_python_client .schema as oai
@@ -1724,7 +1638,7 @@ def test_build_schemas_lazy_resolve_inner_property_self_local_reference():
1724
1638
assert child_settings .inner_property .reference == foo_bar .reference
1725
1639
1726
1640
1727
- def test_build_schemas_lazy_resolve_unknown_inner_property_local_reference ():
1641
+ def test_build_schemas_lazy_resolve_known_inner_property_self_indirect_reference ():
1728
1642
import yaml
1729
1643
1730
1644
import openapi_python_client .schema as oai
@@ -1740,16 +1654,25 @@ def test_build_schemas_lazy_resolve_unknown_inner_property_local_reference():
1740
1654
properties:
1741
1655
childSettings:
1742
1656
type: array
1657
+ description: test
1743
1658
items:
1744
- $ref: '#/components/schemas/noexist'
1659
+ $ref: '#/components/schemas/FoobarSelfIndirectReference'
1660
+ FoobarSelfIndirectReference:
1661
+ $ref: '#/components/schemas/foobarSelfDeeperIndirectReference'
1662
+ foobarSelfDeeperIndirectReference:
1663
+ $ref: '#/components/schemas/fooBar'
1745
1664
"""
1746
1665
)
1747
1666
openapi = oai .OpenAPI .parse_obj (data )
1748
1667
1749
1668
schemas = build_schemas (components = openapi .components .schemas )
1750
1669
1751
- assert len (schemas .errors ) == 1
1752
- assert schemas .errors [0 ] == PropertyError (
1753
- detail = "invalid data in items of array childSettings" ,
1754
- data = oai .Reference (ref = "#/components/schemas/noexist" ),
1755
- )
1670
+ assert len (schemas .errors ) == 0
1671
+ foobar = schemas .models .get ("FooBar" )
1672
+ foobar_indirect_ref = schemas .models .get ("FoobarSelfIndirectReference" )
1673
+ foobar_deep_indirect_ref = schemas .models .get ("FoobarSelfDeeperIndirectReference" )
1674
+ assert foobar is not None and foobar_indirect_ref is not None and foobar_deep_indirect_ref is not None
1675
+ assert foobar == foobar_indirect_ref == foobar_deep_indirect_ref
1676
+
1677
+ child_settings = foobar .optional_properties [0 ]
1678
+ assert child_settings .inner_property .reference == foobar .reference
0 commit comments