talyssonoc / structure

A simple schema/attributes library built on top of modern JavaScript
https://structure.js.org/
MIT License
301 stars 20 forks source link

Nested dynamics types isn't work #132

Closed gustavorodarte closed 4 years ago

gustavorodarte commented 4 years ago

When execute the code below throws the following error message. Error: "userPersonalInformation.vehicle" contains link reference "ref:local:Vehicle" which is outside of schema boundaries

The same not happen when removing the dynamic type;

const { attributes } = require('structure');

const Vehicle = attributes({
  year: {
    type: Number,
    required: true,
  },
})(class Vehicle {});

const UserPersonalInformation = attributes(
  {
    name: String,
    vehicle: 'Vehicle',
  },
  {
    dynamics: {
      Vehicle: () => Vehicle,
    },
  },
)(class UserPersonalInformation {});

const AutoRiskProfile = attributes(
  {
    userPersonalInformation: {
      type: 'UserPersonalInformation',
      required: true,
    },
  },
  {
    dynamics: {
      UserPersonalInformation: () => UserPersonalInformation,
    },
  },
)(class AutoRiskProfile {});

const autoRiskProfile = AutoRiskProfile.buildStrict({
  userPersonalInformation: new UserPersonalInformation({
    name: 'a',
    vehicle: new Vehicle({
      year: 2018,
    }),
  }),
});
talyssonoc commented 4 years ago

Hello, @gustavorodarte, I'll verify and try to fix!

talyssonoc commented 4 years ago

Hey @gustavorodarte, structure 2.0.1 was just released with a fix for the issue.