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

[REQ] Support Set in python for array w/ uniqueItems=True #9552

Closed
Gidgidonihah opened this issue May 21, 2021 · 3 comments
Closed

[REQ] Support Set in python for array w/ uniqueItems=True #9552

Gidgidonihah opened this issue May 21, 2021 · 3 comments

Comments

@Gidgidonihah
Copy link

Gidgidonihah commented May 21, 2021

Is your feature request related to a problem? Please describe.

In upgrading from 5.0.1 to 5.1.0 I found that the types changed for arrays with uniqueItems=True from Set to list. For us, this was a breaking change as we rely upon type hints.

Describe the solution you'd like

IMO, Set should be mapped to set in python, rather than to list. The tradeoff is that the array is not ordered, but it enforces (or rather easily allows us to enforce when deserializing using the supplied type) the uniqueItems constraint.

Describe alternatives you've considered

Alternatively, we don't marshall with set, and alter to the templates to handle duplicate values with uniqueItems.

Additional context

The refactor to add a python ABC in essence added a Set to list mapping to the AbstractPythonConnexionServerCodegen class via AbstractPythonCodegen, whereas previously it assumed a model of Set. This worked well as we could from typing import Set.

We then had custom templates that looked at __origin__ and applied mutations. As of 5.1 Set is now mapped to list and no longer allows us to do so.

Additionally, when using the python-flask templates, Set is currently mapped to list whereas array is currently mapped to List.

See also #8784

@wing328
Copy link
Member

wing328 commented May 24, 2021

Thanks for reporting the issue. I'll see what I can do to fix it this week.

@spacether
Copy link
Contributor

spacether commented Jan 5, 2022

uniqueItems has been added to the python-experimental generator in #8325
The data type was kept as tuple to allow other schemas with type list->(enforced as tuple) lacking uniqueItems to correctly validate against a list payload with unique items.
That way data like
[0, 1]
will validate against: ListWithUniqueItems + ListWithMinItems + SomeComposedSchema

ListWithUniqueItems:
  type: array
  uniqueItems: true
ListWithMinItems:
  type: array
  minItems: 2
SomeComposedSchema:
  allOf:
  - ListWithUniqueItems
  - ListWithMinItems

@spacether
Copy link
Contributor

spacether commented Jan 12, 2022

Closing this issue because uniqueItems is implement in python-experimental

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants