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

Do not restrict to canonical values #34

Open
azmeuk opened this issue Jun 20, 2024 · 1 comment
Open

Do not restrict to canonical values #34

azmeuk opened this issue Jun 20, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@azmeuk
Copy link
Member

azmeuk commented Jun 20, 2024

RFC7643 §2.3.1 indicates that string types with canonical values defined can or cannot have other values, depending on the server configuration:

   Additionally, when "canonicalValues"
   is specified, service providers MAY restrict accepted values to the
   specified values.

In §7 it is indicated that values can be ignored:


      canonicalValues  A collection of suggested canonical values that
         MAY be used (e.g., "work" and "home").  In some cases, service
         providers MAY choose to ignore unsupported values.  OPTIONAL.

Currently scim2_models defines custom enums, but that makes pydantic enforce those values only.

class Email(MultiValuedComplexAttribute):
class Type(str, Enum):
work = "work"
home = "home"
other = "other"

type: Optional[Type] = None
"""A label indicating the attribute's function, e.g., 'work' or 'home'."""

In that situation scim2-models should accept both arbitrary and enum values.

Also, when #6 is implemented, scim2-models should generate dynamic enums.

@azmeuk
Copy link
Member Author

azmeuk commented Jun 20, 2024

This test should pass:

def test_canonical_values():
    class Model(Resource):
        class Foo(str, Enum):
            bar = "bar"
            baz = "baz"

        schemas: List[str] = ["urn:example:2.0:Model"]
        foo: Optional[Foo]

    valid = Model(foo="bar")
    assert valid.foo == "bar"

    valid = Model(foo="invalid")
    assert valid.foo is None

@azmeuk azmeuk added the bug Something isn't working label Jun 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant