Coder Social home page Coder Social logo

Comments (4)

StefanTerdell avatar StefanTerdell commented on May 16, 2024 1

@bacebu4 Check the tests pr #28, let me know what you think

from zod-to-json-schema.

StefanTerdell avatar StefanTerdell commented on May 16, 2024 1

Released as 3.19.2

from zod-to-json-schema.

StefanTerdell avatar StefanTerdell commented on May 16, 2024

I like the idea in principle, but I see a few issues:

  1. .brand() has a pretty substantial effect on your Zod schemas by essentially disabling duck-typing
  2. It would require a substantial refactoring of the current reference collection flow

How about something like this?

const myRecurringSchema = z.string()
const myObjectSchema = z.object({a: myRecurringSchema, b: myRecurringSchema})

const myJsonSchema = zodToJsonSchema(myObjectSchema, { definitions: { myRecurringSchema }})

With output

{
  "type": "object",
  "properties": {
    "a": {
      "$ref": "#/definitions/myRecurringSchema"
    },
    "b": {
      "$ref": "#/definitions/myRecurringSchema"
    }
  },
  "definitions": {
    "myRecurringSchema": {
      "type": "string"
    }
  }
}

This way we limit the blast radius by avoiding branding and can instantiate a References object "preloaded" with ref paths using the keys from the definitions option record

from zod-to-json-schema.

bacebu4 avatar bacebu4 commented on May 16, 2024

@bacebu4 Check the tests pr #28, let me know what you think

Really liked the implementation, much better and cleaner than proposed solution

from zod-to-json-schema.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.