Speakeasy API: The Subscriptions API manages subscriptions for CLI and registry events
For more information about the API: The Speakeasy Platform Documentation
JDK 11 or later is required.
The samples below show how a published SDK artifact is used:
Gradle:
implementation 'dev.speakeasyapi:javaclientsdk:7.23.0'
Maven:
<dependency>
<groupId>dev.speakeasyapi</groupId>
<artifactId>javaclientsdk</artifactId>
<version>7.23.0</version>
</dependency>
After cloning the git repository to your file system you can build the SDK artifact from source to the build
directory by running ./gradlew build
on *nix systems or gradlew.bat
on Windows systems.
If you wish to build from source and publish the SDK artifact to your local Maven repository (on your filesystem) then use the following command (after cloning the git repo locally):
On *nix:
./gradlew publishToMavenLocal -Pskip.signing
On Windows:
gradlew.bat publishToMavenLocal -Pskip.signing
package hello.world;
import dev.speakeasyapi.javaclientsdk.RyanTest;
import dev.speakeasyapi.javaclientsdk.models.errors.Error;
import dev.speakeasyapi.javaclientsdk.models.operations.GenerateCodeSamplePreviewResponse;
import dev.speakeasyapi.javaclientsdk.models.shared.CodeSampleSchemaInput;
import dev.speakeasyapi.javaclientsdk.models.shared.SchemaFile;
import dev.speakeasyapi.javaclientsdk.models.shared.Security;
import java.lang.Exception;
import java.nio.charset.StandardCharsets;
import java.util.List;
public class Application {
public static void main(String[] args) throws Error, Exception {
RyanTest sdk = RyanTest.builder()
.security(Security.builder()
.apiKey("<YOUR_API_KEY_HERE>")
.build())
.build();
CodeSampleSchemaInput req = CodeSampleSchemaInput.builder()
.languages(List.of(
"<value>",
"<value>"))
.schemaFile(SchemaFile.builder()
.content("0xc3dD8BfBef".getBytes(StandardCharsets.UTF_8))
.fileName("example.file")
.build())
.build();
GenerateCodeSamplePreviewResponse res = sdk.generateCodeSamplePreview()
.request(req)
.call();
if (res.twoHundredApplicationJsonResponseStream().isPresent()) {
// handle response
}
}
}
Available methods
- createRemoteSource - Configure a new remote source
- getBlob - Get blob for a particular digest
- getManifest - Get manifest for a particular reference
- getNamespaces - Each namespace contains many revisions.
- getRevisions
- getTags
- listRemoteSources - Get remote sources attached to a particular namespace
- postTags - Add tags to an existing revision
- preflight - Get access token for communicating with OCI distribution endpoints
- setVisibility - Set visibility of a namespace with an existing metadata entry
- getAccess - Get access allowances for a particular workspace
- getAccessToken - Get or refresh an access token for the current workspace.
- getUser - Get information about the current user.
- validateApiKey - Validate the current api key.
- getEventsByTarget - Load recent events for a particular workspace
- getTargets - Load targets for a particular workspace
- getTargetsDeprecated - Load targets for a particular workspace
- post - Post events for a specific workspace
- search - Search events for a particular workspace by any field
- checkAccess
- checkPublishingPRs
- checkPublishingSecrets
- configureCodeSamples
- configureMintlifyRepo
- configureTarget
- getAction
- getSetup
- linkGithub
- storePublishingSecrets
- triggerAction
- create - Create an organization
- createFreeTrial - Create a free trial for an organization
- get - Get organization
- getAll - Get organizations for a user
- getUsage - Get billing usage summary for a particular organization
- getChangesReportSignedUrl - Get the signed access url for the change reports for a particular document.
- getLintingReportSignedUrl - Get the signed access url for the linting reports for a particular document.
- uploadReport - Upload a report.
- generateCodeSamplePreview - Generate Code Sample previews from a file and configuration parameters.
- generateCodeSamplePreviewAsync - Initiate asynchronous Code Sample preview generation from a file and configuration parameters, receiving an async JobID response for polling.
- getCodeSamplePreviewAsync - Poll for the result of an asynchronous Code Sample preview generation.
- create - Shorten a URL.
- activateSubscriptionNamespace - Activate an ignored namespace for a subscription
- ignoreSubscriptionNamespace - Ignored a namespace for a subscription
- suggest - Generate suggestions for improving an OpenAPI document.
- suggestItems - Generate generic suggestions for a list of items.
- suggestOpenAPI - (DEPRECATED) Generate suggestions for improving an OpenAPI document.
- suggestOpenAPIRegistry - Generate suggestions for improving an OpenAPI document stored in the registry.
- create - Create a workspace
- createToken - Create a token for a particular workspace
- deleteToken - Delete a token for a particular workspace
- get - Get workspace by context
- getAll - Get workspaces for a user
- getByID - Get workspace
- getFeatureFlags - Get workspace feature flags
- getSettings - Get workspace settings
- getTeam - Get team members for a particular workspace
- getTokens - Get tokens for a particular workspace
- grantAccess - Grant a user access to a particular workspace
- revokeAccess - Revoke a user's access to a particular workspace
- update - Update workspace details
- updateSettings - Update workspace settings
You can override the default server globally using the .server(AvailableServers server)
builder method when initializing the SDK client instance. The selected server will then be used as the default on the operations that use it. This table lists the names associated with the available servers:
Name | Server |
---|---|
prod |
https://api.prod.speakeasyapi.dev |
package hello.world;
import dev.speakeasyapi.javaclientsdk.RyanTest;
import dev.speakeasyapi.javaclientsdk.models.errors.Error;
import dev.speakeasyapi.javaclientsdk.models.operations.GenerateCodeSamplePreviewResponse;
import dev.speakeasyapi.javaclientsdk.models.shared.CodeSampleSchemaInput;
import dev.speakeasyapi.javaclientsdk.models.shared.SchemaFile;
import dev.speakeasyapi.javaclientsdk.models.shared.Security;
import java.lang.Exception;
import java.nio.charset.StandardCharsets;
import java.util.List;
public class Application {
public static void main(String[] args) throws Error, Exception {
RyanTest sdk = RyanTest.builder()
.server(RyanTest.AvailableServers.PROD)
.security(Security.builder()
.apiKey("<YOUR_API_KEY_HERE>")
.build())
.build();
CodeSampleSchemaInput req = CodeSampleSchemaInput.builder()
.languages(List.of(
"<value>",
"<value>"))
.schemaFile(SchemaFile.builder()
.content("0xc3dD8BfBef".getBytes(StandardCharsets.UTF_8))
.fileName("example.file")
.build())
.build();
GenerateCodeSamplePreviewResponse res = sdk.generateCodeSamplePreview()
.request(req)
.call();
if (res.twoHundredApplicationJsonResponseStream().isPresent()) {
// handle response
}
}
}
The default server can also be overridden globally using the .serverURL(String serverUrl)
builder method when initializing the SDK client instance. For example:
package hello.world;
import dev.speakeasyapi.javaclientsdk.RyanTest;
import dev.speakeasyapi.javaclientsdk.models.errors.Error;
import dev.speakeasyapi.javaclientsdk.models.operations.GenerateCodeSamplePreviewResponse;
import dev.speakeasyapi.javaclientsdk.models.shared.CodeSampleSchemaInput;
import dev.speakeasyapi.javaclientsdk.models.shared.SchemaFile;
import dev.speakeasyapi.javaclientsdk.models.shared.Security;
import java.lang.Exception;
import java.nio.charset.StandardCharsets;
import java.util.List;
public class Application {
public static void main(String[] args) throws Error, Exception {
RyanTest sdk = RyanTest.builder()
.serverURL("https://api.prod.speakeasyapi.dev")
.security(Security.builder()
.apiKey("<YOUR_API_KEY_HERE>")
.build())
.build();
CodeSampleSchemaInput req = CodeSampleSchemaInput.builder()
.languages(List.of(
"<value>",
"<value>"))
.schemaFile(SchemaFile.builder()
.content("0xc3dD8BfBef".getBytes(StandardCharsets.UTF_8))
.fileName("example.file")
.build())
.build();
GenerateCodeSamplePreviewResponse res = sdk.generateCodeSamplePreview()
.request(req)
.call();
if (res.twoHundredApplicationJsonResponseStream().isPresent()) {
// handle response
}
}
}
Handling errors in this SDK should largely match your expectations. All operations return a response object or raise an exception.
By default, an API error will throw a models/errors/SDKError
exception. When custom error responses are specified for an operation, the SDK may also throw their associated exception. You can refer to respective Errors tables in SDK docs for more details on possible exception types for each operation. For example, the generateCodeSamplePreview
method throws the following exceptions:
Error Type | Status Code | Content Type |
---|---|---|
models/errors/Error | 4XX, 5XX | application/json |
package hello.world;
import dev.speakeasyapi.javaclientsdk.RyanTest;
import dev.speakeasyapi.javaclientsdk.models.errors.Error;
import dev.speakeasyapi.javaclientsdk.models.operations.GenerateCodeSamplePreviewResponse;
import dev.speakeasyapi.javaclientsdk.models.shared.CodeSampleSchemaInput;
import dev.speakeasyapi.javaclientsdk.models.shared.SchemaFile;
import dev.speakeasyapi.javaclientsdk.models.shared.Security;
import java.lang.Exception;
import java.nio.charset.StandardCharsets;
import java.util.List;
public class Application {
public static void main(String[] args) throws Error, Exception {
RyanTest sdk = RyanTest.builder()
.security(Security.builder()
.apiKey("<YOUR_API_KEY_HERE>")
.build())
.build();
CodeSampleSchemaInput req = CodeSampleSchemaInput.builder()
.languages(List.of(
"<value>",
"<value>"))
.schemaFile(SchemaFile.builder()
.content("0xc3dD8BfBef".getBytes(StandardCharsets.UTF_8))
.fileName("example.file")
.build())
.build();
GenerateCodeSamplePreviewResponse res = sdk.generateCodeSamplePreview()
.request(req)
.call();
if (res.twoHundredApplicationJsonResponseStream().isPresent()) {
// handle response
}
}
}
This SDK supports the following security schemes globally:
Name | Type | Scheme |
---|---|---|
apiKey |
apiKey | API key |
bearer |
http | HTTP Bearer |
workspaceIdentifier |
apiKey | API key |
You can set the security parameters through the security
builder method when initializing the SDK client instance. The selected scheme will be used by default to authenticate with the API for all operations that support it. For example:
package hello.world;
import dev.speakeasyapi.javaclientsdk.RyanTest;
import dev.speakeasyapi.javaclientsdk.models.errors.Error;
import dev.speakeasyapi.javaclientsdk.models.operations.GenerateCodeSamplePreviewResponse;
import dev.speakeasyapi.javaclientsdk.models.shared.CodeSampleSchemaInput;
import dev.speakeasyapi.javaclientsdk.models.shared.SchemaFile;
import dev.speakeasyapi.javaclientsdk.models.shared.Security;
import java.lang.Exception;
import java.nio.charset.StandardCharsets;
import java.util.List;
public class Application {
public static void main(String[] args) throws Error, Exception {
RyanTest sdk = RyanTest.builder()
.security(Security.builder()
.apiKey("<YOUR_API_KEY_HERE>")
.build())
.build();
CodeSampleSchemaInput req = CodeSampleSchemaInput.builder()
.languages(List.of(
"<value>",
"<value>"))
.schemaFile(SchemaFile.builder()
.content("0xc3dD8BfBef".getBytes(StandardCharsets.UTF_8))
.fileName("example.file")
.build())
.build();
GenerateCodeSamplePreviewResponse res = sdk.generateCodeSamplePreview()
.request(req)
.call();
if (res.twoHundredApplicationJsonResponseStream().isPresent()) {
// handle response
}
}
}
A parameter is configured globally. This parameter may be set on the SDK client instance itself during initialization. When configured as an option during SDK initialization, This global value will be used as the default on the operations that use it. When such operations are called, there is a place in each to override the global value, if needed.
For example, you can set workspace_id
to "<id>"
at SDK initialization and then you do not have to pass the same value on calls to operations like getAccessToken
. But if you want to do so you may, which will locally override the global setting. See the example code below for a demonstration.
The following global parameter is available.
Name | Type | Description |
---|---|---|
workspaceId | java.lang.String | The workspaceId parameter. |
package hello.world;
import dev.speakeasyapi.javaclientsdk.RyanTest;
import dev.speakeasyapi.javaclientsdk.models.errors.Error;
import dev.speakeasyapi.javaclientsdk.models.operations.GetAccessTokenRequest;
import dev.speakeasyapi.javaclientsdk.models.operations.GetAccessTokenResponse;
import java.lang.Exception;
public class Application {
public static void main(String[] args) throws Error, Exception {
RyanTest sdk = RyanTest.builder()
.build();
GetAccessTokenRequest req = GetAccessTokenRequest.builder()
.workspaceId("<value>")
.build();
GetAccessTokenResponse res = sdk.auth().getAccessToken()
.request(req)
.call();
if (res.accessToken().isPresent()) {
// handle response
}
}
}
Some of the endpoints in this SDK support retries. If you use the SDK without any configuration, it will fall back to the default retry strategy provided by the API. However, the default retry strategy can be overridden on a per-operation basis, or across the entire SDK.
To change the default retry strategy for a single API call, you can provide a RetryConfig
object through the retryConfig
builder method:
package hello.world;
import dev.speakeasyapi.javaclientsdk.RyanTest;
import dev.speakeasyapi.javaclientsdk.models.operations.GetWorkspaceAccessRequest;
import dev.speakeasyapi.javaclientsdk.models.operations.GetWorkspaceAccessResponse;
import dev.speakeasyapi.javaclientsdk.models.shared.Security;
import dev.speakeasyapi.javaclientsdk.utils.BackoffStrategy;
import dev.speakeasyapi.javaclientsdk.utils.RetryConfig;
import java.lang.Exception;
import java.util.concurrent.TimeUnit;
public class Application {
public static void main(String[] args) throws Exception {
RyanTest sdk = RyanTest.builder()
.security(Security.builder()
.apiKey("<YOUR_API_KEY_HERE>")
.build())
.build();
GetWorkspaceAccessRequest req = GetWorkspaceAccessRequest.builder()
.build();
GetWorkspaceAccessResponse res = sdk.auth().getAccess()
.request(req)
.retryConfig(RetryConfig.builder()
.backoff(BackoffStrategy.builder()
.initialInterval(1L, TimeUnit.MILLISECONDS)
.maxInterval(50L, TimeUnit.MILLISECONDS)
.maxElapsedTime(1000L, TimeUnit.MILLISECONDS)
.baseFactor(1.1)
.jitterFactor(0.15)
.retryConnectError(false)
.build())
.build())
.call();
if (res.accessDetails().isPresent()) {
// handle response
}
}
}
If you'd like to override the default retry strategy for all operations that support retries, you can provide a configuration at SDK initialization:
package hello.world;
import dev.speakeasyapi.javaclientsdk.RyanTest;
import dev.speakeasyapi.javaclientsdk.models.operations.GetWorkspaceAccessRequest;
import dev.speakeasyapi.javaclientsdk.models.operations.GetWorkspaceAccessResponse;
import dev.speakeasyapi.javaclientsdk.models.shared.Security;
import dev.speakeasyapi.javaclientsdk.utils.BackoffStrategy;
import dev.speakeasyapi.javaclientsdk.utils.RetryConfig;
import java.lang.Exception;
import java.util.concurrent.TimeUnit;
public class Application {
public static void main(String[] args) throws Exception {
RyanTest sdk = RyanTest.builder()
.retryConfig(RetryConfig.builder()
.backoff(BackoffStrategy.builder()
.initialInterval(1L, TimeUnit.MILLISECONDS)
.maxInterval(50L, TimeUnit.MILLISECONDS)
.maxElapsedTime(1000L, TimeUnit.MILLISECONDS)
.baseFactor(1.1)
.jitterFactor(0.15)
.retryConnectError(false)
.build())
.build())
.security(Security.builder()
.apiKey("<YOUR_API_KEY_HERE>")
.build())
.build();
GetWorkspaceAccessRequest req = GetWorkspaceAccessRequest.builder()
.build();
GetWorkspaceAccessResponse res = sdk.auth().getAccess()
.request(req)
.call();
if (res.accessDetails().isPresent()) {
// handle response
}
}
}