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

Cardinality slots are not reflected in pydantic models for multivalued fields, but they work in arrays #2109

Open
manulera opened this issue May 15, 2024 · 0 comments
Labels
bug Something that should work but isn't, with an example and a test case. community-generated generator-pydantic

Comments

@manulera
Copy link
Contributor

Following a slack conversation with @cmungall

Using linkml 1.7.8

Cardinality slots are not reflected in pydantic models for multivalued fields, but they work in arrays. I don't know if this is only an error of the pydantic generator, or it also affects other things.

For instance:

slot_usage:
  input:
    multivalued: true
    maximum_cardinality: 3
    minimum_cardinality: 1

Translates into this in pydantic:

input: Optional[List[int]] = Field(
        default_factory=list,
        description=...)

Whereas this:

    slot_usage:
      input:
        array:
          dimensions:
            - alias: max_card
              maximum_cardinality: 3
              minimum_cardinality: 1

Gives the wanted result in pydantic:

input: Optional[conlist(min_length=1, max_length=3, item_type=int)] = Field(
        default_factory=list,
        description=...,
    )
@manulera manulera added the bug Something that should work but isn't, with an example and a test case. label May 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something that should work but isn't, with an example and a test case. community-generated generator-pydantic
Projects
None yet
Development

No branches or pull requests

2 participants