StefanTerdell / zod-to-json-schema

Converts Zod schemas to Json schemas
ISC License
917 stars 76 forks source link

bug: propertyNames is not generated if the key type is branded #149

Closed mitchell-merry closed 3 weeks ago

mitchell-merry commented 3 weeks ago

This schema:

const schema = z.record(
  z.string().regex(/.+/).brand('MyBrandedThingo'),
  z.number()
);

currently generates as:

{
  "type": "object",
  "additionalProperties": {
    "type": "number"
  },
  "$schema": "http://json-schema.org/draft-07/schema#"
}

when I would expect:

{
  "type": "object",
  "additionalProperties": {
    "type": "number"
  },
  "propertyNames": {
    "pattern": ".+"
  },
  "$schema": "http://json-schema.org/draft-07/schema#"
}

(I have a branch fixing this)