fastify schema cannot read nested objects

124 Views Asked by At

I have the following schema

schema
{
  "response": {
    "200": {
      "type": "object",
      "properties": {
        "data": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "id": {
                "type": "string"
              },
              "created_at": {
                "type": "string"
              },
              "modified_at": {
                "type": "string"
              },
              "title": {
                "type": "string",
                "example": "unit #323",
                "description": "the org unit's title"
              },
              "parent": {
                "type": "string",
                "description": "the parent org unit",
                "nullable": true,
                "example": null
              },
              "manager": {
                "type": "object",
                "properties": {
                  "code": {
                    "type": "string",
                    "example": "code#538",
                    "description": "employer code"
                  },
                  "name": {
                    "type": "string",
                    "example": "John"
                  },
                  "status": {
                    "type": "string",
                    "nullable": true,
                    "enum": [
                      "active",
                      "inactive"
                    ]
                  },
                  "org_unit": {
                    "type": "string",
                    "nullable": true
                  }
                }
              }
            }
          }
        },
        "next": {
          "type": "string"
        },
        "prev": {
          "type": "string"
        }
      }
    }
  },
  "querystring": {
    "filter": {
      "type": "string",
      "description": "a json decoded string of fields to be filtered, or a sql where statement with query.values provided",
      "example": {
        "title": "value",
        "parent": "value",
        "manager": "value"
      }
    }
  }
}

to summarize the schema, it is something like:

{
  id,
  title,
  manager: {id, name, code, ....}
}

and the response is similar to

[
 {id, manager: {id, name, ...}
]

but I got the following error

 Cannot read properties of null (reading 'name')\n    at anonymous3 (eval at build (node_modules/fast-json-stringify/index.js:175:23),

this error disappears when I remove the property manager from the schema

0

There are 0 best solutions below