Skip to content

Conversation

@jpbrodrick89
Copy link
Contributor

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 42 as 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

⚠️ Made some changes to test_app that weren't directly related to this PR, I removed the output field dummy which is not in the OutputSchema and changed int.hobby.name to str.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.

@dionhaefner
Copy link
Contributor

Looks really useful, thanks. @jacanchaplais are you taking this one?

@jacanchaplais
Copy link
Collaborator

Thanks both @dionhaefner and @jpbrodrick89. Yep, will review this today or tomorrow. :)

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.

4 participants