feat: add client generation - #10
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds code generation for Ktor HTTP client classes from an OpenAPI spec. It introduces three generators: ClientGenerator (per-tag API client classes), ApiClientBaseGenerator (shared abstract base class with HTTP utilities), and ApiResponseGenerator (response type wrappers).
Changes:
ClientGeneratorgenerates one client class per API tag, with suspend functions for each endpoint, path/query/header parameter handling, and polymorphic serialization supportApiClientBaseGeneratorgenerates a shared abstractApiClientBaseclass with auth, error handling (safeCall), and HTTP client creation utilitiesApiResponseGeneratorgeneratesHttpError,HttpErrorType, andHttpSuccess<T>response wrapper types
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
core/src/main/kotlin/.../ClientGenerator.kt |
Generates per-tag Ktor client classes with endpoint functions |
core/src/main/kotlin/.../ApiClientBaseGenerator.kt |
Generates abstract base class with shared HTTP client utilities |
core/src/main/kotlin/.../ApiResponseGenerator.kt |
Generates response type data classes and enum |
core/src/test/kotlin/.../ClientGeneratorTest.kt |
Tests for client generation covering methods, params, return types |
core/src/test/kotlin/.../ApiClientBaseGeneratorTest.kt |
Tests for base class structure, utilities, and extensions |
core/src/test/kotlin/.../ApiResponseGeneratorTest.kt |
Tests for response type generation |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
262772b to
8a233a4
Compare
mzielu
left a comment
There was a problem hiding this comment.
small comments, please let's focus on model-generation PR to be closed before the next round of review
There was a problem hiding this comment.
Pull request overview
This PR introduces KotlinPoet-based generation of Ktor HTTP client code, including shared client infrastructure and standardized success/error response wrappers, building on earlier model/shared-utility generation work.
Changes:
- Add generators for
ApiClientBase, per-tag API clients, andHttpSuccess/HttpErrorresponse types. - Centralize shared generated-client identifiers in
Names.kt(e.g.,baseUrl,token, helper names). - Add unit tests validating the generated client structures and wiring (constructor params, headers/query/path handling, polymorphic serializers module wiring).
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| core/src/main/kotlin/com/avsystem/justworks/core/gen/ClientGenerator.kt | Generates per-tag Ktor client classes and endpoint functions. |
| core/src/main/kotlin/com/avsystem/justworks/core/gen/ApiClientBaseGenerator.kt | Generates shared base client + helper extensions/utilities. |
| core/src/main/kotlin/com/avsystem/justworks/core/gen/ApiResponseGenerator.kt | Generates HttpSuccess + HttpError (+ HttpErrorType) wrapper types. |
| core/src/main/kotlin/com/avsystem/justworks/core/gen/Names.kt | Adds shared constants/names used across multiple generators. |
| core/src/main/kotlin/com/avsystem/justworks/core/gen/SerializersModuleGenerator.kt | Reuses centralized name for generatedSerializersModule property. |
| core/src/test/kotlin/com/avsystem/justworks/core/gen/ClientGeneratorTest.kt | Tests per-tag client generation, endpoint signatures/body emission, and polymorphic wiring. |
| core/src/test/kotlin/com/avsystem/justworks/core/gen/ApiClientBaseGeneratorTest.kt | Tests generated base client structure and helper functions. |
| core/src/test/kotlin/com/avsystem/justworks/core/gen/ApiResponseGeneratorTest.kt | Tests generated response wrapper types and file outputs. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
… ApiResponseGenerator) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
… ClientGenerator - Standardized terminology by replacing "tokenProvider" with "token". - Improved header parameter handling in generated client code.
…iResponseGenerator and ClientGenerator - Replaced redundant inline property creation with reusable constants. - Improved readability and maintainability by standardizing code structure. - Updated content type in ClientGenerator for more accurate type resolution.
…entBaseGenerator and update test for parameter name change - Improved maintainability by introducing constant definitions for frequently used string literals. - Updated `ApiResponseGeneratorTest` to reflect parameter name change from `statusCode` to `code`.
…pes in ApiClientBaseGenerator - Standardized formatting for builder definitions to improve readability. - Replaced explicitly defined lambda types with inline declarations for brevity.
…ult helper toResult and toEmptyResult now delegate to mapToResult, eliminating duplicated error handling branches. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…enerator definitions - Moved frequently reused property and function names to `Names.kt` for better maintainability. - Simplified class builder and function definitions in `ApiClientBaseGenerator` and `ClientGenerator` to reduce redundancy.
…x property order - safeCall now catches only IOException instead of all exceptions - Extract GENERATED_SERIALIZERS_MODULE and NETWORK_ERROR to Names.kt - Fix HttpError property order to match constructor (code, message, type) - Inline codeProperty into each generator method - Remove unused CATCH_FUN Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…ion handling in generators and tests - Changed `token` parameter and property to accept `() -> String` instead of `String`. - Improved exception handling by adding `HttpRequestTimeoutException` in `safeCall`. - Adjusted tests to reflect updated `token` and exception handling logic.
da5e587 to
4f2c44d
Compare
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Summary
ClientGenerator.kt— generates Ktor HTTP client classes per API tagApiClientBaseGenerator.kt— generates abstract base class with shared HTTP utilitiesApiResponseGenerator.kt— generates HttpSuccess, HttpError, and HttpErrorType response typesStack
master🤖 Generated with Claude Code