Skip to content

JsonSchema can not be generated #601

Closed
@prutheus

Description

@prutheus

As I thought that the #597 resolves my issues, I found out that following still does not work (but worked with older pydantic/redis-om versions):

Dependencies:

fastapi = "^0.110.0"
redis-om = "^0.2.2"

Model definition:

class ItemConfig(redis_om.HashModel):
    """
    Item Config
    """

    id: str = redis_om.Field(index=True, primary_key=True)
    note: Optional[str]
    purchase_price: Optional[float]

    class Meta:
        """
        Meta
        """

        global_key_prefix = "pw"
        model_key_prefix = "ItemConfig"

FastAPI controller, using ItemConfig model as body parameter for POST endpoint:

@router.post("/config")
def set_item_config(item_config: ItemConfig) -> None:
    ...

Navigating to the generated OpenAPI docs (localhost:8080/docs), getting error:

pydantic.errors.PydanticInvalidForJsonSchema: Cannot generate a JsonSchema for core_schema.PlainValidatorFunctionSchema ({'type': 'with-info', 'function': <bound method BaseModel.validate of <class 'models.ItemConfig'>>})
For further information visit https://errors.pydantic.dev/2.4/u/invalid-for-json-schema

It seems that the redis-om is not properly working with latest pydantic versions, e.g. the ItemConfig.model_json_schema method is not defined (what is new way to get the json schema of a Model).

@slorello89 @banker wdyt?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions