glideapps / quicktype

Generate types and converters from JSON, Schema, and GraphQL
https://app.quicktype.io
Apache License 2.0
11.93k stars 1.05k forks source link

fix: add supportsOptionalClassProperties to TypeScriptZod target language #2478

Closed inferrinizzard closed 6 months ago

inferrinizzard commented 7 months ago

Summary

Added supportsOptionalClassProperties to TypeScriptZodTargetLanguage in order to fix handling of optional properties in JSON Schema that are not listed in required array.

JSON Schema

{
  "properties": {
    "foo": { "type": "string" },           // standard string
    "bar": { "type": ["string", "null"] }, // string | null union
    "baz": { "type": "string" },           // string, optional
    "qux": { "type": ["string", "null"] }, // string | null union, optional
  },
  "required": ["foo", "bar"]
}

Old

export const Schema = z.object({
  foo: z.string(),                               // standard string
  bar: z.union(z.string(), z.null()),            // string | null union
  baz: z.union(z.string(), z.null()).optional(), // string, optional
  qux: z.union(z.string(), z.null()).optional(), // string | null union, optional
})

New


export const Schema = z.object({
  foo: z.string(),                               // standard string
  bar: z.union(z.string(), z.null()),            // string | null union
  baz: z.string().optional(),                    // string, optional
  qux: z.union(z.string(), z.null()).optional(), // string | null union, optional
})
inferrinizzard commented 7 months ago

CI Test failure looks like #2462

dvdsgl commented 7 months ago

Yes, sadly our CI is currently haunted.

inferrinizzard commented 6 months ago

@dvdsgl Are you guys looking for more maintainers? Would like to help out if there's space available

dvdsgl commented 6 months ago

Yes please!

We're getting desperate: https://replit.com/bounties/@dvdsgl/fix-our-oss-project

Want to see if you can fix CI? I'll pay you the bounty.

Adam724 commented 6 months ago

Hello. I believe this PR should fix #2462. The failing tests are now passing locally for me on that branch.

inferrinizzard commented 6 months ago

@dvdsgl great to hear that the CI issue has finally been fixed - is there a link to the maintainer slack (or is that defunct?) Would like to chat to some folks to see which areas of the codebase need more effort before jumping on fixing more issues.

dvdsgl commented 6 months ago

We don't have a discourse or slack anymore, but we could make a WhatsApp thingy for now: https://chat.whatsapp.com/E3Heqe9Tjl8IBVqpeFMyPp