apple / apple/swift-openapi-generator

Support customising names of generated types

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

Description

### Motivation

Currently the code generated by swift-openapi-generator uses very generic type names that cannot be customised, e.g. `Client`, `Operation`, `APIProtocol`, and so on. These names aren't particularly descriptive (what kind of client? what kind of operation?) and prevent multiple generated API clients from being used within a project without splitting them into their own modules and using fully qualified type names (e.g. `MyAPI.Client`).

### Proposed solution

It would be ideal to have some way to customise the names of generated types. I propose adding a set of configuration options to control this, e.g.:

```yaml
typeNames:
Client: MyServiceClient
Operations: MyServiceOperations
APIProtocol: MyServiceAPIProtocol
```

### Alternatives considered

In most cases, what you really want is some sort of prefix to disambiguate type names, in which case we could simplify the config by simply providing this prefix:

```yaml
typeNamePrefix: MyService
```

This may also be preferable as it maps more cleanly to a command line argument, e.g. `swift-openapi-generator generate --type-name-prefix MyService`.

### Additional information

_No response_

Contributor guide

Open the contributing guide

Research direction

The issue does not name files, tests, or an entry point; begin by locating the configuration and `generate` command handling described here, and compare the `typeNames` and `typeNamePrefix` proposals. Done means generated types can be customized so multiple API clients coexist without module separation, with the final configuration shape and CLI behavior settled.

Written by the indexing model from the issue text.

Assessment

Tech stack
openapi, swift
Domain
tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.