Skip to content

schemaForm.merge regression in 1.0.0-alpha.5 #891

Closed
@donalmurtagh

Description

@donalmurtagh

I recently upgraded from 0.8.13 to the latest 1.0.0-alpha.5. In my app, I programmatically merge the form and schema definitions by calling the following function, which serves as a simple facade for
schemaForm.merge

    function mergeFormAndSchema(form, schema) {
      return schemaForm.merge(schema, form, {}, {}, undefined, []);
    }

I have some Jasmine tests of this function, which fail since upgrading from 0.8.13 to the latest alpha

Test 1

  it('should merge form and schema', function () {

    var form = [
      {
        key: 'foo',
        title: 'bar',
        type: 'xyz'
      },
      {
        key: 'noschema'
      }
    ];

    var schema = {
      type: 'object',
      properties: {
        foo: {
          type: 'string'
        }
      },
      required: ['foo']
    };

    var result = schemaFormHelperService.mergeFormAndSchema(form, schema);

    expect(result[0].key).toEqual(['foo']);
    expect(result[0].required).toEqual(true);  // FAIL
    expect(result[0].type).toEqual('xyz');
    expect(result[0].schema.type).toEqual('string'); // FAIL

    expect(result[1].key).toEqual(['noschema']);
  });

I've marked the lines that fail with // FAIL but ultimately the reason for the failure is simply because each object in result has less data in the latest alpha than in 0.8.13

result in 0.8.13

[
  {
    "key": [
      "foo"
    ],
    "title": "bar",
    "type": "xyz",
    "required": true,
    "schema": {
      "type": "string"
    },
    "ngModelOptions": {}
  },
  {
    "key": [
      "noschema"
    ]
  }
]

result in 1.0.0-alpha.5

[
  {
    "key": [
      "foo"
    ],
    "title": "bar",
    "type": "xyz"
  },
  {
    "key": [
      "noschema"
    ]
  }
] 

Test 2

  it('should traverse basic form', function () {

    var form = ['*'];
    var schema = {
      type: 'object',
      properties: {
        foo: {
          type: 'string'
        },
        bar: {
          type: 'object',
          properties: {
            child: {
              type: 'number'
            }
          }
        }
      },
      required: ['foo']
    };
    var mergedForm = schemaFormHelperService.mergeFormAndSchema(form, schema);
    expect(mergedForm.length).toEqual(2); // FAIL
  });

In the latest 1.0.0-alpha.5, mergedForm is an empty list, whereas in 0.8.13 it is

[
  {
    "title": "foo",
    "required": true,
    "schema": {
      "type": "string"
    },
    "ngModelOptions": {},
    "key": [
      "foo"
    ],
    "type": "text"
  },
  {
    "title": "bar",
    "schema": {
      "type": "object",
      "properties": {
        "child": {
          "type": "number"
        }
      }
    },
    "ngModelOptions": {},
    "type": "fieldset",
    "items": [
      {
        "title": "child",
        "schema": {
          "type": "number"
        },
        "ngModelOptions": {},
        "key": [
          "bar",
          "child"
        ],
        "type": "number"
      }
    ]
  }
]

Is it the case that

  • this is a bug in 1.0.0-alpha.5
  • the contract (arguments) of schemaForm.merge has changed in 1.0.0-alpha.5, and I need to call it differently in order to get the same results as in version 0.8.3
  • schemaForm.merge was not intended to be used outside of ASF (and therefore no attempt is made to maintain backwards compatability)

@json-schema-form/angular-schema-form-lead

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions