feat: support union and optional arguments #83
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description of changes
Support union and optional types (e.g.
float | str,str | None,Hobby | list[Hobby]:Resolution rules:
1. If null is in union, remove it and set is_optional=True
2. If any member has $ref, resolve to "json"
3. If only int/float types remain, resolve to "number"
4. If array + only int/float, resolve to "array"
5. If has number + other non-composite types, resolve to "string" with could_be_number=True
6. Otherwise resolve to "string" with could_be_number=False
could_be_number means that text input renders
42as a number (Pydantic's smart resolution would resolve"42"as a string).Added checkboxes for optional arguments if unselected then None is passed. Unfortunately, removing the input field conditionally is not possible in a jinja template. Any reason why we're using jinja templates and not pure streamlit here?
Testing done
dummywhich is not in the OutputSchema and changedint.hobby.nametostr.hobby.name. I have no idea how tests passed previously...Added test cases to mock schemas and goodbyeworld.
Added unit tests for parsing functions.
Manual testing.