glideapps / glideapps/quicktype

[Swift] Add a --nest-types option to avoid child type name collisions in multi-source generation

Open
#3,104 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
13.9k
Forks
1.2k
Avg merge
8h 53m
Merged PRs (30d)
369

Description

## Problem

When quicktype generates code from multiple input sources, child types are emitted at the top level instead of being nested inside the corresponding root type.

For example, Swift output may look like:

```swift
public struct RspAPIV1AIToolTemplateToImageExecutionGet: Codable {
public let id: String
public let images: [Image]
public let status: String
}

public struct Image: Codable {
public let id: String
public let url: String
}
```

If another input source also produces a child type named `Image`, the generated declarations collide. This is especially problematic when combining independently generated API models from multiple sources.

## Proposed feature

Add a `--nest-types` (or equivalent `nest-type`) option that nests generated child types inside their owning/root type when the target language supports nested types.

The example above would become conceptually:

```swift
public struct RspAPIV1AIToolTemplateToImageExecutionGet: Codable {
public let id: String
public let images: [Image]
public let status: String

public struct Image: Codable {
public let id: String
public let url: String
}
}
```

References should use the nested type as appropriate, e.g. `[RspAPIV1AIToolTemplateToImageExecutionGet.Image]` where required by the target language.

## Scope

- Primarily needed for multi-source generation.
- Preserve current flat output as the default for backwards compatibility.
- Enable nesting only with the new option.
- For target languages without nested type support, document the behavior or report a clear unsupported-option error.

This would provide namespace isolation and prevent symbol collisions without requiring users to manually rename generated types.

Contributor guide

Open the contributing guide

Research direction

No files, tests, or entry points are named. Start by tracing multi-source type generation and target-language support, then define the option's default, nested references, and unsupported-language behavior; done means Swift can opt into collision-free nesting while existing flat output remains unchanged.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.