Skip to content

Commit 6ab8036

Browse files
authored
fix(dotnet): update README templates for correct BatchCheck documenta… (#663)
2 parents f95f898 + ebb4176 commit 6ab8036

File tree

4 files changed

+113
-49
lines changed

4 files changed

+113
-49
lines changed

config/clients/dotnet/config.overrides.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"testPackageGuid": "d119dfae-509a-4eba-a973-645b739356fc",
1212
"packageName": "OpenFga.Sdk",
1313
"testPackageName": "OpenFga.Sdk.Test",
14-
"packageVersion": "0.8.0",
14+
"packageVersion": "0.9.0",
1515
"licenseUrl": "https://github.com/openfga/dotnet-sdk/blob/main/LICENSE",
1616
"fossaComplianceNoticeId": "f8ac2ec4-84fc-44f4-a617-5800cd3d180e",
1717
"termsOfService": "",

config/clients/dotnet/template/README_calling_api.mustache

Lines changed: 107 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -381,8 +381,15 @@ var response = await fgaClient.Check(body, options);
381381

382382
##### Batch Check
383383

384-
Run a set of [checks](#check). Batch Check will return `allowed: false` if it encounters an error, and will return the error in the body.
385-
If 429s or 5xxs are encountered, the underlying check will retry up to {{defaultMaxRetry}} times before giving up.
384+
Similar to [check](#check), but instead of checking a single user-object relationship, accepts a list of relationships to check. Requires OpenFGA server version [1.8.0](https://github.com/openfga/openfga/releases/tag/v1.8.0) or greater.
385+
386+
This method automatically handles:
387+
- Generating correlation IDs for checks that don't have one
388+
- Validating that correlation IDs are unique
389+
- Chunking requests based on `MaxBatchSize` (default: {{clientMaxBatchSize}})
390+
- Executing batches in parallel based on `MaxParallelRequests` (default: {{clientMaxMethodParallelRequests}})
391+
392+
If 429s or 5xxs are encountered, the underlying requests will retry up to {{defaultMaxRetry}} times before giving up.
386393

387394
> **Note**: The order of `BatchCheck` results is not guaranteed to match the order of the checks provided. Use `correlationId` to pair responses with requests.
388395

@@ -391,87 +398,139 @@ var options = new ClientBatchCheckOptions {
391398
// You can rely on the model id set in the configuration or override it for this specific request
392399
AuthorizationModelId = "01GXSA8YR785C4FYS3C0RTG7B1",
393400
MaxParallelRequests = 5, // Max number of requests to issue in parallel, defaults to {{clientMaxMethodParallelRequests}}
401+
MaxBatchSize = 20, // Max number of checks per batch request, defaults to {{clientMaxBatchSize}}
394402
};
395-
var body = new List<ClientCheckRequest>(){
396-
new() {
397-
User = "user:81684243-9356-4421-8fbf-a4f8d36aa31b",
398-
Relation = "viewer",
399-
Object = "document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a",
400-
ContextualTuples = new List<ClientTupleKey>() {
401-
new() {
402-
User = "user:81684243-9356-4421-8fbf-a4f8d36aa31b",
403-
Relation = "editor",
404-
Object = "document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a",
405-
}
403+
var body = new ClientBatchCheckRequest {
404+
Checks = new List<ClientBatchCheckItem>() {
405+
new() {
406+
User = "user:81684243-9356-4421-8fbf-a4f8d36aa31b",
407+
Relation = "viewer",
408+
Object = "document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a",
409+
ContextualTuples = new ContextualTupleKeys {
410+
TupleKeys = new List<TupleKey>() {
411+
new() {
412+
User = "user:81684243-9356-4421-8fbf-a4f8d36aa31b",
413+
Relation = "editor",
414+
Object = "document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a",
415+
}
416+
}
417+
},
418+
// CorrelationId is optional - will be auto-generated if not provided
406419
},
407-
},
408-
new() {
409-
User = "user:81684243-9356-4421-8fbf-a4f8d36aa31b",
410-
Relation = "admin",
411-
Object = "document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a",
412-
ContextualTuples = new List<ClientTupleKey>() {
413-
new() {
414-
User = "user:81684243-9356-4421-8fbf-a4f8d36aa31b",
415-
Relation = "editor",
416-
Object = "document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a",
417-
}
420+
new() {
421+
User = "user:81684243-9356-4421-8fbf-a4f8d36aa31b",
422+
Relation = "admin",
423+
Object = "document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a",
424+
ContextualTuples = new ContextualTupleKeys {
425+
TupleKeys = new List<TupleKey>() {
426+
new() {
427+
User = "user:81684243-9356-4421-8fbf-a4f8d36aa31b",
428+
Relation = "editor",
429+
Object = "document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a",
430+
}
431+
}
432+
},
433+
CorrelationId = "check-admin-01234", // Custom correlation ID
418434
},
419-
},
420-
new() {
421-
User = "user:81684243-9356-4421-8fbf-a4f8d36aa31b",
422-
Relation = "creator",
423-
Object = "document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a",
424-
},
425-
new() {
426-
User = "user:81684243-9356-4421-8fbf-a4f8d36aa31b",
427-
Relation = "deleter",
428-
Object = "document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a",
435+
new() {
436+
User = "user:81684243-9356-4421-8fbf-a4f8d36aa31b",
437+
Relation = "creator",
438+
Object = "document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a",
439+
},
440+
new() {
441+
User = "user:81684243-9356-4421-8fbf-a4f8d36aa31b",
442+
Relation = "deleter",
443+
Object = "document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a",
444+
}
429445
}
430446
};
431447

432448
var response = await fgaClient.BatchCheck(body, options);
433449

434450
/*
435-
response.Responses = [{
451+
response.Result = [{
452+
CorrelationId: "01JA8PM3QM7VBPGB8KMPK8SBD5", // Auto-generated
436453
Allowed: false,
437454
Request: {
438455
User: "user:81684243-9356-4421-8fbf-a4f8d36aa31b",
439456
Relation: "viewer",
440457
Object: "document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a",
441-
ContextualTuples: [{
442-
User: "user:81684243-9356-4421-8fbf-a4f8d36aa31b",
443-
Relation: "editor",
444-
Object: "document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a"
445-
}]
458+
ContextualTuples: { ... }
446459
}
447460
}, {
461+
CorrelationId: "check-admin-01234", // Custom ID
448462
Allowed: false,
449463
Request: {
450464
User: "user:81684243-9356-4421-8fbf-a4f8d36aa31b",
451465
Relation: "admin",
452466
Object: "document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a",
453-
ContextualTuples: [{
454-
User: "user:81684243-9356-4421-8fbf-a4f8d36aa31b",
455-
Relation: "editor",
456-
Object: "document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a"
457-
}]
467+
ContextualTuples: { ... }
458468
}
459469
}, {
470+
CorrelationId: "01JA8PMM6A90NV5ET0F28CYSZQ",
460471
Allowed: false,
461472
Request: {
462473
User: "user:81684243-9356-4421-8fbf-a4f8d36aa31b",
463474
Relation: "creator",
464475
Object: "document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a",
465476
},
466-
Error: <FgaError ...>
477+
Error: { Message: "...", InputError: "..." } // Error details if check failed
467478
}, {
479+
CorrelationId: "01JA8PN7K2XBVW9R3FQMH5JZTA",
468480
Allowed: true,
469481
Request: {
470482
User: "user:81684243-9356-4421-8fbf-a4f8d36aa31b",
471483
Relation: "deleter",
472484
Object: "document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a",
473-
}},
474-
]
485+
}
486+
}]
487+
*/
488+
```
489+
490+
##### Client Batch Check
491+
492+
Run a set of [checks](#check) by making individual `/check` API calls in parallel on the client side. This is useful for small batches (< 10 checks) when you want more control over each individual request.
493+
494+
For larger batches or to use the server-side batch endpoint, use [`BatchCheck`](#batch-check) instead.
495+
496+
```csharp
497+
var options = new ClientBatchCheckClientOptions {
498+
AuthorizationModelId = "01GXSA8YR785C4FYS3C0RTG7B1",
499+
MaxParallelRequests = 5, // Max number of requests to issue in parallel, defaults to {{clientMaxMethodParallelRequests}}
500+
};
501+
var body = new List<ClientCheckRequest>() {
502+
new() {
503+
User = "user:81684243-9356-4421-8fbf-a4f8d36aa31b",
504+
Relation = "viewer",
505+
Object = "document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a",
506+
},
507+
new() {
508+
User = "user:81684243-9356-4421-8fbf-a4f8d36aa31b",
509+
Relation = "admin",
510+
Object = "document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a",
511+
}
512+
};
513+
514+
var response = await fgaClient.ClientBatchCheck(body, options);
515+
516+
/*
517+
response.Responses = [{
518+
Allowed: false,
519+
Request: {
520+
User: "user:81684243-9356-4421-8fbf-a4f8d36aa31b",
521+
Relation: "viewer",
522+
Object: "document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a"
523+
},
524+
Error: null
525+
}, {
526+
Allowed: true,
527+
Request: {
528+
User: "user:81684243-9356-4421-8fbf-a4f8d36aa31b",
529+
Relation: "admin",
530+
Object: "document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a"
531+
},
532+
Error: null
533+
}]
475534
*/
476535
```
477536

config/clients/dotnet/template/README_initializing.mustache

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ namespace Example {
7878
Credentials = new Credentials() {
7979
Method = CredentialsMethod.ClientCredentials,
8080
Config = new CredentialsConfig() {
81+
// API Token Issuer can contain:
82+
// - a scheme, defaults to https
83+
// - a path, defaults to /oauth/token
84+
// - a port
8185
ApiTokenIssuer = Environment.GetEnvironmentVariable("FGA_API_TOKEN_ISSUER"),
8286
ApiAudience = Environment.GetEnvironmentVariable("FGA_API_AUDIENCE"),
8387
ClientId = Environment.GetEnvironmentVariable("FGA_CLIENT_ID"),

config/common/files/README.mustache

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
- [Relationship Queries](#relationship-queries)
3838
- [Check](#check)
3939
- [Batch Check](#batch-check)
40+
- [Client Batch Check](#client-batch-check)
4041
- [Expand](#expand)
4142
- [List Objects](#list-objects)
4243
{{#supportsStreamedListObjects}}

0 commit comments

Comments
 (0)