@@ -1530,3 +1530,62 @@ func TestRawBody(t *testing.T) {
15301530 }
15311531 }` , r .SpecSchema ())
15321532}
1533+
1534+ func TestSelfReference (t * testing.T ) {
1535+ reflector := openapi31 .NewReflector ()
1536+
1537+ type SubEntity struct {
1538+ Self * SubEntity `json:"self"`
1539+ }
1540+
1541+ type My struct {
1542+ Foo string `json:"foo"`
1543+ SubEntity * SubEntity `json:"subentity"`
1544+ }
1545+
1546+ putOp , err := reflector .NewOperationContext (http .MethodPut , "/things/" )
1547+ require .NoError (t , err )
1548+
1549+ putOp .AddReqStructure (My {})
1550+ putOp .AddRespStructure (My {})
1551+
1552+ require .NoError (t , reflector .AddOperation (putOp ))
1553+
1554+ assertjson .EqMarshal (t , `{
1555+ "openapi":"3.1.0","info":{"title":"","version":""},
1556+ "paths":{
1557+ "/things/":{
1558+ "put":{
1559+ "requestBody":{
1560+ "content":{
1561+ "application/json":{"schema":{"$ref":"#/components/schemas/Openapi31TestMy"}}
1562+ }
1563+ },
1564+ "responses":{
1565+ "200":{
1566+ "description":"OK",
1567+ "content":{
1568+ "application/json":{"schema":{"$ref":"#/components/schemas/Openapi31TestMy"}}
1569+ }
1570+ }
1571+ }
1572+ }
1573+ }
1574+ },
1575+ "components":{
1576+ "schemas":{
1577+ "Openapi31TestMy":{
1578+ "properties":{
1579+ "foo":{"type":"string"},
1580+ "subentity":{"$ref":"#/components/schemas/Openapi31TestSubEntity"}
1581+ },
1582+ "type":"object"
1583+ },
1584+ "Openapi31TestSubEntity":{
1585+ "properties":{"self":{"$ref":"#/components/schemas/Openapi31TestSubEntity"}},
1586+ "type":"object"
1587+ }
1588+ }
1589+ }
1590+ }` , reflector .SpecSchema ())
1591+ }
0 commit comments