-
Notifications
You must be signed in to change notification settings - Fork 94
Description
What do I want to achive
I want kor to generate a Typescript description like the following:
bookings: Array<{
project: string
date: string
amount: {
value: number
unit: string
}
}>
What did I try
Define the following pydantic schema:
class Amount(BaseModel):
value: int
unit: str
class Booking(BaseModel):
project: str
date: str
amount: Amount
class Bookings(BaseModel):
bookings: List[Booking]
Bookings(bookings=...).json()
generates the desired output {"bookings": [{"project": "...", "date": "...", ' '"amount": {"value": "...", "unit": "..."}}]}
, so I think the schema definition is correct.
The output of the current from_pydantic
implementation is the following:
Call:
booking_schema, validator = from_pydantic(
Bookings,
description="",
examples=booking_examples,
many=False,
)
Output:
bookings: {
bookings: Array<{
project: string
date: string
amount: {
value: number
unit: string
}
}>
}
To overcome this, I tried:
Call:
booking_schema, validator = from_pydantic(
Booking,
description="",
examples=booking_examples,
many=True,
)
Output:
booking: Array<{
project: string
date: string
amount: {
value: number
unit: string
}
}>
The output is better, but I need the string "bookings" (with an "s"), and couldn't find a way to accomplish this.
How I think it may be solved
Add parameter id
to from_pydantic
method.
Currently the from_pydantic
method allows for the definition of a description
, examples
and the many
flag.
In my opinion the id parameter is missing. Since it is possible to define it in a kor-Object, it should also be possible to provide it to this method. This way it will be possible to set the name of the root object, in my case to "bookings".