@@ -263,6 +263,98 @@ describe("Next link operations", () => {
263263 `Expected response model 'LinkResponse' to be present in code model. Found: ${ root . models . map ( ( m ) => m . name ) . join ( ", " ) } ` ,
264264 ) ;
265265 } ) ;
266+
267+ it ( "includes nested enum from protocol-only response model in code model" , async ( ) => {
268+ const program = await typeSpecCompile (
269+ `
270+ @convenientAPI(false)
271+ @list
272+ op link(): {
273+ @pageItems
274+ items: Foo[];
275+
276+ @nextLink
277+ next?: url;
278+ };
279+ enum Status { running, completed, failed };
280+ model Foo {
281+ name: string;
282+ status: Status;
283+ };
284+ ` ,
285+ runner ,
286+ { IsTCGCNeeded : true } ,
287+ ) ;
288+ const context = createEmitterContext ( program ) ;
289+ const sdkContext = await createCSharpSdkContext ( context ) ;
290+ const [ root ] = createModel ( sdkContext ) ;
291+
292+ // The enum used as a property type of a model only reachable via a
293+ // protocol-only paging operation must be included in the code model's
294+ // enums list, not just the models list.
295+ const statusEnum = root . enums . find ( ( e ) => e . name === "Status" ) ;
296+ ok (
297+ statusEnum ,
298+ `Expected enum 'Status' to be present in code model enums. Found: ${ root . enums . map ( ( e ) => e . name ) . join ( ", " ) } ` ,
299+ ) ;
300+
301+ // The model itself should also be present
302+ const fooModel = root . models . find ( ( m ) => m . name === "Foo" ) ;
303+ ok (
304+ fooModel ,
305+ `Expected model 'Foo' to be present in code model models. Found: ${ root . models . map ( ( m ) => m . name ) . join ( ", " ) } ` ,
306+ ) ;
307+ } ) ;
308+
309+ it ( "includes deeply nested enum from protocol-only response model in code model" , async ( ) => {
310+ const program = await typeSpecCompile (
311+ `
312+ @convenientAPI(false)
313+ @list
314+ op link(): {
315+ @pageItems
316+ items: Foo[];
317+
318+ @nextLink
319+ next?: url;
320+ };
321+ enum Priority { low, medium, high };
322+ model Bar {
323+ priority: Priority;
324+ };
325+ model Foo {
326+ name: string;
327+ bar: Bar;
328+ };
329+ ` ,
330+ runner ,
331+ { IsTCGCNeeded : true } ,
332+ ) ;
333+ const context = createEmitterContext ( program ) ;
334+ const sdkContext = await createCSharpSdkContext ( context ) ;
335+ const [ root ] = createModel ( sdkContext ) ;
336+
337+ // An enum nested two levels deep (Foo -> Bar -> Priority) must still
338+ // be captured when the entire graph is only reachable via a
339+ // protocol-only paging operation.
340+ const priorityEnum = root . enums . find ( ( e ) => e . name === "Priority" ) ;
341+ ok (
342+ priorityEnum ,
343+ `Expected enum 'Priority' to be present in code model enums. Found: ${ root . enums . map ( ( e ) => e . name ) . join ( ", " ) } ` ,
344+ ) ;
345+
346+ const barModel = root . models . find ( ( m ) => m . name === "Bar" ) ;
347+ ok (
348+ barModel ,
349+ `Expected model 'Bar' to be present in code model models. Found: ${ root . models . map ( ( m ) => m . name ) . join ( ", " ) } ` ,
350+ ) ;
351+
352+ const fooModel = root . models . find ( ( m ) => m . name === "Foo" ) ;
353+ ok (
354+ fooModel ,
355+ `Expected model 'Foo' to be present in code model models. Found: ${ root . models . map ( ( m ) => m . name ) . join ( ", " ) } ` ,
356+ ) ;
357+ } ) ;
266358} ) ;
267359
268360describe ( "Continuation token operations" , ( ) => {
0 commit comments