'Schema not show child list using SQLModel with FastAPI

I need help using SQLModel and FastAPI:

from typing import Optional, List
from sqlalchemy import UniqueConstraint
from sqlmodel import Field, Relationship, SQLModel


class Servers(SQLModel, table=True):
    id: Optional[int] = Field(default=None, primary_key=True)
    servername: str
    server_ip: str
    is_active: bool

    folders: Optional[List['ServersFolders']] = Relationship(back_populates='server')

    __table_args__ = (
        UniqueConstraint('servername', name='_servername_uc'),
        UniqueConstraint('server_ip', name='_serverip_uc'),
    )


class ServersFolders(SQLModel, table=True):
    id: Optional[int] = Field(default=None, primary_key=True)
    server_id: int = Field(index=True, foreign_key='servers.id')
    folder_path: str

    server: Servers = Relationship(back_populates='folders')
    account_base_folders: Optional[List['AccountBaseFolders']] = Relationship(
        back_populates='server_folder'
    )

    __table_args__ = (
        UniqueConstraint('server_id', 'folder_path', name='_server_folder_uc'),
    )

But openapi 3.0.2 schema looks like:

http://localhost:8000/docs#

Servers{
    id  integer
    servername* string
    server_ip*  string
    is_active*  boolean
}

ServersFolders{
    id  integer
    server_id*  integer
    folder_path*    string
}

Why schema is not showing "folders" in servers? servers should show folders as a list of serversfolders.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source