Skip to content

feat: handle nullable oneOf#1531

Merged
ernado merged 1 commit intoogen-go:mainfrom
ngalaiko:push-ykztwtwzxwur
Sep 17, 2025
Merged

feat: handle nullable oneOf#1531
ernado merged 1 commit intoogen-go:mainfrom
ngalaiko:push-ykztwtwzxwur

Conversation

@ngalaiko
Copy link
Contributor

@ngalaiko ngalaiko commented Sep 17, 2025

One of the differences between OpenAPI 3.1 and 3.0 is how nullable
values are represented:

In 3.0, they are maked with nullable: true, and ogen handles that.

In 3.1, there are two ways:

  • json schema type arrays for primitives:
type:
  - "string"
  - "null"
  • oneOf with a null alternative for other things (including
    primitives):
oneOf:
  - type: "string"
  - type: "null"

This commits adds special hadling for latter to unlock openapi 3.1
compatible specs to be handled by ogen.

Type array support is needed for for openapi 3.1 compatability, but this
is a first step that unlocks at least some 3.1 specs to be handled by
ogen.

One of the differences between OpenAPI 3.1 and 3.0 is how nullable
values are represented:

In 3.0, they are maked with `nullable: true`, and ogen handles that.

In 3.1, there are two ways:

- json schema type arrays for primitives:

```yaml
type:
  - "string"
  - "null"
```

- oneOf with a null alternative for other things (including
  primitives):

```yaml
oneOf:
  - type: "string"
  - type: "null"
```

This commits adds special hadling for latter to unlock openapi 3.1
compatible specs to be handled by ogen.

Type array support is needed for for openapi 3.1 compatability, but this
is a first step that unlocks at least some 3.1 specs to be handled by
ogen.
@ernado ernado merged commit 57c7a8f into ogen-go:main Sep 17, 2025
15 checks passed
ernado added a commit that referenced this pull request Sep 18, 2025
ngalaiko added a commit to ngalaiko/ogen that referenced this pull request Sep 19, 2025
ngalaiko added a commit to ngalaiko/ogen that referenced this pull request Sep 19, 2025
This is a refined version of ogen-go#1531

I have added more tests in ./gen/nullable_oneof_test.go to make sure
that all cases are covered.

Also implementation was changed to handle the translation on `generate()`
function level instead of a lower-lever `oneOf()`.
ngalaiko added a commit to ngalaiko/ogen that referenced this pull request Sep 19, 2025
ngalaiko added a commit to ngalaiko/ogen that referenced this pull request Sep 19, 2025
This is a refined version of ogen-go#1531

I have added more tests in ./gen/nullable_oneof_test.go to make sure
that all cases are covered.

Also implementation was changed to handle the translation on `generate()`
function level instead of a lower-lever `oneOf()`.
ngalaiko added a commit to ngalaiko/ogen that referenced this pull request Sep 19, 2025
This is a refined version of ogen-go#1531

I have added more tests in ./gen/nullable_oneof_test.go to make sure
that all cases are covered.

Also implementation was changed to handle the translation on `generate()`
function level instead of a lower-lever `oneOf()`.
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.

2 participants