@@ -1899,3 +1899,158 @@ test('generateInterface handles inline response with nested $ref containing enum
18991899 "DevupObject<'response', 'openapi.json'>['OtherItemResponse']" ,
19001900 )
19011901} )
1902+
1903+ // Test circular reference handling in collectSchemaNames (line 83 coverage)
1904+ test ( 'generateInterface handles circular references in schema collection' , ( ) => {
1905+ const schema = {
1906+ paths : {
1907+ '/nodes' : {
1908+ get : {
1909+ operationId : 'listNodes' ,
1910+ responses : {
1911+ '200' : {
1912+ description : 'Success' ,
1913+ content : {
1914+ 'application/json' : {
1915+ schema : {
1916+ type : 'array' ,
1917+ items : {
1918+ $ref : '#/components/schemas/TreeNode' ,
1919+ } ,
1920+ } ,
1921+ } ,
1922+ } ,
1923+ } ,
1924+ } ,
1925+ } ,
1926+ } ,
1927+ } ,
1928+ components : {
1929+ schemas : {
1930+ TreeNode : {
1931+ type : 'object' ,
1932+ properties : {
1933+ id : { type : 'number' } ,
1934+ name : { type : 'string' } ,
1935+ // Circular reference - children contains TreeNode
1936+ children : {
1937+ type : 'array' ,
1938+ items : {
1939+ $ref : '#/components/schemas/TreeNode' ,
1940+ } ,
1941+ } ,
1942+ } ,
1943+ } ,
1944+ } ,
1945+ } ,
1946+ }
1947+ const result = generateInterface ( createSchemas ( createDocument ( schema as any ) ) )
1948+ expect ( result ) . toMatchSnapshot ( )
1949+ // Should not cause infinite loop and should generate valid output
1950+ expect ( result ) . toContain ( 'TreeNode' )
1951+ } )
1952+
1953+ // Test request schema with inline enum (lines 659-661 coverage)
1954+ test ( 'generateInterface handles request schema with inline enum' , ( ) => {
1955+ const schema = {
1956+ paths : {
1957+ '/items' : {
1958+ post : {
1959+ operationId : 'createItem' ,
1960+ requestBody : {
1961+ content : {
1962+ 'application/json' : {
1963+ schema : {
1964+ $ref : '#/components/schemas/CreateItemRequest' ,
1965+ } ,
1966+ } ,
1967+ } ,
1968+ } ,
1969+ responses : {
1970+ '200' : {
1971+ description : 'Success' ,
1972+ content : {
1973+ 'application/json' : {
1974+ schema : { type : 'object' , properties : { } } ,
1975+ } ,
1976+ } ,
1977+ } ,
1978+ } ,
1979+ } ,
1980+ } ,
1981+ } ,
1982+ components : {
1983+ schemas : {
1984+ CreateItemRequest : {
1985+ type : 'object' ,
1986+ properties : {
1987+ name : { type : 'string' } ,
1988+ // Inline enum - not a $ref, should be collected during schema processing
1989+ priority : {
1990+ type : 'string' ,
1991+ enum : [ 'low' , 'medium' , 'high' ] ,
1992+ } ,
1993+ } ,
1994+ } ,
1995+ } ,
1996+ } ,
1997+ }
1998+ const result = generateInterface ( createSchemas ( createDocument ( schema as any ) ) )
1999+ expect ( result ) . toMatchSnapshot ( )
2000+ // Inline enum should generate type alias based on context
2001+ expect ( result ) . toContain ( 'type CreateItemRequestPriority =' )
2002+ expect ( result ) . toContain ( '"low"' )
2003+ } )
2004+
2005+ // Test error schema with inline enum (lines 705-707 coverage)
2006+ test ( 'generateInterface handles error schema with inline enum' , ( ) => {
2007+ const schema = {
2008+ paths : {
2009+ '/items' : {
2010+ get : {
2011+ operationId : 'getItems' ,
2012+ responses : {
2013+ '200' : {
2014+ description : 'Success' ,
2015+ content : {
2016+ 'application/json' : {
2017+ schema : { type : 'object' , properties : { } } ,
2018+ } ,
2019+ } ,
2020+ } ,
2021+ '400' : {
2022+ description : 'Error' ,
2023+ content : {
2024+ 'application/json' : {
2025+ schema : {
2026+ $ref : '#/components/schemas/ErrorResponse' ,
2027+ } ,
2028+ } ,
2029+ } ,
2030+ } ,
2031+ } ,
2032+ } ,
2033+ } ,
2034+ } ,
2035+ components : {
2036+ schemas : {
2037+ ErrorResponse : {
2038+ type : 'object' ,
2039+ properties : {
2040+ message : { type : 'string' } ,
2041+ // Inline enum - not a $ref, should be collected during schema processing
2042+ code : {
2043+ type : 'string' ,
2044+ enum : [ 'INVALID_INPUT' , 'NOT_FOUND' , 'UNAUTHORIZED' ] ,
2045+ } ,
2046+ } ,
2047+ } ,
2048+ } ,
2049+ } ,
2050+ }
2051+ const result = generateInterface ( createSchemas ( createDocument ( schema as any ) ) )
2052+ expect ( result ) . toMatchSnapshot ( )
2053+ // Inline enum should generate type alias based on context
2054+ expect ( result ) . toContain ( 'type ErrorResponseCode =' )
2055+ expect ( result ) . toContain ( '"INVALID_INPUT"' )
2056+ } )
0 commit comments