Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,39 @@ jobs:

- name: Javadoc
run: mvn -B javadoc:javadoc

- name: Generator tests
run: mvn -B -f tools/model-generator/pom.xml test

generated-sdk:
# Regenerates the SDK from the committed spec inside the disposable CI checkout and proves the
# result compiles and passes the SDK tests. Generated output is not committed in this phase;
# once a baseline is committed, `make check-generated` replaces this job as the gate.
runs-on: ubuntu-latest

steps:
- name: Harden the runner (Audit all outbound calls)
uses: step-security/harden-runner@002fdce3c6a235733a90a27c80493a3241e56863 # v2.12.1
with:
egress-policy: audit

- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2

- name: Setup Java
uses: actions/setup-java@f2beeb24e141e01a676f977032f5a29d81c9e27e # v5.1.0
with:
distribution: temurin
java-version: "11"
cache: maven

- name: Check generation drift against the vended SDK
# Regenerating from the committed spec may only change the files listed in
# tools/model-generator/config/expected-generation-changes.txt.
run: make check-surface

- name: Generate SDK from committed spec
run: make generate

- name: Test generated SDK
run: mvn -B test
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ dependency-reduced-pom.xml
tmp/

ai-docs/
docs/

# SDK generator download + OpenAPI CLI output
generated/
Expand Down
20 changes: 17 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,24 @@
.PHONY: fetch-spec compile format
.PHONY: fetch-spec compile format generate check-generated check-surface generate-live-diff

fetch-spec:
@mkdir -p apiSpec
@curl -fsSL -o apiSpec/prime-public-spec.yaml https://api.prime.coinbase.com/v1/openapi.yaml
mvn -B -f tools/model-generator/pom.xml compile exec:java@generate-models -Dexec.args="--fetch-spec"

compile:
mvn -B compile

format:
mvn -B spotless:apply

generate:
mvn -B -f tools/model-generator/pom.xml compile exec:java@generate-models
mvn -B spotless:apply

check-generated:
mvn -B -f tools/model-generator/pom.xml compile exec:java@generate-models -Dexec.args="--check"

# Proves generation from the committed spec changes only the files listed in the allowlist.
check-surface:
mvn -B -f tools/model-generator/pom.xml compile exec:java@generate-models -Dexec.args="--check --expect-changes=tools/model-generator/config/expected-generation-changes.txt"

generate-live-diff:
mvn -B -f tools/model-generator/pom.xml compile exec:java@generate-models -Dexec.args="--live-diff"
Original file line number Diff line number Diff line change
Expand Up @@ -29,34 +29,52 @@
import java.util.List;

public class CoinbasePrimeClient extends CoinbaseNetHttpClient {
private final String baseUrl;
private final HttpClient httpClient;

public CoinbasePrimeClient(CoinbasePrimeCredentials credentials, String baseUrl) {
super(credentials, baseUrl);
this.baseUrl = baseUrl;
this.httpClient = null;
}

public CoinbasePrimeClient(
CoinbasePrimeCredentials credentials, String baseUrl, HttpClient client) {
super(credentials, baseUrl, client);
this.baseUrl = baseUrl;
this.httpClient = client;
}

public CoinbasePrimeClient(CoinbasePrimeCredentials credentials) {
super(credentials, Constants.CB_PRIME_BASE_URL);
this.baseUrl = Constants.CB_PRIME_BASE_URL;
this.httpClient = null;
}

public CoinbasePrimeClient(CoinbasePrimeCredentials credentials, HttpClient client) {
super(credentials, Constants.CB_PRIME_BASE_URL, client);
this.baseUrl = Constants.CB_PRIME_BASE_URL;
this.httpClient = client;
}

public String getBaseUrl() {
return baseUrl;
}

/**
* Returns a new client with the given base URL; credentials and behavior are otherwise unchanged.
* Prefer this for single-call version overrides (e.g. {@code v2}) without mutating the shared
* client.
* Returns a new client with the given base URL; credentials and the injected HttpClient are
* reused. Prefer this for single-call version overrides (e.g. {@code v2}) without mutating the
* shared client.
*/
public CoinbasePrimeClient withBaseUrl(String baseUrl) {
CoinbaseCredentials credentials = getCredentials();
if (!(credentials instanceof CoinbasePrimeCredentials)) {
throw new IllegalStateException("Credentials must be CoinbasePrimeCredentials");
}
return new CoinbasePrimeClient((CoinbasePrimeCredentials) credentials, baseUrl);
CoinbasePrimeCredentials primeCredentials = (CoinbasePrimeCredentials) credentials;
return httpClient == null
? new CoinbasePrimeClient(primeCredentials, baseUrl)
: new CoinbasePrimeClient(primeCredentials, baseUrl, httpClient);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Copyright 2026-present Coinbase Global, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.coinbase.prime.client;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertSame;

import com.coinbase.core.client.CoinbaseNetHttpClient;
import com.coinbase.prime.credentials.CoinbasePrimeCredentials;
import java.lang.reflect.Field;
import java.net.http.HttpClient;
import org.junit.jupiter.api.Test;

class CoinbasePrimeClientTest {
private static final CoinbasePrimeCredentials CREDENTIALS =
new CoinbasePrimeCredentials("test-access-key", "test-passphrase", "test-signing-key");

@Test
void withBaseUrlReusesInjectedHttpClient() throws Exception {
HttpClient injected = HttpClient.newHttpClient();
CoinbasePrimeClient client =
new CoinbasePrimeClient(CREDENTIALS, "https://example.test/v1", injected);

CoinbasePrimeClient v2 = client.withBaseUrl("https://example.test/v2");

assertEquals("https://example.test/v2", v2.getBaseUrl());
assertSame(injected, transport(v2));
}

@Test
void withBaseUrlKeepsDefaultTransportWhenNoneInjected() {
CoinbasePrimeClient v2 =
new CoinbasePrimeClient(CREDENTIALS).withBaseUrl("https://example.test/v2");

assertEquals("https://example.test/v2", v2.getBaseUrl());
}

private static HttpClient transport(CoinbasePrimeClient client) throws Exception {
Field field = CoinbaseNetHttpClient.class.getDeclaredField("client");
field.setAccessible(true);
return (HttpClient) field.get(client);
}
}
7 changes: 2 additions & 5 deletions tools/model-generator/.openapi-generator-ignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,9 @@
src/main/java/com/coinbase/prime/model/*Request.java
src/main/java/com/coinbase/prime/model/*Response.java

# Per-operation typed error payloads and codes (not consumed by the SDK yet)
# Per-operation typed error payloads are not consumed by the SDK yet. ErrorCode and
# Subcode enums are intentionally generated and routed to model/errors by PostProcessor.
src/main/java/com/coinbase/prime/model/*ErrorResponse.java
src/main/java/com/coinbase/prime/model/*ErrorCode.java
src/main/java/com/coinbase/prime/model/*Subcode.java
src/main/java/com/coinbase/prime/model/enums/*ErrorCode.java
src/main/java/com/coinbase/prime/model/enums/*Subcode.java

# Google infrastructure types (google.type.Date is generated as GoogleTypeDate and renamed to DateOfBirth)
src/main/java/com/coinbase/prime/model/GoogleProtobufAny.java
Expand Down
86 changes: 86 additions & 0 deletions tools/model-generator/config/expected-generation-changes.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# Every change that regenerating the SDK from the committed spec is allowed to make to the vended
# sources. `make check-surface` fails on any other change, and on any entry here that stops
# applying, so this list can only shrink as the generated baseline is adopted.
#
# Anything not listed must regenerate byte-for-byte: existing request/response/service classes keep
# their vended shape, member order and documentation.

# New canonical classes for operations whose Java names were aligned across SDKs (see
# operations-overrides.json). The legacy names below remain as @Deprecated subclasses.
ADD com/coinbase/prime/activities/ListActivitiesRequest.java
ADD com/coinbase/prime/activities/ListActivitiesResponse.java
ADD com/coinbase/prime/addressbook/GetAddressBookRequest.java
ADD com/coinbase/prime/addressbook/GetAddressBookResponse.java
ADD com/coinbase/prime/allocations/GetAllocationsByClientNettingIdRequest.java
ADD com/coinbase/prime/allocations/GetAllocationsByClientNettingIdResponse.java
ADD com/coinbase/prime/orders/GetOrderRequest.java
ADD com/coinbase/prime/orders/GetOrderResponse.java
ADD com/coinbase/prime/paymentmethods/GetEntityPaymentMethodRequest.java
ADD com/coinbase/prime/paymentmethods/GetEntityPaymentMethodResponse.java
ADD com/coinbase/prime/paymentmethods/ListEntityPaymentMethodsRequest.java
ADD com/coinbase/prime/paymentmethods/ListEntityPaymentMethodsResponse.java
ADD com/coinbase/prime/staking/ClaimStakingRewardsRequest.java
ADD com/coinbase/prime/staking/ClaimStakingRewardsResponse.java
ADD com/coinbase/prime/staking/CreatePortfolioStakeRequest.java
ADD com/coinbase/prime/staking/CreatePortfolioStakeResponse.java
ADD com/coinbase/prime/staking/CreatePortfolioUnstakeRequest.java
ADD com/coinbase/prime/staking/CreatePortfolioUnstakeResponse.java
ADD com/coinbase/prime/transactions/CreateTransferRequest.java
ADD com/coinbase/prime/transactions/CreateTransferResponse.java
ADD com/coinbase/prime/transactions/CreateWithdrawalRequest.java
ADD com/coinbase/prime/transactions/CreateWithdrawalResponse.java

# Legacy request/response classes rewritten as @Deprecated aliases of the canonical classes.
CHANGE com/coinbase/prime/activities/ListPortfolioActivitiesRequest.java
CHANGE com/coinbase/prime/activities/ListPortfolioActivitiesResponse.java
CHANGE com/coinbase/prime/addressbook/ListAddressBookRequest.java
CHANGE com/coinbase/prime/addressbook/ListAddressBookResponse.java
CHANGE com/coinbase/prime/allocations/ListAllocationsByNettingIdRequest.java
CHANGE com/coinbase/prime/allocations/ListAllocationsByNettingIdResponse.java
CHANGE com/coinbase/prime/orders/GetOrderByOrderIdRequest.java
CHANGE com/coinbase/prime/orders/GetOrderByOrderIdResponse.java
CHANGE com/coinbase/prime/paymentmethods/GetPaymentMethodDetailsRequest.java
CHANGE com/coinbase/prime/paymentmethods/GetPaymentMethodDetailsResponse.java
CHANGE com/coinbase/prime/paymentmethods/ListPaymentMethodsRequest.java
CHANGE com/coinbase/prime/paymentmethods/ListPaymentMethodsResponse.java
CHANGE com/coinbase/prime/staking/ClaimRewardsRequest.java
CHANGE com/coinbase/prime/staking/ClaimRewardsResponse.java
CHANGE com/coinbase/prime/staking/PortfolioStakingInitiateRequest.java
CHANGE com/coinbase/prime/staking/PortfolioStakingInitiateResponse.java
CHANGE com/coinbase/prime/staking/PortfolioStakingUnstakeRequest.java
CHANGE com/coinbase/prime/staking/PortfolioStakingUnstakeResponse.java
CHANGE com/coinbase/prime/transactions/CreateWalletTransferRequest.java
CHANGE com/coinbase/prime/transactions/CreateWalletTransferResponse.java
CHANGE com/coinbase/prime/transactions/CreateWalletWithdrawalRequest.java
CHANGE com/coinbase/prime/transactions/CreateWalletWithdrawalResponse.java

# Service interfaces/implementations that gain the canonical methods plus @Deprecated forwarding
# aliases for the legacy method names.
CHANGE com/coinbase/prime/activities/ActivitiesService.java
CHANGE com/coinbase/prime/activities/ActivitiesServiceImpl.java
CHANGE com/coinbase/prime/addressbook/AddressBookService.java
CHANGE com/coinbase/prime/addressbook/AddressBookServiceImpl.java
CHANGE com/coinbase/prime/allocations/AllocationsService.java
CHANGE com/coinbase/prime/allocations/AllocationsServiceImpl.java
CHANGE com/coinbase/prime/orders/OrdersService.java
CHANGE com/coinbase/prime/orders/OrdersServiceImpl.java
CHANGE com/coinbase/prime/paymentmethods/PaymentMethodsService.java
CHANGE com/coinbase/prime/paymentmethods/PaymentMethodsServiceImpl.java
CHANGE com/coinbase/prime/staking/StakingService.java
CHANGE com/coinbase/prime/staking/StakingServiceImpl.java
CHANGE com/coinbase/prime/transactions/TransactionsService.java
CHANGE com/coinbase/prime/transactions/TransactionsServiceImpl.java

# Fields the committed spec has that the vended classes lack (real spec updates).
CHANGE com/coinbase/prime/orders/CreateQuoteRequest.java
CHANGE com/coinbase/prime/orders/CreateQuoteResponse.java
CHANGE com/coinbase/prime/orders/EditOrderRequest.java

# /v2 endpoints now derive their base URL from the configured client instead of the production
# constant, so a custom base URL is honored.
CHANGE com/coinbase/prime/financing/FinancingServiceImpl.java

# Hand-maintained compatibility files (protectedCompatibilityFiles). The generator only proposes
# changes for them and never writes them.
SKIP com/coinbase/prime/portfolios/PortfoliosService.java
SKIP com/coinbase/prime/portfolios/PortfoliosServiceImpl.java
26 changes: 26 additions & 0 deletions tools/model-generator/config/generator-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"specUrl": "https://api.prime.coinbase.com/v1/openapi.yaml",
"committedSpecPath": "apiSpec/prime-public-spec.yaml",
"tagToFolderOverrides": {
"Travel Rule": "transactions"
},
"modelTypeMappings": {
"CreateOnchainTransactionRequestEVMParams": "EvmParams",
"CreateOnchainTransactionRequestEvmParams": "EvmParams",
"FcmFuturesSweepRequestAmount": "SweepAmount",
"FcmFuturesSweep": "FuturesSweep",
"EvmParam": "EvmParams",
"RPC": "RpcConfig",
"XMControlStatus": "PrimeXMControlStatus",
"XMMarginLevel": "PrimeXMMarginLevel"
},
"sharedModelMappings": {
"PaginatedResponse": "com.coinbase.prime.common.Pagination"
},
"protectedCompatibilityFiles": [
"com/coinbase/prime/portfolios/GetPortfolioCounterpartyIdRequest.java",
"com/coinbase/prime/portfolios/GetPortfolioCounterpartyIdResponse.java",
"com/coinbase/prime/portfolios/PortfoliosService.java",
"com/coinbase/prime/portfolios/PortfoliosServiceImpl.java"
]
}
Loading
Loading