fluent-json-schema icon indicating copy to clipboard operation
fluent-json-schema copied to clipboard

Support JSON Schema 2019-09 deprecated value

Open DamienGarrido opened this issue 4 years ago • 4 comments

Prerequisites

  • [X] I have written a descriptive issue title
  • [X] I have searched existing issues to ensure the feature has not already been requested

🚀 Feature Proposal

Add support to deprecated values as stated in the JSON Schema 2019-09 paragraph.

Motivation

Be able to deprecate properties without raw().

Example

S.object().prop('myDeprecatedProperty', S.string()).deprecated();

Current workaround:

S.object().prop('myDeprecatedProperty', S.string()).raw({ deprecated: true });

DamienGarrido avatar Dec 03 '21 08:12 DamienGarrido

Would you like to send a Pull Request to address this feature? Remember to add unit tests.

Eomm avatar Dec 03 '21 14:12 Eomm

the actual syntax: S.object().prop('myDeprecatedProperty', S.string().deprecated());

aboutlo avatar Dec 03 '21 16:12 aboutlo

I tried to address it on #161 but I'm not sure about handling this property inheritance.

Should array properties with a single schema item inherit 'deprecated' property?

Which one should resolve?

expect(
    S.object()
      .prop('foo', S.string())
      .prop('bar', S
        .array()
        .items(S.number().deprecated())
      )
      .valueOf()
  ).toEqual({
    $schema: 'http://json-schema.org/draft-07/schema#',
    type: 'object',
    properties: {
      foo: { type: 'string' },
      bar: {
        type: 'array',
        deprecated: true,
        items: { type: 'number' }
      }
    },
  })

expect(
    S.object()
      .prop('foo', S.string())
      .prop('bar', S
        .array()
        .items(S.number().deprecated())
      )
      .valueOf()
  ).toEqual({
    $schema: 'http://json-schema.org/draft-07/schema#',
    type: 'object',
    properties: {
      foo: { type: 'string' },
      bar: {
        type: 'array',
        items: { type: 'number', deprecated: true, }
      }
    },
  })

Is the same valid for single property objects? Any ideas on this?

victortosts avatar Jan 12 '22 04:01 victortosts

Is the same valid for single property objects?

I think the latter is right and the former is not: items may contain an array and you may want to deprecate just one type.

Eomm avatar Jan 14 '22 17:01 Eomm