mokkabonna / json-schema-merge-allof

Simplify your schema by combining allOf
98 stars 23 forks source link

In what way should the order of items in an allOf matter for descriptions? #35

Closed erunion closed 1 year ago

erunion commented 2 years ago

Should the order of the items in an allOf matter for a description property override? Seems that if a description is a lone schema in the second part of an allOf that it's ignored.

const mergeAllOf = require('json-schema-merge-allof');

console.log(
  mergeAllOf([
    {
      type: 'string',
      format: 'date-time',
      description: 'A description on the schema.',
    },
    {
      description: 'A description override in the `allOf`.',
    },
  ])
);

/* {
  type: 'string',
  format: 'date-time',
  description: 'A description on the schema.'
} */
const mergeAllOf = require('json-schema-merge-allof');
console.log(
  mergeAllOf([
    {
      description: 'A description override in the `allOf`.',
    },
    {
      type: 'string',
      format: 'date-time',
      description: 'A description on the schema.',
    },
  ])
);

/* {
  description: 'A description override in the `allOf`.',
  type: 'string',
  format: 'date-time'
} */
mokkabonna commented 2 years ago

For meta keywords like title, description, $id, $schema, default the strategy is to use the first possible value if there are conflicting ones. So the root schema is prioritized. This process possibly removes some meta information from your schema. So it's lossy. Override this by providing custom resolvers.

There is no good way to merge these values, So it picks the first one. You can override this by providing a custom resolver for the description keyword.