spacetelescope / vo-models

https://vo-models.readthedocs.io/
MIT License
4 stars 2 forks source link

Support multivalued UWS parameters #24

Closed rra closed 1 month ago

rra commented 1 month ago

Support multivalued UWS parameters

Some UWS services (SODA, for example) have multivalued job parameters. The parameter may be specified repeatedly with different values. pydantic-xml supports this and produces a model element that holds a list of Parameters, but it previously was not supported by vo-models because the overridden __init__ method didn't know how to handle lists.

Add support to Parameters.__init__ to first flatten all of the input values into a simple list, regardless of which attribute pydantic-xml thought they corresponded to, and then construct a dict based on id values as before, but create a list of Parameter objects if we see the same id more than once. Document that multi-valued parameters should be declared as MultiValuedParameter instead of list[Parameter], which adds a validator that ensures that the parameters are always converted to a list.

Add a test case for multivalued attributes and for correctly parsing parameters given out of order in XML.

Fixes #21

rra commented 1 month ago

This approach doesn't work in cases where the model attribute is declared as a list but received one element. I'm trying to figure out if there's a better approach that uses more type introspection.

rra commented 1 month ago

I tried a few ways to fix this, but the easiest is to add a validator to the multi-valued fields. This adds a new data type that makes it easy to do that, and updates the documentation accordingly.

jwfraustro commented 1 month ago

Thank you for looking into this, and I apologize for not taking a look at this sooner. The Parameters element in the UWS specification have been a thorn in my side for a long time when working with this and I have a sneaking suspicion they will remain so.

I'll take a look at this today-- everything here seems like great work in handling this case.