Skip to content

.raw({ nullable: true }) being inserted in the wrong position #129

@denisdifazio

Description

@denisdifazio

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure it has not already been reported

Fastify version

3.6

Node.js version

12

Operating system

Windows

Operating system version (i.e. 20.04, 11.3, 10)

20H2

Description

fluent-json-schema version: 3.0.0

When using .raw({ nullable: true }) with a type object schema, the generated schema is wrong.

Steps to Reproduce

I created the following unit test to reproduce the bug:

import S from 'fluent-json-schema';

describe('parent', () => {
  expect(
    S.object()
      .required(['symbol', 'productType'])
      .prop('symbol', S.string())
      .prop('productType', S.string())
      .raw({ nulllable: true })
      .valueOf(),
  ).toEqual({
    $schema: 'http://json-schema.org/draft-07/schema#',
    type: 'object',
    nullable: true,
    required: ['symbol', 'productType'],
    properties: {
      symbol: {
        type: 'string',
      },
      productType: {
        type: 'string',
      },
    },
  });
});

Expected Behavior

Expected output:

{
    $schema: 'http://json-schema.org/draft-07/schema#',
    type: 'object',
    nullable: true,
    required: ['symbol', 'productType'],
    properties: {
      symbol: {
        type: 'string',
      },
      productType: {
        type: 'string',
      },
    },
}

Received:

{
    $schema: 'http://json-schema.org/draft-07/schema#',
    type: 'object',
    required: ['symbol', 'productType'],
    properties: {
      symbol: {
        type: 'string',
      },
      productType: {
        nullable: true, // nullable is being inserted here
        type: 'string',
      },
    },
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions