feat(plugin): add generateInterfaces option#86
Open
halotukozak wants to merge 4 commits into
Open
Conversation
Adds generateInterfaces (Boolean, default false) to JustworksSpecConfiguration. When enabled, an interface is generated per API tag holding all endpoint signatures, and the concrete client implements it. The interface keeps the configured name (e.g. PetsApi) and the client gets an `Impl` suffix (PetsApiImpl), enabling hand-written fakes in tests without a mocking library. Endpoint function generation now has explicit override/body/kdoc modes: interface members are abstract and carry the KDoc; impl members override and hold the body (and drop parameter defaults, which live on the interface). Default false keeps the single-class output unchanged. Closes #44 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…s generation Optimize interface-related logic by removing redundant null checks and replacing them with `takeIf` for cleaner code. Streamline endpoint function generation with direct use of `options.generateInterfaces`. Simplify return logic by using `listOfNotNull`.
The interface name was registered via `register(baseName).takeIf {
generateInterfaces }`, whose side effect ran even when interfaces were
disabled, so the impl class then got a `2`-suffixed name. Register the
interface name only when generateInterfaces is set.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds
generateInterfaces(Boolean, defaultfalse). When enabled, an interface is generated per API tag holding all endpoint signatures, and the concrete client implements it — enabling hand-written fakes in tests without a mocking library.PetsApi); the client class gets anImplsuffix (PetsApiImpl).apiClassPrefix/apiClassSuffix(e.g. suffixClient→PetsClient+PetsClientImpl).false→ single-class output unchanged.Implementation
generateEndpointFunctiongains explicitoverride/includeBody/includeKdocmodes:abstract, no body, carries the KDoc;override+ body, KDoc omitted (lives on the interface), and parameter defaults stripped (Kotlin forbids defaults on overrides).Tests
PetsApi; on →PetsApi(interface, abstract suspend members) +PetsApiImpl(implements, override + body); honors custom prefix/suffix.generateInterfaces = truerunscompileKotlinend-to-end, assertingPetsApi.kt(interface) +PetsApiImpl.ktexist and compile.Docs
README config row + "Interfaces for Testing" example.
Closes #44
🤖 Generated with Claude Code