inkandswitch / cambria-project

Schema evolution with bi-directional lenses.
MIT License
592 stars 24 forks source link

Issue importing doc #4

Open podviaznikov opened 3 years ago

podviaznikov commented 3 years ago

When I import doc which has two array items (with a property that has null) all works fine:

const importedDoc = cambria.importDoc({
        items: [
                { name: 'Peter Johnson', nationality: null },
                // { name: 'Ashley Appleseed', nationality: null },
                { name: 'John Doe', nationality: null }
              ]
    })

but if I have 3 items in the array:

const importedDoc = cambria.importDoc({
        items: [
                { name: 'Peter Johnson', nationality: null },
                { name: 'Ashley Appleseed', nationality: null },
                { name: 'John Doe', nationality: null }
              ]
    })

it fails with error:

(node:21691) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'type' of null
    at Object.mergeSchemaObjs (.../node_modules/to-json-schema/lib/helpers.js:40:19)
    at .../node_modules/to-json-schema/lib/index.js:93:24
    at Array.reduce (<anonymous>)
    at ToJsonSchema.getCommonArrayItemSchema (...node_modules/to-json-schema/lib/index.js:92:22)

Node version: v12.18.3

scott-wyatt commented 3 years ago

Bumping above ^^^

I created a Runkit snippet where the same thing happens.

https://runkit.com/embed/p5i1i5yqo6fr

It's related to the postProcessFnc in importDoc

geoffturk commented 1 year ago
image

Comment out line 20 in src/docs.ts and recompile (yarn build) and it works.

michielbdejong commented 1 month ago

I was able to reproduce both the problem and the mitigation. I'm not sure what that line does though, nor what the side-effects of removing it would be.