@rotesblatt/hex-tractor-data-api 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +349 -0
- package/dist/generated/typescript/api.d.ts +2306 -0
- package/dist/generated/typescript/api.d.ts.map +1 -0
- package/dist/generated/typescript/api.js +862 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +18 -0
- package/generated/typescript/api.ts +1368 -0
- package/package.json +42 -0
package/README.md
ADDED
|
@@ -0,0 +1,349 @@
|
|
|
1
|
+
# Hex-Tractor API Client Generation
|
|
2
|
+
|
|
3
|
+
This project generates API clients from the OpenAPI specification for both Kotlin Multiplatform and TypeScript/Node.js applications.
|
|
4
|
+
|
|
5
|
+
## Prerequisites
|
|
6
|
+
|
|
7
|
+
### For Kotlin Generation
|
|
8
|
+
- Java 11 or higher
|
|
9
|
+
- Maven 3.6 or higher
|
|
10
|
+
|
|
11
|
+
### For TypeScript Generation
|
|
12
|
+
- Node.js 18 or higher
|
|
13
|
+
- npm 9 or higher
|
|
14
|
+
|
|
15
|
+
## Project Structure
|
|
16
|
+
|
|
17
|
+
```
|
|
18
|
+
hex-specs/
|
|
19
|
+
├── openApi/
|
|
20
|
+
│ └── hex-tractor-open-api.yml # OpenAPI specification
|
|
21
|
+
├── generated/ # Generated code (gitignored)
|
|
22
|
+
│ ├── kotlin/ # Generated Kotlin sources
|
|
23
|
+
│ └── typescript/ # Generated TypeScript sources
|
|
24
|
+
├── dist/ # Compiled TypeScript (gitignored)
|
|
25
|
+
├── pom.xml # Maven configuration
|
|
26
|
+
├── package.json # npm configuration
|
|
27
|
+
├── tsconfig.json # TypeScript configuration
|
|
28
|
+
├── PUBLISHING.md # Publishing guide
|
|
29
|
+
├── OPENAPI_ZOD_CLIENT.md # Zod client documentation
|
|
30
|
+
├── CHANGELOG.md # Version history
|
|
31
|
+
└── README.md # This file
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## 📦 Published Packages
|
|
35
|
+
|
|
36
|
+
This project is published to both npm and Maven Central:
|
|
37
|
+
|
|
38
|
+
- **npm**: [@hextractor/api-client](https://www.npmjs.com/package/@hextractor/api-client)
|
|
39
|
+
- **Maven Central**: [com.hextractor:hex-tractor-api-client](https://central.sonatype.com/artifact/com.hextractor/hex-tractor-api-client)
|
|
40
|
+
|
|
41
|
+
For publishing your own version, see [PUBLISHING.md](PUBLISHING.md) for complete setup instructions.
|
|
42
|
+
|
|
43
|
+
## Kotlin Multiplatform Client
|
|
44
|
+
|
|
45
|
+
### Generate Kotlin Code
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
mvn clean generate-sources
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
This will generate Kotlin client code in the `generated/kotlin` directory with the following packages:
|
|
52
|
+
- `com.hextractor.api` - API interfaces
|
|
53
|
+
- `com.hextractor.api.model` - Data models
|
|
54
|
+
- `com.hextractor.api.client` - Client infrastructure
|
|
55
|
+
|
|
56
|
+
### Build the Kotlin Library
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
mvn clean package
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
This will compile the generated Kotlin code and create a JAR file in the `target` directory.
|
|
63
|
+
|
|
64
|
+
### Using in Your Kotlin Multiplatform Project
|
|
65
|
+
|
|
66
|
+
Add the generated library as a dependency in your `build.gradle.kts`:
|
|
67
|
+
|
|
68
|
+
```kotlin
|
|
69
|
+
dependencies {
|
|
70
|
+
implementation(files("path/to/hex-tractor-api-client-1.0.0.jar"))
|
|
71
|
+
|
|
72
|
+
// Required dependencies
|
|
73
|
+
implementation("io.ktor:ktor-client-core:2.3.7")
|
|
74
|
+
implementation("io.ktor:ktor-client-content-negotiation:2.3.7")
|
|
75
|
+
implementation("io.ktor:ktor-serialization-kotlinx-json:2.3.7")
|
|
76
|
+
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.2")
|
|
77
|
+
}
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
Or publish to your local Maven repository:
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
mvn clean install
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
Then add as a regular Maven dependency:
|
|
87
|
+
|
|
88
|
+
```kotlin
|
|
89
|
+
dependencies {
|
|
90
|
+
implementation("com.hextractor:hex-tractor-api-client:1.0.0")
|
|
91
|
+
}
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### Example Kotlin Usage
|
|
95
|
+
|
|
96
|
+
```kotlin
|
|
97
|
+
import com.hextractor.api.client.ApiClient
|
|
98
|
+
import com.hextractor.api.AccountApi
|
|
99
|
+
import io.ktor.client.*
|
|
100
|
+
import io.ktor.client.engine.cio.*
|
|
101
|
+
|
|
102
|
+
suspend fun main() {
|
|
103
|
+
val client = HttpClient(CIO)
|
|
104
|
+
val apiClient = ApiClient(basePath = "http://localhost:3000/api", httpClient = client)
|
|
105
|
+
val accountApi = AccountApi(apiClient)
|
|
106
|
+
|
|
107
|
+
try {
|
|
108
|
+
val account = accountApi.accountRegionSummonerNameTagLineGet(
|
|
109
|
+
region = "euw1",
|
|
110
|
+
summonerName = "PlayerName",
|
|
111
|
+
tagLine = "EUW"
|
|
112
|
+
)
|
|
113
|
+
println("Account: $account")
|
|
114
|
+
} finally {
|
|
115
|
+
client.close()
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
## TypeScript/Node.js Client
|
|
121
|
+
|
|
122
|
+
The TypeScript client is generated with [openapi-zod-client](https://github.com/astahmer/openapi-zod-client), providing **runtime validation** of API requests and responses using Zod schemas. This gives you:
|
|
123
|
+
|
|
124
|
+
- ✅ Runtime type safety with Zod validation
|
|
125
|
+
- ✅ Compile-time type safety with TypeScript
|
|
126
|
+
- ✅ Smaller bundle size (single file output)
|
|
127
|
+
- ✅ Better developer experience with automatic schema validation
|
|
128
|
+
|
|
129
|
+
See [OPENAPI_ZOD_CLIENT.md](OPENAPI_ZOD_CLIENT.md) for detailed documentation.
|
|
130
|
+
|
|
131
|
+
### Install Dependencies
|
|
132
|
+
|
|
133
|
+
```bash
|
|
134
|
+
npm install
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
### Generate TypeScript Code
|
|
138
|
+
|
|
139
|
+
```bash
|
|
140
|
+
npm run generate
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
This will generate a TypeScript client with Zod schemas in `generated/typescript/api.ts`.
|
|
144
|
+
|
|
145
|
+
### Build the TypeScript Library
|
|
146
|
+
|
|
147
|
+
```bash
|
|
148
|
+
npm run build
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
This will:
|
|
152
|
+
1. Generate the TypeScript client with Zod schemas from the OpenAPI spec
|
|
153
|
+
2. Compile the TypeScript to JavaScript
|
|
154
|
+
3. Create type definitions
|
|
155
|
+
4. Output everything to the `dist` directory
|
|
156
|
+
|
|
157
|
+
### Clean Generated Files
|
|
158
|
+
|
|
159
|
+
```bash
|
|
160
|
+
npm run clean
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
### Using in Your Node.js/TypeScript Project
|
|
164
|
+
|
|
165
|
+
You can use the generated client in several ways:
|
|
166
|
+
|
|
167
|
+
#### Option 1: Link Locally During Development
|
|
168
|
+
|
|
169
|
+
```bash
|
|
170
|
+
# In the hex-specs directory
|
|
171
|
+
npm link
|
|
172
|
+
|
|
173
|
+
# In your Node.js project
|
|
174
|
+
npm link @hextractor/api-client
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
#### Option 2: Install from File
|
|
178
|
+
|
|
179
|
+
```bash
|
|
180
|
+
npm install path/to/hex-specs
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
#### Option 3: Publish to npm Registry
|
|
184
|
+
|
|
185
|
+
```bash
|
|
186
|
+
npm publish
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
### Example TypeScript Usage
|
|
190
|
+
|
|
191
|
+
```typescript
|
|
192
|
+
import { makeApi } from '@hextractor/api-client';
|
|
193
|
+
import Axios from 'axios';
|
|
194
|
+
|
|
195
|
+
// Create axios instance with base URL
|
|
196
|
+
const axios = Axios.create({
|
|
197
|
+
baseURL: 'http://localhost:3000/api'
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
// Create type-safe API client
|
|
201
|
+
const api = makeApi(axios);
|
|
202
|
+
|
|
203
|
+
async function getAccountInfo() {
|
|
204
|
+
try {
|
|
205
|
+
// All requests and responses are validated with Zod schemas
|
|
206
|
+
const account = await api.accountRegionSummonerNameTagLineGet({
|
|
207
|
+
params: {
|
|
208
|
+
region: 'euw1',
|
|
209
|
+
summonerName: 'PlayerName',
|
|
210
|
+
tagLine: 'EUW'
|
|
211
|
+
}
|
|
212
|
+
});
|
|
213
|
+
console.log('Account:', account);
|
|
214
|
+
|
|
215
|
+
const matches = await api.matchesRegionPuuidGet({
|
|
216
|
+
params: {
|
|
217
|
+
region: 'euw1',
|
|
218
|
+
puuid: account.generalInfo.puuid,
|
|
219
|
+
start: 0,
|
|
220
|
+
count: 10
|
|
221
|
+
}
|
|
222
|
+
});
|
|
223
|
+
console.log('Matches:', matches);
|
|
224
|
+
} catch (error) {
|
|
225
|
+
// Zod validation errors or API errors
|
|
226
|
+
console.error('Error:', error);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
getAccountInfo();
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
### Example JavaScript Usage (CommonJS)
|
|
234
|
+
|
|
235
|
+
```javascript
|
|
236
|
+
const { makeApi } = require('@hextractor/api-client');
|
|
237
|
+
const Axios = require('axios');
|
|
238
|
+
|
|
239
|
+
const axios = Axios.create({
|
|
240
|
+
baseURL: 'http://localhost:3000/api'
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
const api = makeApi(axios);
|
|
244
|
+
|
|
245
|
+
api.accountRegionSummonerNameTagLineGet({
|
|
246
|
+
params: {
|
|
247
|
+
region: 'euw1',
|
|
248
|
+
summonerName: 'PlayerName',
|
|
249
|
+
tagLine: 'EUW'
|
|
250
|
+
}
|
|
251
|
+
})
|
|
252
|
+
.then(account => {
|
|
253
|
+
console.log('Account:', account);
|
|
254
|
+
})
|
|
255
|
+
.catch(error => {
|
|
256
|
+
console.error('Error:', error);
|
|
257
|
+
});
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
## Configuration
|
|
261
|
+
|
|
262
|
+
### Kotlin Configuration
|
|
263
|
+
|
|
264
|
+
The Kotlin client is configured in [pom.xml](pom.xml). Key settings:
|
|
265
|
+
|
|
266
|
+
- **Generator**: `kotlin` (multiplatform support)
|
|
267
|
+
- **Library**: `multiplatform` (works with JVM, JS, and Native)
|
|
268
|
+
- **Serialization**: `kotlinx_serialization`
|
|
269
|
+
- **HTTP Client**: Ktor
|
|
270
|
+
- **Packages**:
|
|
271
|
+
- API: `com.hextractor.api`
|
|
272
|
+
- Models: `com.hextractor.api.model`
|
|
273
|
+
- Invoker: `com.hextractor.api.client`
|
|
274
|
+
|
|
275
|
+
### TypeScript Configuration
|
|
276
|
+
|
|
277
|
+
The TypeScript client is configured in [package.json](package.json). Key features:
|
|
278
|
+
|
|
279
|
+
- **Generator**: `openapi-zod-client` (runtime validation)
|
|
280
|
+
- **Validation**: Zod schemas for runtime type checking
|
|
281
|
+
- **HTTP Client**: Axios (you provide your own instance)
|
|
282
|
+
- **Output**: Single file (`generated/typescript/api.ts`)
|
|
283
|
+
- **TypeScript**: Strict mode with ES2020 target
|
|
284
|
+
|
|
285
|
+
See [OPENAPI_ZOD_CLIENT.md](OPENAPI_ZOD_CLIENT.md) for detailed documentation on using the Zod-based client.
|
|
286
|
+
|
|
287
|
+
## Customization
|
|
288
|
+
|
|
289
|
+
### Modify Kotlin Generation
|
|
290
|
+
|
|
291
|
+
Edit [pom.xml](pom.xml) in the `openapi-generator-maven-plugin` configuration section to change:
|
|
292
|
+
- Package names
|
|
293
|
+
- Output directory
|
|
294
|
+
- Generator options
|
|
295
|
+
- Dependencies
|
|
296
|
+
|
|
297
|
+
### Modify TypeScript Generation
|
|
298
|
+
|
|
299
|
+
Edit the `generate` script in [package.json](package.json) to change:
|
|
300
|
+
- Output file location (`-o` flag)
|
|
301
|
+
- Additional openapi-zod-client options
|
|
302
|
+
|
|
303
|
+
See the [openapi-zod-client documentation](https://github.com/astahmer/openapi-zod-client) for all available options.
|
|
304
|
+
|
|
305
|
+
## Troubleshooting
|
|
306
|
+
|
|
307
|
+
### Kotlin Issues
|
|
308
|
+
|
|
309
|
+
**Problem**: Build fails with serialization errors
|
|
310
|
+
```bash
|
|
311
|
+
# Solution: Ensure kotlinx-serialization plugin is properly configured
|
|
312
|
+
mvn clean compile
|
|
313
|
+
```
|
|
314
|
+
|
|
315
|
+
**Problem**: Multiplatform compatibility issues
|
|
316
|
+
```bash
|
|
317
|
+
# Solution: Check that your target platform is supported by Ktor
|
|
318
|
+
# Update library version in pom.xml if needed
|
|
319
|
+
```
|
|
320
|
+
|
|
321
|
+
### TypeScript Issues
|
|
322
|
+
|
|
323
|
+
**Problem**: Module not found errors
|
|
324
|
+
```bash
|
|
325
|
+
# Solution: Regenerate and rebuild
|
|
326
|
+
npm run clean
|
|
327
|
+
npm run build
|
|
328
|
+
```
|
|
329
|
+
|
|
330
|
+
**Problem**: Type definition errors
|
|
331
|
+
```bash
|
|
332
|
+
# Solution: Check tsconfig.json and ensure all paths are correct
|
|
333
|
+
npm install
|
|
334
|
+
npm run build
|
|
335
|
+
```
|
|
336
|
+
|
|
337
|
+
## API Endpoints
|
|
338
|
+
|
|
339
|
+
The generated clients provide access to the following endpoints:
|
|
340
|
+
|
|
341
|
+
- **Account API**: Get Riot account information by summoner name/tag or PUUID
|
|
342
|
+
- **Leagues API**: Get league entries by queue, tier, and division
|
|
343
|
+
- **Matches API**: Get match details and match IDs by PUUID or match ID
|
|
344
|
+
|
|
345
|
+
Refer to [hex-tractor-open-api.yml](openApi/hex-tractor-open-api.yml) for detailed API documentation.
|
|
346
|
+
|
|
347
|
+
## License
|
|
348
|
+
|
|
349
|
+
MIT
|