Skip to content

Support nullable vs required#9

Merged
bhelx merged 1 commit intomainfrom
required-vs-nullable
Nov 11, 2024
Merged

Support nullable vs required#9
bhelx merged 1 commit intomainfrom
required-vs-nullable

Conversation

@bhelx
Copy link
Contributor

@bhelx bhelx commented Oct 23, 2024

No description provided.

@bhelx bhelx requested a review from zshipko as a code owner October 23, 2024 18:46

if (!tp) throw new Error("Cant convert property to Python type: " + property.type)
if (!property.nullable) return tp
if (!property.nullable && !property.required) return tp
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trying to decide what the logic should be here and if extism.Json is able to distinguish b/w null and optional.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zshipko is there an equivalent of omitempty for the json encoder? We may want to skip the key if the value is None and the type is !required

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not really, I think the best way to handle nullable is to make the field Optional[T] and for non-required we can do the same, but a default value for that field in the dataclass.

I haven't totally thought it through but that should work.

Copy link

@zshipko zshipko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There doesn't seem to be a whole lot more we can do without something like omitempty - so this seems good for now.

I have some related changes in #11 that I can update to work better with this change once it's merged.

@bhelx bhelx merged commit 60242c8 into main Nov 11, 2024
@bhelx bhelx deleted the required-vs-nullable branch November 11, 2024 14:22
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