asteasolutions / zod-to-openapi

A library that generates OpenAPI (Swagger) docs from Zod schemas
MIT License
955 stars 60 forks source link

Field of default 0 is being marked as required #243

Closed arjunyel closed 4 months ago

arjunyel commented 4 months ago

I tried to fix this but couldn't figure it out in the time I had, I made a failing test for this: #242

it('supports default of 0', () => {
  expectSchema(
    [z.object({ test: z.number().positive().default(0) }).openapi('Object')],
    {
      Object: {
        type: 'object',
        properties: {
          test: {
            type: 'number',
            default: 0,
            exclusiveMinimum: true,
            minimum: 0,
          },
        },
      },
    }
  );
});
- Expected  - 0
+ Received  + 3

@@ -6,8 +6,11 @@
          "exclusiveMinimum": true,
          "minimum": 0,
          "type": "number",
        },
      },
+     "required": Array [
+       "test",
+     ],
      "type": "object",
    },
  }