Skip to content

feat(plugin): add generateInterfaces option#86

Open
halotukozak wants to merge 4 commits into
masterfrom
feat/44-generate-interfaces
Open

feat(plugin): add generateInterfaces option#86
halotukozak wants to merge 4 commits into
masterfrom
feat/44-generate-interfaces

Conversation

@halotukozak

Copy link
Copy Markdown
Member

Stacked on #85 (feat/43-api-class-prefix-suffix, which is stacked on #84). Base is feat/43-..., so this diff shows only the #44 changes. Merge after #84#85.

What

Adds generateInterfaces (Boolean, default false). 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.

  • Interface keeps the configured name (e.g. PetsApi); the client class gets an Impl suffix (PetsApiImpl).
  • Respects apiClassPrefix / apiClassSuffix (e.g. suffix ClientPetsClient + PetsClientImpl).
  • Default false → single-class output unchanged.

Implementation

generateEndpointFunction gains explicit override / includeBody / includeKdoc modes:

  • interface member: abstract, no body, carries the KDoc;
  • impl member: override + body, KDoc omitted (lives on the interface), and parameter defaults stripped (Kotlin forbids defaults on overrides).

Tests

  • Core: interfaces off → only PetsApi; on → PetsApi (interface, abstract suspend members) + PetsApiImpl (implements, override + body); honors custom prefix/suffix.
  • Plugin functional: generateInterfaces = true runs compileKotlin end-to-end, asserting PetsApi.kt (interface) + PetsApiImpl.kt exist and compile.

Docs

README config row + "Interfaces for Testing" example.

Closes #44

🤖 Generated with Claude Code

halotukozak and others added 2 commits June 9, 2026 17:22
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`.
@halotukozak halotukozak added this to the 1.0.0 milestone Jun 9, 2026
@halotukozak halotukozak self-assigned this Jun 9, 2026
@halotukozak halotukozak added the enhancement New feature or request label Jun 9, 2026
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.
Base automatically changed from feat/43-api-class-prefix-suffix to master June 10, 2026 14:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant