apple / apple/swift-openapi-generator

codegen fails to produce anyOf/oneOf with a null type

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

Description

### Description

The code generator skips `anyOf` or `oneOf` that have nullable listed:

```
warning: Schema "null" is not supported, reason: "schema type", skipping [context: foundIn=Operations.OperationName.Output.Ok.Body.JsonPayload.DataPayloadPayload (#/paths/path/to/resource/GET/responses/200/content/json/DataPayload)/my_type]
```

### Reproduction

```json
"my_type": {
"anyOf": [
{
"$ref": "#/components/schemas/MyType"
},
{
"type": "null"
}
]
}
```

```json
"my_type": {
"oneOf": [
{
"$ref": "#/components/schemas/MyType"
},
{
"type": "null"
}
]
}
```

### Package version(s)

Image

### Expected behavior

ideally it should produce an optional. But an enum would also work.

### Environment

swift 6.2
Xcode 26.0 beta 6

### Additional information

The only workaround I've found is to do something like this, but the library our back end is using to produce the openapi spec does not seem to support something like this:

```
"my_type": {
"$ref": "#/components/schemas/MyType",
"type": ["object", "null"]
},
```

Contributor guide

Open the contributing guide

Research direction

Start at the code generator's schema-type handling and reproduce the issue with the provided anyOf and oneOf OpenAPI snippets. Done means nullable schemas are represented in generated output as an optional or enum, without the reported unsupported-null warning.

Written by the indexing model from the issue text.

Assessment

Tech stack
openapi, swift
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
64/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.