xddq / schema2typebox

Creating TypeBox code from JSON schemas
MIT License
66 stars 15 forks source link

fix: add support for unions containing arrays or objects #44

Closed smeijer closed 6 months ago

smeijer commented 6 months ago

Summary

This adds support for unions that have an array or object in them, like in the schema below.

Other unions like [string, null] were already supported. Unions with arrays [array, null] and objects [object, null] were not. Tests covering these new cases are included.

{
  type: "object",
  properties: {
    nullableObject: {
      type: ["object", "null"],
      properties: {
        name: { type: "string" },
      }
    },
    nullableArray: {
      type: ["array", "null"],
      items: {
        type: "string"
      },
    },
  }
});

I'm making this change, because we have schemas with nullable arrays and objects. Without this change, those schemas cannot be parsed.

Fixes #43

smeijer commented 6 months ago

I noticed a comment in another PR where the author was asked to update the changelog, so I went ahead and did that here already. Please feel free to modify whatever needs to be modified to get this merged.

xddq commented 6 months ago

Again, thanks for the PR! closed for https://github.com/xddq/schema2typebox/pull/48