-
Notifications
You must be signed in to change notification settings - Fork 3
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
Added set support for arrays #117
base: main
Are you sure you want to change the base?
Conversation
The code looks good! Please add a test case in |
Also, for the future: If you write "This fixes #107" into the PR description, GitHub will automatically link it to the issue. |
I've noticed that
For the test case so far
So either the pydantic model throws an error or the test case fails when I use |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should not be part of the PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same.
result = [h.getter() for h in elements[:element_size]] | ||
if schema.get("set", False): | ||
if len(result) != len(set(result)): | ||
raise FormError("Array elements are not unique") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at what pydantic
does, I think it would also be acceptable to make the array unique instead of throwing an error:
import pydantic
from typing import Set
class Foo(pydantic.BaseModel):
ids: Set[str]
Foo(ids=["a", "a"])
above code outputs Foo(ids={'a'})
@@ -931,12 +931,19 @@ def _resetter(): | |||
# Initially call the resetter | |||
_resetter() | |||
|
|||
def _getter(): | |||
result = [h.getter() for h in elements[:element_size]] | |||
if schema.get("set", False): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there is a mix-up here of set
and uniqueItems
. uniqueItems
is deprecated in a pydantic field definition, but it is still very much in the generated JSONSchema. set
on the other hand does not exist in the JSONSchema spec - but uniqueItems
does.
No description provided.