Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Duplicate dependencies are being rendered #825

Closed
jonaslagoni opened this issue Jul 28, 2022 · 0 comments
Closed

Duplicate dependencies are being rendered #825

jonaslagoni opened this issue Jul 28, 2022 · 0 comments
Labels
bug Something isn't working

Comments

@jonaslagoni
Copy link
Member

Describe the bug

Related to next branch.

If a model has duplicate dependencies i.e. two properties that both reference another model. Two dependencies will be rendered which is unintended.

Think something like this should work:

    //Filter out any duplicate dependencies
    dependencyModels = dependencyModels.filter((referenceModel) => {
      return dependencyModels.indexOf(referenceModel) === dependencyModels.lastIndexOf(referenceModel);
    });

    test('should not return duplicate dependencies', () => {
      const stringModel = new StringModel('', undefined);
      const referenceModel = new ReferenceModel('', undefined, stringModel);
      const referenceObjectPropertyModel = new ObjectPropertyModel('reference', false, referenceModel);
      const stringObjectPropertyModel = new ObjectPropertyModel('string', false, stringModel);
      const rawModel = new ObjectModel('test', undefined, {
        reference: referenceObjectPropertyModel,
        reference2: referenceObjectPropertyModel,
        string: stringObjectPropertyModel
      });
      
      const model = constrainMetaModel(mockedTypeMapping, mockedConstraints, {
        metaModel: rawModel,
        constrainedName: '',
        options: undefined
      }) as ConstrainedObjectModel;
      const dependencies = model.getNearestDependencies();
      expect(dependencies).toHaveLength(1);
      expect(dependencies[0]).toEqual(model.properties['reference'].property);
    });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant