Skip to content

Commit 65bb673

Browse files
committed
Initial SDK setup
- Auto-generated Java SDK from OpenAPI specification - GitHub Actions workflow for auto-publishing to Maven Central - Version tracking via OPENAPI_VERSION file - Maven POM configured for Central Portal publishing - Ready for automated releases when API is tagged
0 parents  commit 65bb673

5 files changed

Lines changed: 495 additions & 0 deletions

File tree

Lines changed: 190 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,190 @@
1+
name: Update and Publish SDK
2+
3+
on:
4+
repository_dispatch:
5+
types: [update-sdk]
6+
workflow_dispatch: # Allow manual trigger
7+
8+
jobs:
9+
update-and-publish:
10+
runs-on: ubuntu-latest
11+
permissions:
12+
contents: write
13+
packages: write
14+
15+
steps:
16+
- name: Checkout repository
17+
uses: actions/checkout@v4
18+
with:
19+
token: ${{ secrets.GITHUB_TOKEN }}
20+
21+
- name: Setup Java
22+
uses: actions/setup-java@v4
23+
with:
24+
java-version: '11'
25+
distribution: 'temurin'
26+
cache: 'maven'
27+
28+
- name: Install OpenAPI Generator
29+
run: |
30+
npm install -g @openapitools/openapi-generator-cli
31+
32+
- name: Fetch current version from swagger
33+
id: fetch-version
34+
run: |
35+
SWAGGER_URL="https://api.linkbreakers.com/internal/openapi/api/v1/api.swagger.json"
36+
NEW_VERSION=$(curl -s "$SWAGGER_URL" | jq -r '.info.version')
37+
echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
38+
echo "Swagger version: $NEW_VERSION"
39+
40+
- name: Read current OPENAPI_VERSION
41+
id: current-version
42+
run: |
43+
if [ -f OPENAPI_VERSION ]; then
44+
CURRENT_VERSION=$(cat OPENAPI_VERSION)
45+
else
46+
CURRENT_VERSION="0.0.0"
47+
fi
48+
echo "current_version=$CURRENT_VERSION" >> $GITHUB_OUTPUT
49+
echo "Current version: $CURRENT_VERSION"
50+
51+
- name: Compare versions
52+
id: compare
53+
run: |
54+
if [ "${{ steps.fetch-version.outputs.new_version }}" == "${{ steps.current-version.outputs.current_version }}" ]; then
55+
echo "needs_update=false" >> $GITHUB_OUTPUT
56+
echo "✅ Versions match. No update needed."
57+
else
58+
echo "needs_update=true" >> $GITHUB_OUTPUT
59+
echo "🔄 Version changed: ${{ steps.current-version.outputs.current_version }} → ${{ steps.fetch-version.outputs.new_version }}"
60+
fi
61+
62+
- name: Download and convert OpenAPI spec to 3.1
63+
if: steps.compare.outputs.needs_update == 'true'
64+
run: |
65+
# Download OpenAPI 3.2.0 spec
66+
curl -o openapi-3.2.json https://api.linkbreakers.com/internal/openapi/api/v1/api.swagger.json
67+
68+
# Convert OpenAPI 3.2 to 3.1 (remove 3.2-specific fields)
69+
jq '.openapi = "3.1.0" | del(.jsonSchemaDialect)' openapi-3.2.json > openapi-3.1.json
70+
71+
echo "✅ OpenAPI spec converted from 3.2 to 3.1"
72+
73+
- name: Generate SDK using OpenAPI Generator
74+
if: steps.compare.outputs.needs_update == 'true'
75+
run: |
76+
NEW_VERSION="${{ steps.fetch-version.outputs.new_version }}"
77+
78+
# Backup custom files that we want to preserve
79+
mkdir -p .backup
80+
cp pom.xml .backup/ 2>/dev/null || true
81+
cp README.md .backup/ 2>/dev/null || true
82+
83+
# Remove old generated code
84+
rm -rf src/main/java/com/linkbreakers 2>/dev/null || true
85+
86+
# Generate SDK using OpenAPI Generator with java generator
87+
openapi-generator-cli generate \
88+
-i openapi-3.1.json \
89+
-g java \
90+
-o . \
91+
--skip-validate-spec \
92+
--global-property apiTests=false,modelTests=false,apiDocs=false,modelDocs=false \
93+
--additional-properties=groupId=com.linkbreakers,artifactId=linkbreakers-sdk,artifactVersion=$NEW_VERSION,library=okhttp-gson,dateLibrary=java8,hideGenerationTimestamp=true
94+
95+
# Restore custom pom.xml (contains publishing config)
96+
cp .backup/pom.xml . 2>/dev/null || true
97+
cp .backup/README.md . 2>/dev/null || true
98+
99+
# Update version in pom.xml
100+
sed -i "s|<version>.*</version>|<version>$NEW_VERSION</version>|" pom.xml | head -1
101+
102+
# Clean up
103+
rm -rf .backup
104+
rm openapi-3.2.json openapi-3.1.json
105+
106+
echo "✅ SDK generated successfully with version $NEW_VERSION"
107+
108+
- name: Update version files
109+
if: steps.compare.outputs.needs_update == 'true'
110+
run: |
111+
NEW_VERSION="${{ steps.fetch-version.outputs.new_version }}"
112+
113+
# Update OPENAPI_VERSION file
114+
echo "$NEW_VERSION" > OPENAPI_VERSION
115+
116+
echo "✅ Version files updated to $NEW_VERSION"
117+
118+
- name: Build with Maven
119+
if: steps.compare.outputs.needs_update == 'true'
120+
run: |
121+
mvn clean package -DskipTests
122+
echo "✅ Maven build completed"
123+
124+
- name: Import GPG key
125+
if: steps.compare.outputs.needs_update == 'true'
126+
env:
127+
GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }}
128+
GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
129+
run: |
130+
echo "$GPG_PRIVATE_KEY" | base64 -d | gpg --batch --import
131+
echo "✅ GPG key imported"
132+
133+
- name: Configure Maven settings
134+
if: steps.compare.outputs.needs_update == 'true'
135+
run: |
136+
mkdir -p ~/.m2
137+
cat > ~/.m2/settings.xml <<EOF
138+
<settings>
139+
<servers>
140+
<server>
141+
<id>ossrh</id>
142+
<username>${{ secrets.OSSRH_USERNAME }}</username>
143+
<password>${{ secrets.OSSRH_TOKEN }}</password>
144+
</server>
145+
</servers>
146+
</settings>
147+
EOF
148+
echo "✅ Maven settings configured"
149+
150+
- name: Configure Git
151+
if: steps.compare.outputs.needs_update == 'true'
152+
run: |
153+
git config user.name "github-actions[bot]"
154+
git config user.email "github-actions[bot]@users.noreply.github.com"
155+
156+
- name: Commit changes
157+
if: steps.compare.outputs.needs_update == 'true'
158+
run: |
159+
NEW_VERSION="${{ steps.fetch-version.outputs.new_version }}"
160+
161+
git add .
162+
git commit -m "chore: update SDK to API version $NEW_VERSION"
163+
164+
echo "✅ Changes committed"
165+
166+
- name: Create and push tag
167+
if: steps.compare.outputs.needs_update == 'true'
168+
run: |
169+
NEW_VERSION="${{ steps.fetch-version.outputs.new_version }}"
170+
171+
git tag "v$NEW_VERSION"
172+
git push origin main
173+
git push origin "v$NEW_VERSION"
174+
175+
echo "✅ Tag v$NEW_VERSION created and pushed"
176+
177+
- name: Deploy to Maven Central
178+
if: steps.compare.outputs.needs_update == 'true'
179+
env:
180+
GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
181+
run: |
182+
mvn clean deploy -DskipTests -Dgpg.passphrase=$GPG_PASSPHRASE
183+
echo "✅ Published to Maven Central"
184+
185+
- name: Summary
186+
if: steps.compare.outputs.needs_update == 'true'
187+
run: |
188+
echo "🎉 SDK successfully updated and published!"
189+
echo "Version: ${{ steps.fetch-version.outputs.new_version }}"
190+
echo "Maven Central: https://central.sonatype.com/artifact/com.linkbreakers/linkbreakers-sdk"

‎.gitignore‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Compiled class files
2+
*.class
3+
4+
# Log files
5+
*.log
6+
7+
# Maven
8+
target/
9+
pom.xml.tag
10+
pom.xml.releaseBackup
11+
pom.xml.versionsBackup
12+
pom.xml.next
13+
release.properties
14+
dependency-reduced-pom.xml
15+
buildNumber.properties
16+
.mvn/timing.properties
17+
.mvn/wrapper/maven-wrapper.jar
18+
19+
# Gradle
20+
.gradle
21+
build/
22+
!gradle/wrapper/gradle-wrapper.jar
23+
!**/src/main/**/build/
24+
!**/src/test/**/build/
25+
26+
# IDE
27+
.idea/
28+
*.iws
29+
*.iml
30+
*.ipr
31+
.vscode/
32+
*.swp
33+
*.swo
34+
*~
35+
36+
# OS
37+
.DS_Store
38+
Thumbs.db

‎OPENAPI_VERSION‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0.0.0

‎README.md‎

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
# Linkbreakers Java SDK
2+
3+
Official Java SDK for the Linkbreakers API, auto-generated from OpenAPI specification.
4+
5+
## Installation
6+
7+
### Maven
8+
9+
Add this dependency to your `pom.xml`:
10+
11+
```xml
12+
<dependency>
13+
<groupId>com.linkbreakers</groupId>
14+
<artifactId>linkbreakers-sdk</artifactId>
15+
<version>1.32.0</version>
16+
</dependency>
17+
```
18+
19+
### Gradle
20+
21+
Add this to your `build.gradle`:
22+
23+
```gradle
24+
implementation 'com.linkbreakers:linkbreakers-sdk:1.32.0'
25+
```
26+
27+
## Requirements
28+
29+
- Java 11 or higher
30+
31+
## Usage
32+
33+
```java
34+
import com.linkbreakers.*;
35+
import com.linkbreakers.api.*;
36+
import com.linkbreakers.model.*;
37+
38+
public class Example {
39+
public static void main(String[] args) {
40+
// Create API client
41+
ApiClient defaultClient = Configuration.getDefaultApiClient();
42+
defaultClient.setBasePath("https://api.linkbreakers.com");
43+
44+
// Configure Bearer token authentication
45+
HttpBearerAuth bearerAuth = (HttpBearerAuth) defaultClient.getAuthentication("bearerAuth");
46+
bearerAuth.setBearerToken("your-api-token");
47+
48+
// Create API instance
49+
LinksApi apiInstance = new LinksApi(defaultClient);
50+
51+
try {
52+
// Example: List links
53+
Integer pageSize = 10;
54+
LinksList200Response result = apiInstance.linksList(pageSize, null, null, null, null, null, null, null, null);
55+
System.out.println("Found " + result.getLinks().size() + " links");
56+
} catch (ApiException e) {
57+
System.err.println("Exception when calling LinksApi#linksList");
58+
System.err.println("Status code: " + e.getCode());
59+
System.err.println("Reason: " + e.getResponseBody());
60+
System.err.println("Response headers: " + e.getResponseHeaders());
61+
e.printStackTrace();
62+
}
63+
}
64+
}
65+
```
66+
67+
## Authentication
68+
69+
The SDK supports Bearer token authentication:
70+
71+
```java
72+
ApiClient defaultClient = Configuration.getDefaultApiClient();
73+
HttpBearerAuth bearerAuth = (HttpBearerAuth) defaultClient.getAuthentication("bearerAuth");
74+
bearerAuth.setBearerToken("your-api-token");
75+
```
76+
77+
## API Documentation
78+
79+
For detailed API documentation, visit: https://docs.linkbreakers.com
80+
81+
## Auto-Generated
82+
83+
This SDK is automatically generated from the Linkbreakers OpenAPI specification and published when the API is updated.
84+
85+
Current API version: See [OPENAPI_VERSION](./OPENAPI_VERSION)
86+
87+
## Issues
88+
89+
Report issues at: https://github.com/linkbreakers-com/linkbreakers-java/issues
90+
91+
## License
92+
93+
MIT License

0 commit comments

Comments
 (0)