Skip to content

feat: add client generation - #10

Merged
halotukozak merged 11 commits into
masterfrom
feat/client-generation
Mar 19, 2026
Merged

feat: add client generation#10
halotukozak merged 11 commits into
masterfrom
feat/client-generation

Conversation

@halotukozak

Copy link
Copy Markdown
Contributor

Summary

  • ClientGenerator.kt — generates Ktor HTTP client classes per API tag
  • ApiClientBaseGenerator.kt — generates abstract base class with shared HTTP utilities
  • ApiResponseGenerator.kt — generates HttpSuccess, HttpError, and HttpErrorType response types

Stack

  1. feat/shared-utilities → master
  2. feat/model-generation → feat/shared-utilities
  3. this PR → feat/model-generation

🤖 Generated with Claude Code

Copilot AI review requested due to automatic review settings March 17, 2026 13:52

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

  • ClientGenerator generates one client class per API tag, with suspend functions for each endpoint, path/query/header parameter handling, and polymorphic serialization support
  • ApiClientBaseGenerator generates a shared abstract ApiClientBase class with auth, error handling (safeCall), and HTTP client creation utilities
  • ApiResponseGenerator generates HttpError, HttpErrorType, and HttpSuccess<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.

Comment thread core/src/main/kotlin/com/avsystem/justworks/core/gen/ApiClientBaseGenerator.kt Outdated
Comment thread core/src/main/kotlin/com/avsystem/justworks/core/gen/ClientGenerator.kt Outdated
Comment thread core/src/main/kotlin/com/avsystem/justworks/core/gen/ApiResponseGenerator.kt Outdated
Comment thread core/src/main/kotlin/com/avsystem/justworks/core/gen/ClientGenerator.kt Outdated
@halotukozak
halotukozak force-pushed the feat/client-generation branch 2 times, most recently from 262772b to 8a233a4 Compare March 17, 2026 14:49
@halotukozak halotukozak self-assigned this Mar 18, 2026
@halotukozak
halotukozak requested a review from mzielu March 18, 2026 11:41

@mzielu mzielu left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

small comments, please let's focus on model-generation PR to be closed before the next round of review

Comment thread core/src/main/kotlin/com/avsystem/justworks/core/gen/ApiResponseGenerator.kt Outdated
Comment thread core/src/main/kotlin/com/avsystem/justworks/core/gen/ApiResponseGenerator.kt Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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, and HttpSuccess/HttpError response 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.

Comment thread core/src/main/kotlin/com/avsystem/justworks/core/gen/ClientGenerator.kt Outdated
Comment thread core/src/main/kotlin/com/avsystem/justworks/core/gen/ApiClientBaseGenerator.kt Outdated
Comment thread core/src/main/kotlin/com/avsystem/justworks/core/gen/ApiClientBaseGenerator.kt Outdated
Base automatically changed from feat/model-generation to master March 19, 2026 08:32
@halotukozak
halotukozak requested a review from mzielu March 19, 2026 08:40
halotukozak and others added 10 commits March 19, 2026 09:58
… 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.
@halotukozak
halotukozak force-pushed the feat/client-generation branch from da5e587 to 4f2c44d Compare March 19, 2026 08:59
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@halotukozak
halotukozak requested a review from mzielu March 19, 2026 10:31

@mzielu mzielu left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good job, lgtm!

@halotukozak
halotukozak merged commit bc68f5b into master Mar 19, 2026
1 check passed
@halotukozak
halotukozak deleted the feat/client-generation branch March 19, 2026 11:01
@halotukozak halotukozak added this to the 0.0.1 milestone Apr 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants