Bug: `number` field not generating schema with default value
andenacitelli opened this issue · comments
I have an object defined as follows:
RequestOptions:
type: object
properties:
temperature:
type: number
description: Temperature of the model. Higher values means more creative responses. A value of zero always provides the same output for a given input - we trim your cost by 5x if you do so, as we can cache the output and pass on the savings to you.
example: 0.5
minimum: 0
maximum: 1
default: 0
model:
$ref: "#/components/schemas/ModelsEnum"
default:
temperature: 0
model: gpt-3.5-turbo
Relevant ModelsEnum
here:
ModelsEnum:
type: string
default: gpt-3.5-turbo
enum:
- gpt-3.5-turbo
The output zod
schema looks like this:
const ModelsEnum = z.literal("gpt-3.5-turbo");
const RequestOptions = z
.object({
temperature: z.number().gte(0).lte(1),
model: ModelsEnum.default("gpt-3.5-turbo"),
})
.partial();
The temperature
attribute should have a default value, no? The enum is correctly set to its default value, but the number seems to have that missing default value.
Using openapi: 3.0.0
in my schema. swagger-cli validate ./src/api.yaml
gives no errors, so I believe my schema overall is valid.
Happy to provide more detail, if needed, just tried to include the relevant parts.
yes, you're right, the current lib's output is wrong
for future references, here's the minimal reproduction in the playground
would you like to look into it ?
Doubt I'll get the time in the near future. I'll leave it open to anyone interested.