Skip to content

Commit 5cd0fde

Browse files
feat: Support Box Doc Gen API (box/box-codegen#644) (#378)
1 parent e8863fc commit 5cd0fde

File tree

61 files changed

+2577
-1
lines changed

Some content is hidden

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

61 files changed

+2577
-1
lines changed

.codegen.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{ "engineHash": "5ab9c2b", "specHash": "091b558", "version": "1.5.0" }
1+
{ "engineHash": "ead925a", "specHash": "091b558", "version": "1.5.0" }
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
using Microsoft.VisualStudio.TestTools.UnitTesting;
2+
using System;
3+
using System.Collections.ObjectModel;
4+
using System.Collections.Generic;
5+
using Box.Sdk.Gen.Internal;
6+
using Box.Sdk.Gen;
7+
using Box.Sdk.Gen.Schemas;
8+
9+
namespace Box.Sdk.Gen.Tests.Integration {
10+
[TestClass]
11+
public class DocgenManagerTests {
12+
public BoxClient client { get; }
13+
14+
public DocgenManagerTests() {
15+
client = new CommonsManager().GetDefaultClient();
16+
}
17+
[TestMethod]
18+
public async System.Threading.Tasks.Task TestDocgenBatchAndJobs() {
19+
FileFull uploadedFile = await new CommonsManager().UploadNewFileAsync();
20+
FolderFull folder = await new CommonsManager().CreateNewFolderAsync();
21+
DocGenTemplateBaseV2025R0 createdDocgenTemplate = await client.DocgenTemplate.CreateDocgenTemplateV2025R0Async(requestBody: new DocGenTemplateCreateRequestV2025R0(file: new FileReferenceV2025R0(id: uploadedFile.Id)));
22+
DocGenBatchBaseV2025R0 docgenBatch = await client.Docgen.CreateDocgenBatchV2025R0Async(requestBody: new DocGenBatchCreateRequestV2025R0(file: new FileReferenceV2025R0(id: uploadedFile.Id), inputSource: "api", destinationFolder: new DocGenBatchCreateRequestV2025R0DestinationFolderField(id: folder.Id), outputType: "pdf", documentGenerationData: Array.AsReadOnly(new [] {new DocGenDocumentGenerationDataV2025R0(generatedFileName: "test", userInput: new Dictionary<string, object>() { { "abc", "xyz" } })})));
23+
Assert.IsTrue(docgenBatch.Id != "");
24+
Assert.IsTrue(StringUtils.ToStringRepresentation(docgenBatch.Type?.Value) == "docgen_batch");
25+
DocGenJobsV2025R0 docgenBatchJobs = await client.Docgen.GetDocgenBatchJobByIdV2025R0Async(batchId: docgenBatch.Id);
26+
Assert.IsTrue(NullableUtils.Unwrap(docgenBatchJobs.Entries).Count >= 1);
27+
Assert.IsTrue(NullableUtils.Unwrap(docgenBatchJobs.Entries)[0].Id != "");
28+
Assert.IsTrue(StringUtils.ToStringRepresentation(NullableUtils.Unwrap(docgenBatchJobs.Entries)[0].Type) == "docgen_job");
29+
Assert.IsTrue(NullableUtils.Unwrap(docgenBatchJobs.Entries)[0].OutputType == "pdf");
30+
Assert.IsTrue(StringUtils.ToStringRepresentation(NullableUtils.Unwrap(docgenBatchJobs.Entries)[0].Status) != "");
31+
Assert.IsTrue(NullableUtils.Unwrap(docgenBatchJobs.Entries)[0].TemplateFile.Id == uploadedFile.Id);
32+
Assert.IsTrue(NullableUtils.Unwrap(docgenBatchJobs.Entries)[0].Batch.Id == docgenBatch.Id);
33+
DocGenJobsFullV2025R0 docgenJobs = await client.Docgen.GetDocgenJobsV2025R0Async();
34+
Assert.IsTrue(NullableUtils.Unwrap(docgenJobs.Entries).Count >= 1);
35+
Assert.IsTrue(NullableUtils.Unwrap(docgenJobs.Entries)[0].Batch.Id != "");
36+
Assert.IsTrue(NullableUtils.Unwrap(docgenJobs.Entries)[0].CreatedBy.Id != "");
37+
Assert.IsTrue(NullableUtils.Unwrap(docgenJobs.Entries)[0].Enterprise.Id != "");
38+
Assert.IsTrue(NullableUtils.Unwrap(docgenJobs.Entries)[0].Id != "");
39+
Assert.IsTrue(NullableUtils.Unwrap(docgenJobs.Entries)[0].OutputType != "");
40+
Assert.IsTrue(NullableUtils.Unwrap(docgenJobs.Entries)[0].Source != "");
41+
Assert.IsTrue(StringUtils.ToStringRepresentation(NullableUtils.Unwrap(docgenJobs.Entries)[0].Status) != "");
42+
Assert.IsTrue(StringUtils.ToStringRepresentation(NullableUtils.Unwrap(docgenJobs.Entries)[0].TemplateFile.Type) == "file");
43+
Assert.IsTrue(NullableUtils.Unwrap(docgenJobs.Entries)[0].TemplateFile.Id != "");
44+
Assert.IsTrue(StringUtils.ToStringRepresentation(NullableUtils.Unwrap(docgenJobs.Entries)[0].TemplateFileVersion.Type) == "file_version");
45+
Assert.IsTrue(NullableUtils.Unwrap(docgenJobs.Entries)[0].TemplateFileVersion.Id != "");
46+
Assert.IsTrue(StringUtils.ToStringRepresentation(NullableUtils.Unwrap(docgenJobs.Entries)[0].Type) == "docgen_job");
47+
DocGenJobV2025R0 docgenJob = await client.Docgen.GetDocgenJobByIdV2025R0Async(jobId: NullableUtils.Unwrap(docgenJobs.Entries)[0].Id);
48+
Assert.IsTrue(docgenJob.Batch.Id != "");
49+
Assert.IsTrue(docgenJob.Id != "");
50+
Assert.IsTrue(docgenJob.OutputType != "");
51+
Assert.IsTrue(StringUtils.ToStringRepresentation(docgenJob.Status?.Value) != "");
52+
Assert.IsTrue(StringUtils.ToStringRepresentation(docgenJob.TemplateFile.Type?.Value) == "file");
53+
Assert.IsTrue(docgenJob.TemplateFile.Id != "");
54+
Assert.IsTrue(StringUtils.ToStringRepresentation(docgenJob.TemplateFileVersion.Type?.Value) == "file_version");
55+
Assert.IsTrue(docgenJob.TemplateFileVersion.Id != "");
56+
Assert.IsTrue(StringUtils.ToStringRepresentation(docgenJob.Type?.Value) == "docgen_job");
57+
await client.Folders.DeleteFolderByIdAsync(folderId: folder.Id);
58+
await client.Files.DeleteFileByIdAsync(fileId: uploadedFile.Id);
59+
}
60+
61+
}
62+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using Microsoft.VisualStudio.TestTools.UnitTesting;
2+
using Box.Sdk.Gen.Internal;
3+
using Box.Sdk.Gen;
4+
using Box.Sdk.Gen.Schemas;
5+
6+
namespace Box.Sdk.Gen.Tests.Integration {
7+
[TestClass]
8+
public class DocgenTemplateManagerTests {
9+
public BoxClient client { get; }
10+
11+
public DocgenTemplateManagerTests() {
12+
client = new CommonsManager().GetDefaultClient();
13+
}
14+
[TestMethod]
15+
public async System.Threading.Tasks.Task TestDocgenTemplateCrud() {
16+
FileFull file = await new CommonsManager().UploadNewFileAsync();
17+
DocGenTemplateBaseV2025R0 createdDocgenTemplate = await client.DocgenTemplate.CreateDocgenTemplateV2025R0Async(requestBody: new DocGenTemplateCreateRequestV2025R0(file: new FileReferenceV2025R0(id: file.Id)));
18+
DocGenTemplatesV2025R0 docgenTemplates = await client.DocgenTemplate.GetDocgenTemplatesV2025R0Async();
19+
Assert.IsTrue(NullableUtils.Unwrap(docgenTemplates.Entries).Count > 0);
20+
DocGenTemplateV2025R0 fetchedDocgenTemplate = await client.DocgenTemplate.GetDocgenTemplateByIdV2025R0Async(templateId: NullableUtils.Unwrap(createdDocgenTemplate.File).Id);
21+
Assert.IsTrue(NullableUtils.Unwrap(fetchedDocgenTemplate.File).Id == NullableUtils.Unwrap(createdDocgenTemplate.File).Id);
22+
DocGenTagsV2025R0 docgenTemplateTags = await client.DocgenTemplate.GetDocgenTemplateTagsV2025R0Async(templateId: NullableUtils.Unwrap(fetchedDocgenTemplate.File).Id);
23+
DocGenJobsV2025R0 docgenTemplateJobs = await client.DocgenTemplate.GetDocgenTemplateJobByIdV2025R0Async(templateId: NullableUtils.Unwrap(fetchedDocgenTemplate.File).Id);
24+
Assert.IsTrue(NullableUtils.Unwrap(docgenTemplateJobs.Entries).Count == 0);
25+
await client.DocgenTemplate.DeleteDocgenTemplateByIdV2025R0Async(templateId: NullableUtils.Unwrap(createdDocgenTemplate.File).Id);
26+
await client.Files.DeleteFileByIdAsync(fileId: file.Id);
27+
}
28+
29+
}
30+
}

Box.Sdk.Gen/Client/BoxClient.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,10 @@ public class BoxClient : IBoxClient {
149149

150150
public IAiManager Ai { get; }
151151

152+
public IDocgenTemplateManager DocgenTemplate { get; }
153+
154+
public IDocgenManager Docgen { get; }
155+
152156
public BoxClient(IAuthentication auth, NetworkSession? networkSession = default) {
153157
Auth = auth;
154158
NetworkSession = networkSession ?? new NetworkSession(baseUrls: new BaseUrls());
@@ -222,6 +226,8 @@ public BoxClient(IAuthentication auth, NetworkSession? networkSession = default)
222226
SignTemplates = new SignTemplatesManager(networkSession: this.NetworkSession) { Auth = this.Auth };
223227
IntegrationMappings = new IntegrationMappingsManager(networkSession: this.NetworkSession) { Auth = this.Auth };
224228
Ai = new AiManager(networkSession: this.NetworkSession) { Auth = this.Auth };
229+
DocgenTemplate = new DocgenTemplateManager(networkSession: this.NetworkSession) { Auth = this.Auth };
230+
Docgen = new DocgenManager(networkSession: this.NetworkSession) { Auth = this.Auth };
225231
}
226232
/// <summary>
227233
/// Make a custom http request using the client authentication and network session.

Box.Sdk.Gen/Client/IBoxClient.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,5 +147,9 @@ public interface IBoxClient {
147147

148148
public IAiManager Ai { get => throw new System.NotImplementedException("This method needs to be implemented by the derived class before calling it."); }
149149

150+
public IDocgenTemplateManager DocgenTemplate { get => throw new System.NotImplementedException("This method needs to be implemented by the derived class before calling it."); }
151+
152+
public IDocgenManager Docgen { get => throw new System.NotImplementedException("This method needs to be implemented by the derived class before calling it."); }
153+
150154
}
151155
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using Box.Sdk.Gen;
2+
using System.Collections.Generic;
3+
using System.Collections.ObjectModel;
4+
using Box.Sdk.Gen.Internal;
5+
using Box.Sdk.Gen.Schemas;
6+
using Box.Sdk.Gen.Parameters;
7+
8+
namespace Box.Sdk.Gen.Managers {
9+
public class CreateDocgenBatchV2025R0Headers {
10+
/// <summary>
11+
/// Version header
12+
/// </summary>
13+
public StringEnum<BoxVersionHeaderV2025R0> BoxVersion { get; }
14+
15+
/// <summary>
16+
/// Extra headers that will be included in the HTTP request.
17+
/// </summary>
18+
public Dictionary<string, string?> ExtraHeaders { get; }
19+
20+
public CreateDocgenBatchV2025R0Headers(BoxVersionHeaderV2025R0 boxVersion = BoxVersionHeaderV2025R0._20250, Dictionary<string, string?>? extraHeaders = default) {
21+
BoxVersion = boxVersion;
22+
ExtraHeaders = extraHeaders ?? new Dictionary<string, string?>() { };
23+
}
24+
}
25+
}
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
using Box.Sdk.Gen;
2+
using System.Collections.Generic;
3+
using System.Collections.ObjectModel;
4+
using Box.Sdk.Gen.Internal;
5+
using Box.Sdk.Gen.Schemas;
6+
using Box.Sdk.Gen.Parameters;
7+
8+
namespace Box.Sdk.Gen.Managers {
9+
public class DocgenManager : IDocgenManager {
10+
public IAuthentication? Auth { get; init; }
11+
12+
public NetworkSession NetworkSession { get; }
13+
14+
public DocgenManager(NetworkSession? networkSession = default) {
15+
NetworkSession = networkSession ?? new NetworkSession();
16+
}
17+
/// <summary>
18+
/// Get details of the Box Doc Gen job.
19+
/// </summary>
20+
/// <param name="jobId">
21+
/// Box Doc Gen job ID.
22+
/// Example: 123
23+
/// </param>
24+
/// <param name="headers">
25+
/// Headers of getDocgenJobByIdV2025R0 method
26+
/// </param>
27+
/// <param name="cancellationToken">
28+
/// Token used for request cancellation.
29+
/// </param>
30+
public async System.Threading.Tasks.Task<DocGenJobV2025R0> GetDocgenJobByIdV2025R0Async(string jobId, GetDocgenJobByIdV2025R0Headers? headers = default, System.Threading.CancellationToken? cancellationToken = null) {
31+
headers = headers ?? new GetDocgenJobByIdV2025R0Headers();
32+
Dictionary<string, string> headersMap = Utils.PrepareParams(map: DictionaryUtils.MergeDictionaries(new Dictionary<string, string?>() { { "box-version", StringUtils.ToStringRepresentation(headers.BoxVersion) } }, headers.ExtraHeaders));
33+
FetchResponse response = await this.NetworkSession.NetworkClient.FetchAsync(options: new FetchOptions(url: string.Concat(this.NetworkSession.BaseUrls.BaseUrl, "/2.0/docgen_jobs/", StringUtils.ToStringRepresentation(jobId)), method: "GET", responseFormat: Box.Sdk.Gen.ResponseFormat.Json) { Headers = headersMap, Auth = this.Auth, NetworkSession = this.NetworkSession, CancellationToken = cancellationToken }).ConfigureAwait(false);
34+
return SimpleJsonSerializer.Deserialize<DocGenJobV2025R0>(NullableUtils.Unwrap(response.Data));
35+
}
36+
37+
/// <summary>
38+
/// Lists all Box Doc Gen jobs for a user.
39+
/// </summary>
40+
/// <param name="queryParams">
41+
/// Query parameters of getDocgenJobsV2025R0 method
42+
/// </param>
43+
/// <param name="headers">
44+
/// Headers of getDocgenJobsV2025R0 method
45+
/// </param>
46+
/// <param name="cancellationToken">
47+
/// Token used for request cancellation.
48+
/// </param>
49+
public async System.Threading.Tasks.Task<DocGenJobsFullV2025R0> GetDocgenJobsV2025R0Async(GetDocgenJobsV2025R0QueryParams? queryParams = default, GetDocgenJobsV2025R0Headers? headers = default, System.Threading.CancellationToken? cancellationToken = null) {
50+
queryParams = queryParams ?? new GetDocgenJobsV2025R0QueryParams();
51+
headers = headers ?? new GetDocgenJobsV2025R0Headers();
52+
Dictionary<string, string> queryParamsMap = Utils.PrepareParams(map: new Dictionary<string, string?>() { { "marker", StringUtils.ToStringRepresentation(queryParams.Marker) }, { "limit", StringUtils.ToStringRepresentation(queryParams.Limit) } });
53+
Dictionary<string, string> headersMap = Utils.PrepareParams(map: DictionaryUtils.MergeDictionaries(new Dictionary<string, string?>() { { "box-version", StringUtils.ToStringRepresentation(headers.BoxVersion) } }, headers.ExtraHeaders));
54+
FetchResponse response = await this.NetworkSession.NetworkClient.FetchAsync(options: new FetchOptions(url: string.Concat(this.NetworkSession.BaseUrls.BaseUrl, "/2.0/docgen_jobs"), method: "GET", responseFormat: Box.Sdk.Gen.ResponseFormat.Json) { Parameters = queryParamsMap, Headers = headersMap, Auth = this.Auth, NetworkSession = this.NetworkSession, CancellationToken = cancellationToken }).ConfigureAwait(false);
55+
return SimpleJsonSerializer.Deserialize<DocGenJobsFullV2025R0>(NullableUtils.Unwrap(response.Data));
56+
}
57+
58+
/// <summary>
59+
/// Lists Box Doc Gen jobs in a batch
60+
/// </summary>
61+
/// <param name="batchId">
62+
/// Box Doc Gen batch ID.
63+
/// Example: 123
64+
/// </param>
65+
/// <param name="queryParams">
66+
/// Query parameters of getDocgenBatchJobByIdV2025R0 method
67+
/// </param>
68+
/// <param name="headers">
69+
/// Headers of getDocgenBatchJobByIdV2025R0 method
70+
/// </param>
71+
/// <param name="cancellationToken">
72+
/// Token used for request cancellation.
73+
/// </param>
74+
public async System.Threading.Tasks.Task<DocGenJobsV2025R0> GetDocgenBatchJobByIdV2025R0Async(string batchId, GetDocgenBatchJobByIdV2025R0QueryParams? queryParams = default, GetDocgenBatchJobByIdV2025R0Headers? headers = default, System.Threading.CancellationToken? cancellationToken = null) {
75+
queryParams = queryParams ?? new GetDocgenBatchJobByIdV2025R0QueryParams();
76+
headers = headers ?? new GetDocgenBatchJobByIdV2025R0Headers();
77+
Dictionary<string, string> queryParamsMap = Utils.PrepareParams(map: new Dictionary<string, string?>() { { "marker", StringUtils.ToStringRepresentation(queryParams.Marker) }, { "limit", StringUtils.ToStringRepresentation(queryParams.Limit) } });
78+
Dictionary<string, string> headersMap = Utils.PrepareParams(map: DictionaryUtils.MergeDictionaries(new Dictionary<string, string?>() { { "box-version", StringUtils.ToStringRepresentation(headers.BoxVersion) } }, headers.ExtraHeaders));
79+
FetchResponse response = await this.NetworkSession.NetworkClient.FetchAsync(options: new FetchOptions(url: string.Concat(this.NetworkSession.BaseUrls.BaseUrl, "/2.0/docgen_batch_jobs/", StringUtils.ToStringRepresentation(batchId)), method: "GET", responseFormat: Box.Sdk.Gen.ResponseFormat.Json) { Parameters = queryParamsMap, Headers = headersMap, Auth = this.Auth, NetworkSession = this.NetworkSession, CancellationToken = cancellationToken }).ConfigureAwait(false);
80+
return SimpleJsonSerializer.Deserialize<DocGenJobsV2025R0>(NullableUtils.Unwrap(response.Data));
81+
}
82+
83+
/// <summary>
84+
/// Generates a document using a Box Doc Gen template.
85+
/// </summary>
86+
/// <param name="requestBody">
87+
/// Request body of createDocgenBatchV2025R0 method
88+
/// </param>
89+
/// <param name="headers">
90+
/// Headers of createDocgenBatchV2025R0 method
91+
/// </param>
92+
/// <param name="cancellationToken">
93+
/// Token used for request cancellation.
94+
/// </param>
95+
public async System.Threading.Tasks.Task<DocGenBatchBaseV2025R0> CreateDocgenBatchV2025R0Async(DocGenBatchCreateRequestV2025R0 requestBody, CreateDocgenBatchV2025R0Headers? headers = default, System.Threading.CancellationToken? cancellationToken = null) {
96+
headers = headers ?? new CreateDocgenBatchV2025R0Headers();
97+
Dictionary<string, string> headersMap = Utils.PrepareParams(map: DictionaryUtils.MergeDictionaries(new Dictionary<string, string?>() { { "box-version", StringUtils.ToStringRepresentation(headers.BoxVersion) } }, headers.ExtraHeaders));
98+
FetchResponse response = await this.NetworkSession.NetworkClient.FetchAsync(options: new FetchOptions(url: string.Concat(this.NetworkSession.BaseUrls.BaseUrl, "/2.0/docgen_batches"), method: "POST", contentType: "application/json", responseFormat: Box.Sdk.Gen.ResponseFormat.Json) { Headers = headersMap, Data = SimpleJsonSerializer.Serialize(requestBody), Auth = this.Auth, NetworkSession = this.NetworkSession, CancellationToken = cancellationToken }).ConfigureAwait(false);
99+
return SimpleJsonSerializer.Deserialize<DocGenBatchBaseV2025R0>(NullableUtils.Unwrap(response.Data));
100+
}
101+
102+
}
103+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using Box.Sdk.Gen;
2+
using System.Collections.Generic;
3+
using System.Collections.ObjectModel;
4+
using Box.Sdk.Gen.Internal;
5+
using Box.Sdk.Gen.Schemas;
6+
using Box.Sdk.Gen.Parameters;
7+
8+
namespace Box.Sdk.Gen.Managers {
9+
public class GetDocgenBatchJobByIdV2025R0Headers {
10+
/// <summary>
11+
/// Version header
12+
/// </summary>
13+
public StringEnum<BoxVersionHeaderV2025R0> BoxVersion { get; }
14+
15+
/// <summary>
16+
/// Extra headers that will be included in the HTTP request.
17+
/// </summary>
18+
public Dictionary<string, string?> ExtraHeaders { get; }
19+
20+
public GetDocgenBatchJobByIdV2025R0Headers(BoxVersionHeaderV2025R0 boxVersion = BoxVersionHeaderV2025R0._20250, Dictionary<string, string?>? extraHeaders = default) {
21+
BoxVersion = boxVersion;
22+
ExtraHeaders = extraHeaders ?? new Dictionary<string, string?>() { };
23+
}
24+
}
25+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using Box.Sdk.Gen;
2+
using System.Collections.Generic;
3+
using System.Collections.ObjectModel;
4+
using Box.Sdk.Gen.Internal;
5+
using Box.Sdk.Gen.Schemas;
6+
using Box.Sdk.Gen.Parameters;
7+
8+
namespace Box.Sdk.Gen.Managers {
9+
public class GetDocgenBatchJobByIdV2025R0QueryParams {
10+
/// <summary>
11+
/// Defines the position marker at which to begin returning results. This is
12+
/// used when paginating using marker-based pagination.
13+
///
14+
/// This requires `usemarker` to be set to `true`.
15+
/// </summary>
16+
public string? Marker { get; init; }
17+
18+
/// <summary>
19+
/// The maximum number of items to return per page.
20+
/// </summary>
21+
public long? Limit { get; init; }
22+
23+
public GetDocgenBatchJobByIdV2025R0QueryParams() {
24+
25+
}
26+
}
27+
}

0 commit comments

Comments
 (0)