Skip to content

Commit 60f7bae

Browse files
Implement nextLink paging (#6353)
Fixes #6290
1 parent d463a41 commit 60f7bae

File tree

54 files changed

+1589
-111
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+1589
-111
lines changed

packages/http-client-csharp/emitter/test/Unit/operation-paging.test.ts

+31
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,37 @@ describe("Next link operations", () => {
4848
strictEqual(paging.NextLink?.ResponseSegments[0], "next");
4949
});
5050

51+
// skipped until https://github.com/Azure/typespec-azure/issues/2341 is fixed
52+
it.skip("next link as response header", async () => {
53+
const program = await typeSpecCompile(
54+
`
55+
@list
56+
op link(): {
57+
@pageItems
58+
items: Foo[];
59+
60+
@header @nextLink
61+
next?: url;
62+
};
63+
model Foo {
64+
bar: string;
65+
baz: int32;
66+
};
67+
`,
68+
runner,
69+
);
70+
const context = createEmitterContext(program);
71+
const sdkContext = await createCSharpSdkContext(context);
72+
const root = createModel(sdkContext);
73+
const paging = root.Clients[0].Operations[0].Paging;
74+
ok(paging);
75+
ok(paging.ItemPropertySegments);
76+
strictEqual(paging.ItemPropertySegments[0], "items");
77+
strictEqual(paging.NextLink?.ResponseLocation, ResponseLocation.Header);
78+
strictEqual(paging.NextLink?.ResponseSegments.length, 1);
79+
strictEqual(paging.NextLink?.ResponseSegments[0], "next");
80+
});
81+
5182
// skipped until https://github.com/Azure/typespec-azure/issues/2287 is fixed
5283
it.skip("next link with nested property", async () => {
5384
const program = await typeSpecCompile(

packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/src/ClientModelExtensions.cs

-19
This file was deleted.

packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/src/Primitives/ScmKnownParameters.cs

+3
Original file line numberDiff line numberDiff line change
@@ -58,5 +58,8 @@ public static ParameterProvider ClientOptions(CSharpType clientOptionsType)
5858
};
5959

6060
public static readonly ParameterProvider ContentType = new("contentType", $"The contentType to use which has the multipart/form-data boundary.", typeof(string), wireInfo: new PropertyWireInformation(SerializationFormat.Default, true, false, false, false, "Content-Type"));
61+
62+
public static readonly ParameterProvider Endpoint =
63+
new ParameterProvider("endpoint", FormattableStringHelpers.Empty, typeof(Uri));
6164
}
6265
}

packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/src/Providers/Abstractions/ClientResponseApi.cs

+6
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ protected ClientResponseApi(Type type, ValueExpression original) : base(type, or
3232

3333
public abstract CSharpType ClientResponseOfTType { get; }
3434

35+
public abstract CSharpType ClientCollectionResponseType { get; }
36+
public abstract CSharpType ClientCollectionAsyncResponseType { get; }
37+
38+
public abstract CSharpType ClientCollectionResponseOfTType { get; }
39+
public abstract CSharpType ClientCollectionAsyncResponseOfTType { get; }
40+
3541
public abstract CSharpType ClientResponseExceptionType { get; }
3642
}
3743
}

packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/src/Providers/Abstractions/HttpResponseApi.cs

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ protected HttpResponseApi(Type type, ValueExpression original) : base(type, orig
2121

2222
public abstract ScopedApi<bool> IsError();
2323

24+
public abstract ScopedApi<bool> TryGetHeader(string name, out ScopedApi<string>? value);
25+
2426
public abstract CSharpType HttpResponseType { get; }
2527

2628
public abstract HttpResponseApi FromExpression(ValueExpression original);

packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/src/Providers/Abstractions/IClientResponseApi.cs

+8
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,13 @@ public interface IClientResponseApi : IExpressionApi<ClientResponseApi>
1212
CSharpType ClientResponseType { get; }
1313

1414
CSharpType ClientResponseOfTType { get; }
15+
16+
CSharpType ClientCollectionResponseType { get; }
17+
18+
CSharpType ClientCollectionAsyncResponseType { get; }
19+
20+
CSharpType ClientCollectionResponseOfTType { get; }
21+
22+
CSharpType ClientCollectionAsyncResponseOfTType { get; }
1523
}
1624
}

packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/src/Providers/ClientResultProvider.cs

+4
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ public ClientResultProvider(ValueExpression clientResult) : base(typeof(ClientRe
2222
public override CSharpType ClientResponseType => typeof(ClientResult);
2323

2424
public override CSharpType ClientResponseOfTType => typeof(ClientResult<>);
25+
public override CSharpType ClientCollectionResponseType => typeof(CollectionResult);
26+
public override CSharpType ClientCollectionAsyncResponseType => typeof(AsyncCollectionResult);
27+
public override CSharpType ClientCollectionResponseOfTType => typeof(CollectionResult<>);
28+
public override CSharpType ClientCollectionAsyncResponseOfTType => typeof(AsyncCollectionResult<>);
2529

2630
public override CSharpType ClientResponseExceptionType => typeof(ClientResultException);
2731

0 commit comments

Comments
 (0)