
Auto-generates API clients from OpenAPI: single-file TypeScript client with Zod runtime validation, plus generated client libraries with configurable HTTP client and serialization support.
This project generates API clients from the OpenAPI specification for both Kotlin Multiplatform and TypeScript/Node.js applications.
hex-specs/
├── openApi/
│ └── hex-tractor-open-api.yml # OpenAPI specification
├── generated/ # Generated code (gitignored)
│ ├── kotlin/ # Generated Kotlin sources
│ └── typescript/ # Generated TypeScript sources
├── dist/ # Compiled TypeScript (gitignored)
├── pom.xml # Maven configuration
├── package.json # npm configuration
├── tsconfig.json # TypeScript configuration
├── PUBLISHING.md # Publishing guide
├── OPENAPI_ZOD_CLIENT.md # Zod client documentation
├── CHANGELOG.md # Version history
└── README.md # This file
This project is published to both npm and Maven Central:
For publishing your own version, see PUBLISHING.md for complete setup instructions.
mvn clean generate-sourcesThis will generate Kotlin client code in the generated/kotlin directory with the following packages:
com.hextractor.api - API interfacescom.hextractor.api.model - Data modelscom.hextractor.api.client - Client infrastructuremvn clean packageThis will compile the generated Kotlin code and create a JAR file in the target directory.
Add the generated library as a dependency in your build.gradle.kts:
dependencies {
implementation(files("path/to/hex-tractor-api-client-1.0.0.jar"))
// Required dependencies
implementation("io.ktor:ktor-client-core:2.3.7")
implementation("io.ktor:ktor-client-content-negotiation:2.3.7")
implementation("io.ktor:ktor-serialization-kotlinx-json:2.3.7")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.2")
}Or publish to your local Maven repository:
mvn clean installThen add as a regular Maven dependency:
dependencies {
implementation("com.hextractor:hex-tractor-api-client:1.0.0")
}import com.hextractor.api.client.ApiClient
import com.hextractor.api.AccountApi
import io.ktor.client.*
import io.ktor.client.engine.cio.*
suspend fun main() {
val client = HttpClient(CIO)
val apiClient = ApiClient(basePath = "http://localhost:3000/api", httpClient = client)
val accountApi = AccountApi(apiClient)
try {
val account = accountApi.accountRegionSummonerNameTagLineGet(
region = "euw1",
summonerName = "PlayerName",
tagLine = "EUW"
)
println("Account: $account")
} finally {
client.close()
}
}The TypeScript client is generated with openapi-zod-client, providing runtime validation of API requests and responses using Zod schemas. This gives you:
See OPENAPI_ZOD_CLIENT.md for detailed documentation.
npm installnpm run generateThis will generate a TypeScript client with Zod schemas in generated/typescript/api.ts.
npm run buildThis will:
dist directorynpm run cleanYou can use the generated client in several ways:
# In the hex-specs directory
npm link
# In your Node.js project
npm link @hextractor/api-clientnpm install path/to/hex-specsnpm publishimport { makeApi } from '@hextractor/api-client';
import Axios from 'axios';
// Create axios instance with base URL
const axios = Axios.create({
baseURL: 'http://localhost:3000/api'
});
// Create type-safe API client
const api = makeApi(axios);
async function getAccountInfo() {
try {
// All requests and responses are validated with Zod schemas
const account = await api.accountRegionSummonerNameTagLineGet({
params: {
region: 'euw1',
summonerName: 'PlayerName',
tagLine: 'EUW'
}
});
console.log('Account:', account);
const matches = await api.matchesRegionPuuidGet({
params: {
region: 'euw1',
puuid: account.generalInfo.puuid,
start: 0,
count: 10
}
});
console.log('Matches:', matches);
} catch (error) {
// Zod validation errors or API errors
console.error('Error:', error);
}
}
getAccountInfo();const { makeApi } = require('@hextractor/api-client');
const Axios = require('axios');
const axios = Axios.create({
baseURL: 'http://localhost:3000/api'
});
const api = makeApi(axios);
api.accountRegionSummonerNameTagLineGet({
params: {
region: 'euw1',
summonerName: 'PlayerName',
tagLine: 'EUW'
}
})
.then(account => {
console.log('Account:', account);
})
.catch(error => {
console.error('Error:', error);
});The Kotlin client is configured in pom.xml. Key settings:
kotlin (multiplatform support)multiplatform (works with JVM, JS, and Native)kotlinx_serialization
com.hextractor.api
com.hextractor.api.model
com.hextractor.api.client
The TypeScript client is configured in package.json. Key features:
openapi-zod-client (runtime validation)generated/typescript/api.ts)See OPENAPI_ZOD_CLIENT.md for detailed documentation on using the Zod-based client.
Edit pom.xml in the openapi-generator-maven-plugin configuration section to change:
Edit the generate script in package.json to change:
-o flag)See the openapi-zod-client documentation for all available options.
Problem: Build fails with serialization errors
# Solution: Ensure kotlinx-serialization plugin is properly configured
mvn clean compileProblem: Multiplatform compatibility issues
# Solution: Check that your target platform is supported by Ktor
# Update library version in pom.xml if neededProblem: Module not found errors
# Solution: Regenerate and rebuild
npm run clean
npm run buildProblem: Type definition errors
# Solution: Check tsconfig.json and ensure all paths are correct
npm install
npm run buildThe generated clients provide access to the following endpoints:
Refer to hex-tractor-open-api.yml for detailed API documentation.
MIT
This project generates API clients from the OpenAPI specification for both Kotlin Multiplatform and TypeScript/Node.js applications.
hex-specs/
├── openApi/
│ └── hex-tractor-open-api.yml # OpenAPI specification
├── generated/ # Generated code (gitignored)
│ ├── kotlin/ # Generated Kotlin sources
│ └── typescript/ # Generated TypeScript sources
├── dist/ # Compiled TypeScript (gitignored)
├── pom.xml # Maven configuration
├── package.json # npm configuration
├── tsconfig.json # TypeScript configuration
├── PUBLISHING.md # Publishing guide
├── OPENAPI_ZOD_CLIENT.md # Zod client documentation
├── CHANGELOG.md # Version history
└── README.md # This file
This project is published to both npm and Maven Central:
For publishing your own version, see PUBLISHING.md for complete setup instructions.
mvn clean generate-sourcesThis will generate Kotlin client code in the generated/kotlin directory with the following packages:
com.hextractor.api - API interfacescom.hextractor.api.model - Data modelscom.hextractor.api.client - Client infrastructuremvn clean packageThis will compile the generated Kotlin code and create a JAR file in the target directory.
Add the generated library as a dependency in your build.gradle.kts:
dependencies {
implementation(files("path/to/hex-tractor-api-client-1.0.0.jar"))
// Required dependencies
implementation("io.ktor:ktor-client-core:2.3.7")
implementation("io.ktor:ktor-client-content-negotiation:2.3.7")
implementation("io.ktor:ktor-serialization-kotlinx-json:2.3.7")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.2")
}Or publish to your local Maven repository:
mvn clean installThen add as a regular Maven dependency:
dependencies {
implementation("com.hextractor:hex-tractor-api-client:1.0.0")
}import com.hextractor.api.client.ApiClient
import com.hextractor.api.AccountApi
import io.ktor.client.*
import io.ktor.client.engine.cio.*
suspend fun main() {
val client = HttpClient(CIO)
val apiClient = ApiClient(basePath = "http://localhost:3000/api", httpClient = client)
val accountApi = AccountApi(apiClient)
try {
val account = accountApi.accountRegionSummonerNameTagLineGet(
region = "euw1",
summonerName = "PlayerName",
tagLine = "EUW"
)
println("Account: $account")
} finally {
client.close()
}
}The TypeScript client is generated with openapi-zod-client, providing runtime validation of API requests and responses using Zod schemas. This gives you:
See OPENAPI_ZOD_CLIENT.md for detailed documentation.
npm installnpm run generateThis will generate a TypeScript client with Zod schemas in generated/typescript/api.ts.
npm run buildThis will:
dist directorynpm run cleanYou can use the generated client in several ways:
# In the hex-specs directory
npm link
# In your Node.js project
npm link @hextractor/api-clientnpm install path/to/hex-specsnpm publishimport { makeApi } from '@hextractor/api-client';
import Axios from 'axios';
// Create axios instance with base URL
const axios = Axios.create({
baseURL: 'http://localhost:3000/api'
});
// Create type-safe API client
const api = makeApi(axios);
async function getAccountInfo() {
try {
// All requests and responses are validated with Zod schemas
const account = await api.accountRegionSummonerNameTagLineGet({
params: {
region: 'euw1',
summonerName: 'PlayerName',
tagLine: 'EUW'
}
});
console.log('Account:', account);
const matches = await api.matchesRegionPuuidGet({
params: {
region: 'euw1',
puuid: account.generalInfo.puuid,
start: 0,
count: 10
}
});
console.log('Matches:', matches);
} catch (error) {
// Zod validation errors or API errors
console.error('Error:', error);
}
}
getAccountInfo();const { makeApi } = require('@hextractor/api-client');
const Axios = require('axios');
const axios = Axios.create({
baseURL: 'http://localhost:3000/api'
});
const api = makeApi(axios);
api.accountRegionSummonerNameTagLineGet({
params: {
region: 'euw1',
summonerName: 'PlayerName',
tagLine: 'EUW'
}
})
.then(account => {
console.log('Account:', account);
})
.catch(error => {
console.error('Error:', error);
});The Kotlin client is configured in pom.xml. Key settings:
kotlin (multiplatform support)multiplatform (works with JVM, JS, and Native)kotlinx_serialization
com.hextractor.api
com.hextractor.api.model
com.hextractor.api.client
The TypeScript client is configured in package.json. Key features:
openapi-zod-client (runtime validation)generated/typescript/api.ts)See OPENAPI_ZOD_CLIENT.md for detailed documentation on using the Zod-based client.
Edit pom.xml in the openapi-generator-maven-plugin configuration section to change:
Edit the generate script in package.json to change:
-o flag)See the openapi-zod-client documentation for all available options.
Problem: Build fails with serialization errors
# Solution: Ensure kotlinx-serialization plugin is properly configured
mvn clean compileProblem: Multiplatform compatibility issues
# Solution: Check that your target platform is supported by Ktor
# Update library version in pom.xml if neededProblem: Module not found errors
# Solution: Regenerate and rebuild
npm run clean
npm run buildProblem: Type definition errors
# Solution: Check tsconfig.json and ensure all paths are correct
npm install
npm run buildThe generated clients provide access to the following endpoints:
Refer to hex-tractor-open-api.yml for detailed API documentation.
MIT