genson-js icon indicating copy to clipboard operation
genson-js copied to clipboard

Only schema for top level keys generated

Open johnfrancisgit opened this issue 1 year ago • 1 comments

Is it correct that this only creates the schema from top level keys? E.g

{
  extra: {
    point: {
      value: null,
      name: 'Bob',
    },
  },
}

has schema:

{
  type: 'object',
  properties: {
    extra: { type: 'object', properties: [Object], required: [Array] }
  },
  required: [ 'extra' ]
}

Is it possible to also generate populate the schema for nested fields point, value, name?

johnfrancisgit avatar Nov 26 '23 18:11 johnfrancisgit

@johnfrancisgit Are you doing a console log here? There is a limit to the depth that console.log will output. That [Object] and [Array] is a giveaway that there's more data you're not seeing.

The util.inspect method can be used in conjunction with console.log() for this kind of thing.

Try this to see the full object (assuming a variable called schema that contains your schema):

const { inspect } = require('util');

console.log(inspect(schema, false, 10, true));

10 is the depth you want to expand in the object you're inspecting, adjust as needed.

sbarre avatar Feb 09 '24 14:02 sbarre