@@ -1815,3 +1815,58 @@ oneOf:
18151815 assert .Contains (t , output , "meow:" )
18161816 assert .Contains (t , output , "type:" )
18171817}
1818+
1819+ func TestSchema_RenderInlineWithContext_Error (t * testing.T ) {
1820+ // Test the error path in RenderInlineWithContext (line 506)
1821+ // Create a schema with a circular reference that will trigger an error
1822+
1823+ idxYaml := `components:
1824+ schemas:
1825+ Circular:
1826+ type: object
1827+ properties:
1828+ self:
1829+ $ref: '#/components/schemas/Circular'`
1830+
1831+ var idxNode yaml.Node
1832+ _ = yaml .Unmarshal ([]byte (idxYaml ), & idxNode )
1833+
1834+ idx := index .NewSpecIndexWithConfig (& idxNode , index .CreateOpenAPIIndexConfig ())
1835+
1836+ // Build the circular schema
1837+ schemas := idxNode .Content [0 ].Content [1 ].Content [1 ] // components -> schemas -> Circular
1838+ sp := new (lowbase.SchemaProxy )
1839+ err := sp .Build (context .Background (), nil , schemas .Content [1 ], idx )
1840+ assert .NoError (t , err )
1841+
1842+ lowproxy := low.NodeReference [* lowbase.SchemaProxy ]{
1843+ Value : sp ,
1844+ ValueNode : schemas .Content [1 ],
1845+ }
1846+
1847+ schemaProxy := NewSchemaProxy (& lowproxy )
1848+ compiled := schemaProxy .Schema ()
1849+
1850+ // Create a context and pre-mark the schema's render key to simulate a cycle
1851+ ctx := NewInlineRenderContext ()
1852+
1853+ // Get the render key for the self-referencing property's schema proxy
1854+ if compiled .Properties != nil {
1855+ selfProp := compiled .Properties .GetOrZero ("self" )
1856+ if selfProp != nil {
1857+ // Pre-mark this key as rendering to force a cycle error
1858+ renderKey := selfProp .getInlineRenderKey ()
1859+ if renderKey != "" {
1860+ ctx .StartRendering (renderKey )
1861+ }
1862+ }
1863+ }
1864+
1865+ // RenderInlineWithContext should return an error due to the pre-marked cycle
1866+ result , err := compiled .RenderInlineWithContext (ctx )
1867+
1868+ // The error path should be triggered
1869+ assert .Error (t , err )
1870+ assert .Nil (t , result )
1871+ assert .Contains (t , err .Error (), "circular reference" )
1872+ }
0 commit comments