@@ -1529,6 +1529,127 @@ def test_callback(self):
15291529
15301530 ''' ).lstrip ()
15311531
1532+ def test_string_example (self ):
1533+ renderer = renderers .HttpdomainOldRenderer (None , {'examples' : True })
1534+ text = '\n ' .join (renderer .render_restructuredtext_markup ({
1535+ 'openapi' : '3.0.0' ,
1536+ 'paths' : {
1537+ '/resources' : {
1538+ 'get' : {
1539+ 'summary' : 'Get resources' ,
1540+ 'responses' : {
1541+ '200' : {
1542+ 'description' : 'Something' ,
1543+ 'content' : {
1544+ 'application/json' : {
1545+ 'schema' : {
1546+ 'type' : 'string' ,
1547+ 'example' : '"A sample"' ,
1548+ }
1549+ }
1550+ }
1551+ },
1552+ },
1553+ },
1554+ },
1555+ },
1556+ }))
1557+
1558+ assert text == textwrap .dedent ('''
1559+ .. http:get:: /resources
1560+ :synopsis: Get resources
1561+
1562+ **Get resources**
1563+
1564+
1565+ **Example request:**
1566+
1567+ .. sourcecode:: http
1568+
1569+ GET /resources HTTP/1.1
1570+ Host: example.com
1571+
1572+ :status 200:
1573+ Something
1574+
1575+ **Example response:**
1576+
1577+ .. sourcecode:: http
1578+
1579+ HTTP/1.1 200 OK
1580+ Content-Type: application/json
1581+
1582+ "A sample"
1583+
1584+ ''' ).lstrip ()
1585+
1586+ def test_ref_example (self ):
1587+ renderer = renderers .HttpdomainOldRenderer (None , {'examples' : True })
1588+ text = '\n ' .join (renderer .render_restructuredtext_markup ({
1589+ 'openapi' : '3.0.0' ,
1590+ 'paths' : {
1591+ '/resources' : {
1592+ 'get' : {
1593+ 'summary' : 'Get resources' ,
1594+ 'responses' : {
1595+ '200' : {
1596+ 'description' : 'Something' ,
1597+ 'content' : {
1598+ 'application/json' : {
1599+ 'schema' : {
1600+ '$ref' :
1601+ '#/components/schemas/Data' ,
1602+ }
1603+ }
1604+ }
1605+ },
1606+ },
1607+ },
1608+ },
1609+ },
1610+ 'components' : {
1611+ 'schemas' : {
1612+ 'Data' : {
1613+ 'type' : 'object' ,
1614+ 'additionalProperties' : True ,
1615+ 'example' : {
1616+ 'prop1' : "Sample 1" ,
1617+ }
1618+ }
1619+ }
1620+ }
1621+ }))
1622+
1623+ assert text == textwrap .dedent ('''
1624+ .. http:get:: /resources
1625+ :synopsis: Get resources
1626+
1627+ **Get resources**
1628+
1629+
1630+ **Example request:**
1631+
1632+ .. sourcecode:: http
1633+
1634+ GET /resources HTTP/1.1
1635+ Host: example.com
1636+
1637+ :status 200:
1638+ Something
1639+
1640+ **Example response:**
1641+
1642+ .. sourcecode:: http
1643+
1644+ HTTP/1.1 200 OK
1645+ Content-Type: application/json
1646+
1647+ {
1648+ "prop1": "Sample 1"
1649+ }
1650+
1651+ ''' ).lstrip ()
1652+
15321653 def test_method_option (self ):
15331654 spec = collections .defaultdict (collections .OrderedDict )
15341655 spec ['paths' ]['/resource_a' ] = {
0 commit comments