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

Idea for custom built in types #7029

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
"""OpenBB Platform API Meta Package."""

from . import utils
from .utils.types import OptionsEndpoint

__all__ = [
"utils",
"OptionsEndpoint",
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
from typing import Any, Callable, Literal, Optional

from pydantic import BaseModel, Field, GetCoreSchemaHandler, GetJsonSchemaHandler
from pydantic.json_schema import JsonSchemaValue
from pydantic_core import CoreSchema, core_schema


class OptionsEndpoint:
def __new__(cls, func: Callable[[], list[str]]):
values = func()

class DynamicOptions:
@classmethod
def __get_pydantic_core_schema__(cls, _source_type: Any, _handler: GetCoreSchemaHandler) -> CoreSchema:
return core_schema.literal_schema(values)

@classmethod
def __get_pydantic_json_schema__(
cls,
_core_schema: CoreSchema,
_handler: GetJsonSchemaHandler,
) -> JsonSchemaValue:
return {
"type": "string",
"enum": values,
}

return DynamicOptions


class RenderFnParams(BaseModel):
actionType: str = Field(..., description="Specifies the action type for the render function")


class ColumnDef(BaseModel):
field: str = Field(..., description="The name of the field from the JSON data")
headerName: str = Field(..., description="The display name of the column header")
chartDataType: Optional[Literal["category", "series", "time", "excluded"]] = Field(
None, description="Specifies how data is treated in a chart"
)
cellDataType: Optional[Literal["text", "number", "boolean", "date", "dateString", "object"]] = Field(
None, description="Specifies the data type of the cell"
)
formatterFn: Optional[str] = Field(None, description="Specifies how to format the data")
renderFn: Optional[Literal["greenRed", "cellOnClick", "titleCase"]] = Field(
None, description="Specifies a rendering function for cell data"
)
renderFnParams: Optional[RenderFnParams] = Field(
None, description="Required if renderFn cellOnClick is used. Specifies the parameters for the render function"
)
width: Optional[int] = Field(None, gt=0, description="Specifies the width of the column in pixels")
maxWidth: Optional[int] = Field(None, gt=0, description="Specifies the maximum width of the column in pixels")
minWidth: Optional[int] = Field(None, gt=0, description="Specifies the minimum width of the column in pixels")
hide: Optional[bool] = Field(False, description="Hides the column from the table")
pinned: Optional[Literal["left", "right"]] = Field(
None, description="Pins the column to the left or right of the table"
)
Loading