Skip to content

Commit 6f4bcaa

Browse files
docs: Add migration guides (box/box-codegen#867) (#1518)
1 parent 9451d78 commit 6f4bcaa

File tree

7 files changed

+1218
-645
lines changed

7 files changed

+1218
-645
lines changed

.codegen.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{ "engineHash": "fa0419f", "specHash": "fa34496", "version": "10.1.0" }
1+
{ "engineHash": "192deac", "specHash": "fa34496", "version": "10.1.0" }

migration-guides/from-box-java-sdk-gen-v0-to-box-java-sdk-v10.md renamed to migration-guides/from-box-java-sdk-gen-v0-to-box-java-sdk.md

Lines changed: 104 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1-
# Migration guide from beta release (v0.X.Y) of the `box-java-sdk-gen` to the v10 version of the `box-java-sdk`
1+
# Migration guide from beta release (v0.X.Y) of the `box-java-sdk-gen` to the `box-java-sdk`
2+
3+
Note: This guide applies only to migrations targeting Box Java SDK v5.X.Y or v10.X.Y.
4+
It does not apply to other major versions (e.g., v6.X, v11.X).
25

36
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
47
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
58

9+
- [Introduction](#introduction)
610
- [Installation](#installation)
711
- [How to migrate](#how-to-migrate)
812
- [Maven](#maven)
@@ -11,20 +15,39 @@
1115
- [How to migrate](#how-to-migrate-1)
1216
- [Removed unused models from schemas namespace](#removed-unused-models-from-schemas-namespace)
1317
- [How to migrate](#how-to-migrate-2)
18+
- [Usage](#usage)
19+
- [Using the Box Java SDK v10](#using-the-box-java-sdk-v10)
20+
- [Using the Box Java SDK v5](#using-the-box-java-sdk-v5)
1421

1522
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
1623

24+
## Introduction
25+
26+
From the `box-java-sdk-gen` you can migrate either to v5 or v10 of the Box Java SDK.
27+
Your choice should depend on whether you want to continue using the manually maintained SDK (Box Java SDK v4) alongside the generated one or not.
28+
29+
The v5 version of the Box Java SDK consolidates both the legacy SDK package `com.box.sdk` and the generated one `com.box.sdkgen`.
30+
31+
- If previously you were using both artifacts `box-java-sdk` v4 and `box-java-sdk-gen` v0, migrate to v5 version of the Box Java SDK which consolidates `com.box.sdk` and `com.box.sdkgen` packages.
32+
- If you were only using the generated artifact `box-java-sdk-gen`, migrate to v10 version of the Box Java SDK which contains only the generated `com.box.sdkgen` package.
33+
34+
| Scenario | Your current usage | Recommended target | Packages included in target | Why this choice | Notes |
35+
| -------------------------------------------- | ---------------------------------------------------------- | ------------------ | ----------------------------------------------------- | ------------------------------------------------------------------------ | ------------------------------------------------------------------------------------ |
36+
| Using both manual and generated SDK together | `com.box.sdk` v4 + `com.box.sdkgen` v0 in the same project | v5.X.Y | `com.box.sdk` (manual) + `com.box.sdkgen` (generated) | Keep existing v4 code while adopting new features from the generated SDK | Run both modules side by side; use type aliases to avoid name conflicts if necessary |
37+
| Using only the generated SDK | `com.box.sdkgen` v0 only | v10.X.Y | `com.box.sdkgen` (generated) only | Clean upgrade path with no legacy module; simpler dependency surface | Best when you don’t need the manual `com.box.sdk` package |
38+
1739
## Installation
1840

19-
In order to start using v10 version of the Box Java SDK, you need to change the dependency in your project.
41+
In order to start using v5 or v10 version of the Box Java SDK, you need to change the dependency in your project.
2042
The artifact name has changed from `com.box:box-java-sdk-gen` to `com.box:box-java-sdk`.
21-
You also need to set the version to `10.0.0` or higher. You can find the latest version on [Maven Central](https://search.maven.org/artifact/com.box/box-java-sdk).
43+
You also need to set the version to `5.X.Y` if you are migrating to v5 or `10.X.Y` if you are migrating to v10.
44+
You can find the latest version on [Maven Central](https://search.maven.org/artifact/com.box/box-java-sdk).
2245

2346
### How to migrate
2447

2548
#### Maven
2649

27-
To start using v10 version of Box Java SDK in your Maven project replace the dependency in your `pom.xml` file.
50+
To start using v5 or v10 version of Box Java SDK in your Maven project replace the dependency in your `pom.xml` file.
2851

2952
**Old (`box-java-sdk-gen-v0`)**
3053

@@ -46,9 +69,19 @@ To start using v10 version of Box Java SDK in your Maven project replace the dep
4669
</dependency>
4770
```
4871

72+
**New (`box-java-sdk-v5`)**
73+
74+
```xml
75+
<dependency>
76+
<groupId>com.box</groupId>
77+
<artifactId>box-java-sdk</artifactId>
78+
<version>5.0.0</version>
79+
</dependency>
80+
```
81+
4982
#### Gradle
5083

51-
To start using v10 version of Box Java SDK in your Gradle project replace the dependency in your `build.gradle` file.
84+
To start using v5 or v10 version of Box Java SDK in your Gradle project replace the dependency in your `build.gradle` file.
5285

5386
**Old (`box-java-sdk-gen-v0`)**
5487

@@ -62,6 +95,12 @@ implementation 'com.box:box-java-sdk-gen:0.8.0'
6295
implementation 'com.box:box-java-sdk:10.0.0'
6396
```
6497

98+
**New (`box-java-sdk-v5`)**
99+
100+
```groovy
101+
implementation 'com.box:box-java-sdk:5.0.0'
102+
```
103+
65104
## Union classes name changes
66105

67106
In the beta version of the `box-java-sdk-gen` our `OneOf` class names (representing unions from the OpenAPI specification)
@@ -147,3 +186,63 @@ Here is the full list of removed types:
147186
| WorkflowFull |
148187

149188
If your code references any of these types, remove those references.
189+
190+
## Usage
191+
192+
### Using the Box Java SDK v10
193+
194+
After migration from `box-java-sdk-gen` to the `box-java-sdk` v10, you can still use the `com.box.sdkgen` package in the same way as before.
195+
To access the client for interacting with the Box API, simply import `BoxClient` and any other necessary classes from the `com.box.sdkgen` package.
196+
197+
```java
198+
import com.box.sdkgen.client.BoxClient;
199+
import com.box.sdkgen.box.developertokenauth.BoxDeveloperTokenAuth;
200+
201+
BoxDeveloperTokenAuth auth = new BoxDeveloperTokenAuth("DEVELOPER_TOKEN");
202+
BoxClient client = new BoxClient(auth);
203+
client.folders.getFolderItems("0").getEntries().forEach(item -> {
204+
System.out.println(item.toString());
205+
});
206+
```
207+
208+
### Using the Box Java SDK v5
209+
210+
After migration to Box Java SDK v5, you can use both the manual Box Java SDK package `com.box.sdk` and the generated one `com.box.sdkgen`.
211+
You just need to import the required classes from the appropriate package depending on which SDK you intend to use.
212+
If both packages contain classes with the same name, you can use fully qualified names to resolve any naming conflicts.
213+
214+
```java
215+
import com.box.sdk.BoxConfig;
216+
import com.box.sdk.BoxDeveloperEditionAPIConnection;
217+
218+
import com.box.sdk.BoxFolder;
219+
import com.box.sdkgen.box.jwtauth.BoxJWTAuth;
220+
import com.box.sdkgen.box.jwtauth.JWTConfig;
221+
import com.box.sdkgen.client.BoxClient;
222+
import com.box.sdkgen.managers.folders.UpdateFolderByIdRequestBody;
223+
import com.box.sdkgen.schemas.folder.Folder;
224+
225+
import java.io.FileReader;
226+
import java.io.Reader;
227+
228+
public class Main {
229+
public static void main(String[] args) throws Exception {
230+
231+
Reader reader = new FileReader("src/example/config/config.json");
232+
BoxConfig boxConfig = BoxConfig.readFrom(reader);
233+
BoxDeveloperEditionAPIConnection api = BoxDeveloperEditionAPIConnection.getAppEnterpriseConnection(boxConfig);
234+
235+
JWTConfig config = JWTConfig.fromConfigFile("src/example/config/config.json");
236+
BoxJWTAuth auth = new BoxJWTAuth(config);
237+
BoxClient client = new BoxClient(auth);
238+
239+
BoxFolder rootFolder = new BoxFolder(api, "0");
240+
BoxFolder.Info subfolder = rootFolder.createFolder("My Subfolder");
241+
Folder updatedFolder = client.getFolders().updateFolderById(
242+
subfolder.getID(),
243+
new UpdateFolderByIdRequestBody.Builder().name("My Updated Subfolder").build()
244+
);
245+
System.out.println("Created folder with ID " + subfolder.getID() + " has been updated to " + updatedFolder.getName());
246+
}
247+
}
248+
```

0 commit comments

Comments
 (0)