apple / apple/swift-openapi-generator

Consider using typed throws on methods that always throw ClientError/ServerError

Open
#844 1 comment 3 reactions 0 assignees View on GitHub
area/generator area/runtime kind/enhancement
Dominant language
Swift
Stars
2k
Forks
182
Avg merge
13h 28m
Merged PRs (30d)
5

Description

Consider using typed throws on methods that always throw ClientError/ServerError.

This will allow adopters to remove an extra `} catch {` that doesn't have clear purpose.

```swift
do {
_ = try await try await client.getGreeting(input: ...)
} catch as ClientError {
// This branch is always taken
} catch {
// This branch is never taken, we always throw ClientError
}
```

Similar on the server.

With typed throws, we'll be able to do:

```swift
do {
_ = try await try await client.getGreeting(input: ...)
} catch {
// This branch is always taken and error is statically known to be ClientError
}
```

Contributor guide

Open the contributing guide

Research direction

Start by tracing the generated client method shown in the example and the corresponding server methods that always throw ClientError or ServerError. Determine how generated APIs currently declare throws and what generated output must change so the error type is statically known on both sides. Done means adopters no longer need an unreachable catch branch for these methods.

Written by the indexing model from the issue text.

Assessment

Tech stack
swift
Domain
api, backend-api-design
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.