GithubHelp home page GithubHelp logo

Support `readonly()` about zod-to-json-schema HOT 5 CLOSED

thorhj avatar thorhj commented on May 23, 2024 2
Support `readonly()`

from zod-to-json-schema.

Comments (5)

StefanTerdell avatar StefanTerdell commented on May 23, 2024 3

@fredrikj31 about a minute ago

from zod-to-json-schema.

StefanTerdell avatar StefanTerdell commented on May 23, 2024 2

Done in master

from zod-to-json-schema.

kachkaev avatar kachkaev commented on May 23, 2024 1

Same issue here. Does readonly() affect the result or is it a ‘transparent’ definition , like .catch()?

import { ZodCatchDef } from "zod";
import { parseDef } from "../parseDef";
import { Refs } from "../Refs";
export const parseCatchDef = (def: ZodCatchDef<any>, refs: Refs) => {
return parseDef(def.innerType._def, refs);
};

If it’s the latter, supporting .readonly() should be pretty straightforward. Happy to submit a PR if it makes sense.


UPD: This local patch seems to be working – I no longer get empty schemas 🎉

diff --git a/src/parseDef.js b/src/parseDef.js
index 4f33785322590999d31593cdcbdb174175930799..f8a09be4387cd64c1534f1f3a2a6c70f4625e1f2 100644
--- a/src/parseDef.js
+++ b/src/parseDef.js
@@ -151,6 +151,8 @@ const selectParser = (def, typeName, refs) => {
         case zod_1.ZodFirstPartyTypeKind.ZodBranded:
             return (0, branded_1.parseBrandedDef)(def, refs);
         case zod_1.ZodFirstPartyTypeKind.ZodCatch:
+        // https://github.com/StefanTerdell/zod-to-json-schema/issues/90
+        case zod_1.ZodFirstPartyTypeKind.ZodReadonly:
             return (0, catch_1.parseCatchDef)(def, refs);
         case zod_1.ZodFirstPartyTypeKind.ZodPipeline:
             return (0, pipeline_1.parsePipelineDef)(def, refs);

For simplicity, ZodReadonly is processed the same way as ZodCatch.

from zod-to-json-schema.

fredrikj31 avatar fredrikj31 commented on May 23, 2024 1

When is this gonna be released @StefanTerdell ?

from zod-to-json-schema.

kachkaev avatar kachkaev commented on May 23, 2024

Great, thanks @StefanTerdell! The new version works like a charm ✨

If you have a bit of time, can you please update the list of releases?

It should help Renovate (and other similar tools) show the list changes in autogenerated PRs. It is empty at the moment:

Screenshot 2023-11-18 at 11 58 20

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.