Skip to content

feat(generator): services as interfaces for dependency injection#187

Open
aenadgrleey wants to merge 8 commits intomainfrom
services-as-interface
Open

feat(generator): services as interfaces for dependency injection#187
aenadgrleey wants to merge 8 commits intomainfrom
services-as-interface

Conversation

@aenadgrleey
Copy link
Copy Markdown
Contributor

Summary

  • Refactor all SDK generators to extract service interfaces from implementations, enabling dependency injection and testability
  • Add Stub() factory methods to create clients with injectable mocks
  • Add jitter to retry logic and restrict 5xx retries to specific codes (500, 502, 503, 504)
  • Add NotImplementedError typed error in Go for better error handling
  • Add testing examples to SDK READMEs
  • Remove tracked C# build artifacts

Changes by language

Language Interface/Base Class Implementation Stub Factory
TypeScript ChatsService (class) ChatsServiceImpl PachcaClient.stub()
Go ChatsService (interface) ChatsServiceImpl NewStubPachcaClient()
Kotlin ChatsService (interface) ChatsServiceImpl PachcaClient.stub()
Python ChatsService (class) ChatsServiceImpl PachcaClient.stub()
Swift ChatsService (protocol) ChatsServiceImpl PachcaClient.stub()
C# ChatsService (class) ChatsServiceImpl PachcaClient.Stub()

Test plan

  • All generator tests pass
  • Verify Go SDK compiles: cd sdk/go && go build ./...
  • Verify TypeScript SDK compiles: cd sdk/typescript && bun run build
  • Verify stub factories work in each language

🤖 Generated with Claude Code

aenadgrleey and others added 8 commits March 27, 2026 15:41
Enable creation of PachcaClient instances without HTTP clients for
testing purposes. Each language uses its idiomatic pattern:
- Kotlin: companion object with stub() function
- C#: static Stub() method with private constructor
- Go: NewStubPachcaClient() with functional options
- Python: @classmethod stub() bypassing __init__
- Swift: static func stub() with private init

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Document PachcaClient.stub() usage for unit testing with mock services.
Each README now includes language-specific examples and describes what
happens when calling non-overridden methods (throws/returns error).

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Also adds jitter to retry delays and uses explicit 5xx status codes
(500, 502, 503, 504) instead of >= 500 range.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Add jitter (0.5-1.0 random factor) to retry delays across all SDKs
- Add 5xx retry (500, 502, 503, 504) to TypeScript, Go, Python, Swift
- Convert Kotlin services from open class to interface pattern
- Revert TypeScript constructor to non-breaking positional args format
- Remove TypeScript override keyword for ES5/ES6 compatibility

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
…ntedError

- Move jitter, retry constants, and doWithRetry to utils.go (matches other SDKs)
- Add NotImplementedError struct type for better error handling in stubs
- Fix TypeScript docs: revert incorrect object syntax back to positional args

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
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.

1 participant