Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optional fields types #1245

Open
magaya-andrewthal opened this issue Dec 18, 2024 · 2 comments
Open

Optional fields types #1245

magaya-andrewthal opened this issue Dec 18, 2024 · 2 comments

Comments

@magaya-andrewthal
Copy link

The logic to prevent a field from becoming required when skip_serializing_if is present works as intended, however, it appears that the property type still includes both the type itself as well as 'null'.

It would be nice if only the primary type was included in the spec upon successful detection of an Option implying that a field is not required and null will not be serialized.

@juhaku
Copy link
Owner

juhaku commented Jan 2, 2025

So if type is Option<i32> then what should happen? Should there be a way to not to include type to the OpenAPI spec when type is a optional primitive type? I don't quite grasp what should be done here. But sounds like some feature enhancement.

@magaya-andrewthal
Copy link
Author

Expected:
Given skip_serializing_if is present on the field
And the field is an option
Then the openapi spec field type has just the primitive type
And the openapi spec does not mark the field as required

Current:
Given skip_serializing_if is present on the field
And the field is an option
Then the openapi spec field type has both the primitive type and 'null'
And the openapi spec does not mark the field as required

In my opinion, the logic that was introduced to respect skip_serializing_if is incomplete, in that it successfully marks the field as not required, but it also indicates that the field could be present and 'null', even though skip_serializing_if prevents the field from ever being present and null.

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

No branches or pull requests

2 participants