Repository: asyncapi/modelina
Pull request #758 (2022-05-24 03:30:03)

refactor: add object property model 
**Description**

Two issues I want to solve with this change:
1. In the presets, you need access to the original, non-constrained property, for serialization functionality, and that is not possible with the current setup.
2. Keep it consistent, as we already have the same setup for `EnumValueModel` and `TupleValueModel`.


sonarcloud[bot]: Kudos, SonarCloud Quality Gate passed!&nbsp; &nbsp; [![Quality Gate passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/passed-16px.png 'Quality Gate passed')](https://sonarcloud.io/dashboard?id=asyncapi_generator-model-sdk&pullRequest=758)

[![Bug](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/bug-16px.png 'Bug')](https://sonarcloud.io/project/issues?id=asyncapi_generator-model-sdk&pullRequest=758&resolved=false&types=BUG) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=asyncapi_generator-model-sdk&pullRequest=758&resolved=false&types=BUG) [0 Bugs](https://sonarcloud.io/project/issues?id=asyncapi_generator-model-sdk&pullRequest=758&resolved=false&types=BUG)  
[![Vulnerability](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/vulnerability-16px.png 'Vulnerability')](https://sonarcloud.io/project/issues?id=asyncapi_generator-model-sdk&pullRequest=758&resolved=false&types=VULNERABILITY) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=asyncapi_generator-model-sdk&pullRequest=758&resolved=false&types=VULNERABILITY) [0 Vulnerabilities](https://sonarcloud.io/project/issues?id=asyncapi_generator-model-sdk&pullRequest=758&resolved=false&types=VULNERABILITY)  
[![Security Hotspot](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/security_hotspot-16px.png 'Security Hotspot')](https://sonarcloud.io/project/security_hotspots?id=asyncapi_generator-model-sdk&pullRequest=758&resolved=false&types=SECURITY_HOTSPOT) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/security_hotspots?id=asyncapi_generator-model-sdk&pullRequest=758&resolved=false&types=SECURITY_HOTSPOT) [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=asyncapi_generator-model-sdk&pullRequest=758&resolved=false&types=SECURITY_HOTSPOT)  
[![Code Smell](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/code_smell-16px.png 'Code Smell')](https://sonarcloud.io/project/issues?id=asyncapi_generator-model-sdk&pullRequest=758&resolved=false&types=CODE_SMELL) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=asyncapi_generator-model-sdk&pullRequest=758&resolved=false&types=CODE_SMELL) [0 Code Smells](https://sonarcloud.io/project/issues?id=asyncapi_generator-model-sdk&pullRequest=758&resolved=false&types=CODE_SMELL)

[![No Coverage information](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/CoverageChart/NoCoverageInfo-16px.png 'No Coverage information')](https://sonarcloud.io/component_measures?id=asyncapi_generator-model-sdk&pullRequest=758) No Coverage information  
[![No Duplication information](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/Duplications/NoDuplicationInfo-16px.png 'No Duplication information')](https://sonarcloud.io/component_measures?id=asyncapi_generator-model-sdk&pullRequest=758&metric=duplicated_lines_density&view=list) No Duplication information



Patch:
diff --git a/src/generators/csharp/constrainer/PropertyKeyConstrainer.ts b/src/generators/csharp/constrainer/PropertyKeyConstrainer.ts
index a2a324ce..3ce5efc7 100644
--- a/src/generators/csharp/constrainer/PropertyKeyConstrainer.ts
+++ b/src/generators/csharp/constrainer/PropertyKeyConstrainer.ts
@@ -30,8 +30,8 @@ export const DefaultPropertyKeyConstraints: PropertyKeyConstraintOptions = {
 export function defaultPropertyKeyConstraints(customConstraints?: Partial<PropertyKeyConstraintOptions>): PropertyKeyConstraint {
   const constraints = {...DefaultPropertyKeyConstraints, ...customConstraints};
 
-  return ({propertyKey, constrainedObjectModel, objectModel}) => {
-    let constrainedPropertyKey = propertyKey;
+  return ({objectPropertyModel, constrainedObjectModel, objectModel}) => {
+    let constrainedPropertyKey = objectPropertyModel.propertyName;
 
     constrainedPropertyKey = constraints.NO_SPECIAL_CHAR(constrainedPropertyKey);
     constrainedPropertyKey = constraints.NO_NUMBER_START_CHAR(constrainedPropertyKey);
diff --git a/src/generators/go/constrainer/PropertyKeyConstrainer.ts b/src/generators/go/constrainer/PropertyKeyConstrainer.ts
index bc2b32df..d750e78d 100644
--- a/src/generators/go/constrainer/PropertyKeyConstrainer.ts
+++ b/src/generators/go/constrainer/PropertyKeyConstrainer.ts
@@ -30,8 +30,8 @@ export const DefaultPropertyKeyConstraints: PropertyKeyConstraintOptions = {
 export function defaultPropertyKeyConstraints(customConstraints?: Partial<PropertyKeyConstraintOptions>): PropertyKeyConstraint {
   const constraints = {...DefaultPropertyKeyConstraints, ...customConstraints};
 
-  return ({propertyKey, constrainedObjectModel, objectModel}) => {
-    let constrainedPropertyKey = propertyKey;
+  return ({objectPropertyModel, constrainedObjectModel, objectModel}) => {
+    let constrainedPropertyKey = objectPropertyModel.propertyName;
 
     constrainedPropertyKey = constraints.NO_SPECIAL_CHAR(constrainedPropertyKey);
     constrainedPropertyKey = constraints.NO_NUMBER_START_CHAR(constrainedPropertyKey);
diff --git a/src/generators/java/constrainer/PropertyKeyConstrainer.ts b/src/generators/java/constrainer/PropertyKeyConstrainer.ts
index fd1cd24e..31618707 100644
--- a/src/generators/java/constrainer/PropertyKeyConstrainer.ts
+++ b/src/generators/java/constrainer/PropertyKeyConstrainer.ts
@@ -30,8 +30,8 @@ export const DefaultPropertyKeyConstraints: PropertyKeyConstraintOptions = {
 export function defaultPropertyKeyConstraints(customConstraints?: Partial<PropertyKeyConstraintOptions>): PropertyKeyConstraint {
   const constraints = {...DefaultPropertyKeyConstraints, ...customConstraints};
 
-  return ({propertyKey, constrainedObjectModel, objectModel}) => {
-    let constrainedPropertyKey = propertyKey;
+  return ({objectPropertyModel, constrainedObjectModel, objectModel}) => {
+    let constrainedPropertyKey = objectPropertyModel.propertyName;
 
     constrainedPropertyKey = constraints.NO_SPECIAL_CHAR(constrainedPropertyKey);
     constrainedPropertyKey = constraints.NO_NUMBER_START_CHAR(constrainedPropertyKey);
diff --git a/src/generators/javascript/constrainer/PropertyKeyConstrainer.ts b/src/generators/javascript/constrainer/PropertyKeyConstrainer.ts
index 95640786..19e124dc 100644
--- a/src/generators/javascript/constrainer/PropertyKeyConstrainer.ts
+++ b/src/generators/javascript/constrainer/PropertyKeyConstrainer.ts
@@ -30,8 +30,8 @@ export const DefaultPropertyKeyConstraints: PropertyKeyConstraintOptions = {
 export function defaultPropertyKeyConstraints(customConstraints?: Partial<PropertyKeyConstraintOptions>): PropertyKeyConstraint {
   const constraints = {...DefaultPropertyKeyConstraints, ...customConstraints};
 
-  return ({propertyKey, constrainedObjectModel, objectModel}) => {
-    let constrainedPropertyKey = propertyKey;
+  return ({objectPropertyModel, constrainedObjectModel, objectModel}) => {
+    let constrainedPropertyKey = objectPropertyModel.propertyName;
 
     constrainedPropertyKey = constraints.NO_SPECIAL_CHAR(constrainedPropertyKey);
     constrainedPropertyKey = constraints.NO_NUMBER_START_CHAR(constrainedPropertyKey);
diff --git a/src/generators/typescript/constrainer/PropertyKeyConstrainer.ts b/src/generators/typescript/constrainer/PropertyKeyConstrainer.ts
index 4fe673b2..994a97f6 100644
--- a/src/generators/typescript/constrainer/PropertyKeyConstrainer.ts
+++ b/src/generators/typescript/constrainer/PropertyKeyConstrainer.ts
@@ -29,8 +29,8 @@ export const DefaultPropertyKeyConstraints: PropertyKeyConstraintOptions = {
 export function defaultPropertyKeyConstraints(customConstraints?: Partial<PropertyKeyConstraintOptions>): PropertyKeyConstraint {
   const constraints = {...DefaultPropertyKeyConstraints, ...customConstraints};
 
-  return ({propertyKey, constrainedObjectModel, objectModel}) => {
-    let constrainedPropertyKey = propertyKey;
+  return ({objectPropertyModel, constrainedObjectModel, objectModel}) => {
+    let constrainedPropertyKey = objectPropertyModel.propertyName;
 
     constrainedPropertyKey = constraints.NO_SPECIAL_CHAR(constrainedPropertyKey);
     constrainedPropertyKey = constraints.NO_NUMBER_START_CHAR(constrainedPropertyKey);
diff --git a/src/helpers/CommonModelToMetaModel.ts b/src/helpers/CommonModelToMetaModel.ts
index 1bf196e1..241a0adf 100644
--- a/src/helpers/CommonModelToMetaModel.ts
+++ b/src/helpers/CommonModelToMetaModel.ts
@@ -1,5 +1,5 @@
 
-import { CommonModel, MetaModel, UnionModel, ObjectModel, DictionaryModel, StringModel, TupleModel, TupleValueModel, ArrayModel, BooleanModel, IntegerModel, FloatModel, EnumModel, EnumValueModel} from '../models';
+import { CommonModel, MetaModel, UnionModel, ObjectModel, DictionaryModel, StringModel, TupleModel, TupleValueModel, ArrayModel, BooleanModel, IntegerModel, FloatModel, EnumModel, EnumValueModel, ObjectPropertyModel} from '../models';
 
 export function convertToMetaModel(jsonSchemaModel: CommonModel): MetaModel {
   const modelName = jsonSchemaModel.$id || 'undefined';
@@ -123,7 +123,9 @@ export function convertToObjectModel(jsonSchemaModel: CommonModel, name: string)
   }
   const metaModel = new ObjectModel(name, jsonSchemaModel.originalInput, {});
   for (const [propertyName, prop] of Object.entries(jsonSchemaModel.properties || {})) {
-    metaModel.properties[String(propertyName)] = convertToMetaModel(prop);
+    const isRequired = jsonSchemaModel.isRequired(propertyName);
+    const propertyModel = new ObjectPropertyModel(propertyName, isRequired, convertToMetaModel(prop));
+    metaModel.properties[String(propertyName)] = propertyModel;
   }
 
   if (jsonSchemaModel.additionalProperties !== undefined) {
@@ -132,7 +134,8 @@ export function convertToObjectModel(jsonSchemaModel: CommonModel, name: string)
       const keyModel = new StringModel(propertyName, jsonSchemaModel.additionalProperties.originalInput);
       const valueModel = convertToMetaModel(jsonSchemaModel.additionalProperties);
       const dictionaryModel = new DictionaryModel(propertyName, jsonSchemaModel.additionalProperties.originalInput, keyModel, valueModel, 'unwrap');
-      metaModel.properties[String(propertyName)] = dictionaryModel;
+      const propertyModel = new ObjectPropertyModel(propertyName, false, dictionaryModel);
+      metaModel.properties[String(propertyName)] = propertyModel;
     } else {
       throw new Error('Property already exists');
     }
@@ -145,7 +148,8 @@ export function convertToObjectModel(jsonSchemaModel: CommonModel, name: string)
         const keyModel = new StringModel(propertyName, pattern);
         const valueModel = convertToMetaModel(patternModel);
         const dictionaryModel = new DictionaryModel(propertyName, patternModel.originalInput, keyModel, valueModel, 'unwrap');
-        metaModel.properties[String(propertyName)] = dictionaryModel;
+        const propertyModel = new ObjectPropertyModel(propertyName, false, dictionaryModel);
+        metaModel.properties[String(propertyName)] = propertyModel;
       } else {
         throw new Error('Property already exists');
       }
diff --git a/src/helpers/ConstrainHelpers.ts b/src/helpers/ConstrainHelpers.ts
index a456ab39..005508ce 100644
--- a/src/helpers/ConstrainHelpers.ts
+++ b/src/helpers/ConstrainHelpers.ts
@@ -1,6 +1,6 @@
 import { AbstractRenderer } from '../generators';
-import { ConstrainedAnyModel, ConstrainedBooleanModel, ConstrainedFloatModel, ConstrainedIntegerModel, ConstrainedMetaModel, ConstrainedObjectModel, ConstrainedReferenceModel, ConstrainedStringModel, ConstrainedTupleModel, ConstrainedTupleValueModel, ConstrainedArrayModel, ConstrainedUnionModel, ConstrainedEnumModel, ConstrainedDictionaryModel, ConstrainedEnumValueModel } from '../models/ConstrainedMetaModel';
-import { AnyModel, BooleanModel, FloatModel, IntegerModel, ObjectModel, ReferenceModel, StringModel, TupleModel, ArrayModel, UnionModel, EnumModel, DictionaryModel, MetaModel } from '../models/MetaModel';
+import { ConstrainedAnyModel, ConstrainedBooleanModel, ConstrainedFloatModel, ConstrainedIntegerModel, ConstrainedMetaModel, ConstrainedObjectModel, ConstrainedReferenceModel, ConstrainedStringModel, ConstrainedTupleModel, ConstrainedTupleValueModel, ConstrainedArrayModel, ConstrainedUnionModel, ConstrainedEnumModel, ConstrainedDictionaryModel, ConstrainedEnumValueModel, ConstrainedObjectPropertyModel } from '../models/ConstrainedMetaModel';
+import { AnyModel, BooleanModel, FloatModel, IntegerModel, ObjectModel, ReferenceModel, StringModel, TupleModel, ArrayModel, UnionModel, EnumModel, DictionaryModel, MetaModel, ObjectPropertyModel } from '../models/MetaModel';
 import { getTypeFromMapping, TypeMapping } from './TypeHelpers';
 
 export type ConstrainContext<R extends AbstractRenderer, M extends MetaModel> = {
@@ -30,7 +30,8 @@ export type ModelNameContext = {
 export type ModelNameConstraint = (context: ModelNameContext) => string;
 
 export type PropertyKeyContext = {
-  propertyKey: string,
+  constrainedObjectPropertyModel: ConstrainedObjectPropertyModel,
+  objectPropertyModel: ObjectPropertyModel,
   constrainedObjectModel: ConstrainedObjectModel,
   objectModel: ObjectModel
 }
@@ -148,10 +149,13 @@ function constrainDictionaryModel<R extends AbstractRenderer>(typeMapping: TypeM
 
 function constrainObjectModel<R extends AbstractRenderer>(typeMapping: TypeMapping<R>, constrainRules: Constraints, context: ConstrainContext<R, ObjectModel>): ConstrainedObjectModel {
   const constrainedModel = new ConstrainedObjectModel(context.constrainedName, context.metaModel.originalInput, '', {});
-  for (const [propertyKey, propertyMetaModel] of Object.entries(context.metaModel.properties)) {
-    const constrainedPropertyName = constrainRules.propertyKey({propertyKey, constrainedObjectModel: constrainedModel, objectModel: context.metaModel});
-    const constrainedProperty = constrainMetaModel(typeMapping, constrainRules, {...context, metaModel: propertyMetaModel, propertyKey: constrainedPropertyName});
-    constrainedModel.properties[String(constrainedPropertyName)] = constrainedProperty;
+  for (const propertyMetaModel of Object.values(context.metaModel.properties)) {
+    const constrainedPropertyModel = new ConstrainedObjectPropertyModel('', propertyMetaModel.required, constrainedModel);
+    const constrainedPropertyName = constrainRules.propertyKey({objectPropertyModel: propertyMetaModel, constrainedObjectPropertyModel: constrainedPropertyModel, constrainedObjectModel: constrainedModel, objectModel: context.metaModel});
+    constrainedPropertyModel.propertyName = constrainedPropertyName;
+    const constrainedProperty = constrainMetaModel(typeMapping, constrainRules, {...context, metaModel: context.metaModel, propertyKey: constrainedPropertyName});
+    constrainedPropertyModel.property = constrainedProperty;
+    constrainedModel.properties[String(constrainedPropertyName)] = constrainedPropertyModel;
   }
   constrainedModel.type = getTypeFromMapping(typeMapping, {
     constrainedModel,
diff --git a/src/helpers/Splitter.ts b/src/helpers/Splitter.ts
index 16f0b0cf..5bf456c0 100644
--- a/src/helpers/Splitter.ts
+++ b/src/helpers/Splitter.ts
@@ -51,8 +51,8 @@ const trySplitModel = (model: MetaModel, options: SplitOptions, models: MetaMode
 export const split = (model: MetaModel, options: SplitOptions, models: MetaModel[] = [model]): MetaModel[] => {
   if (model instanceof ObjectModel) {
     for (const [prop, propModel] of Object.entries(model.properties)) {
-      model.properties[String(prop)] = trySplitModel(propModel, options, models);
-      split(propModel, options, models);
+      model.properties[String(prop)].property = trySplitModel(propModel.property, options, models);
+      split(propModel.property, options, models);
     }
   } else if (model instanceof UnionModel) {
     for (let index = 0; index < model.union.length; index++) {
diff --git a/src/models/ConstrainedMetaModel.ts b/src/models/ConstrainedMetaModel.ts
index 5a138f67..8b0ee4fe 100644
--- a/src/models/ConstrainedMetaModel.ts
+++ b/src/models/ConstrainedMetaModel.ts
@@ -38,12 +38,19 @@ export class ConstrainedTupleModel extends ConstrainedMetaModel {
     super(name, originalInput, type);
   }
 }
+export class ConstrainedObjectPropertyModel {
+  constructor(
+    public propertyName: string,
+    public required: boolean,
+    public property: ConstrainedMetaModel) {
+  }
+}
 export class ConstrainedObjectModel extends ConstrainedMetaModel {
   constructor(
     name: string,
     originalInput: any, 
     type: string, 
-    public properties: { [key: string]: ConstrainedMetaModel; }) {
+    public properties: { [key: string]: ConstrainedObjectPropertyModel; }) {
     super(name, originalInput, type);
   }
 }
diff --git a/src/models/MetaModel.ts b/src/models/MetaModel.ts
index acc8b5cb..dd40726b 100644
--- a/src/models/MetaModel.ts
+++ b/src/models/MetaModel.ts
@@ -32,11 +32,18 @@ export class TupleModel extends MetaModel {
     super(name, originalInput);
   }
 }
+export class ObjectPropertyModel {
+  constructor(
+    public propertyName: string,
+    public required: boolean,
+    public property: MetaModel) {
+  }
+}
 export class ObjectModel extends MetaModel {
   constructor(
     name: string,
     originalInput: any,
-    public properties: { [key: string]: MetaModel; }) {
+    public properties: { [key: string]: ObjectPropertyModel; }) {
     super(name, originalInput);
   }
 }


Test patch:
diff --git a/test/generators/csharp/constrainer/PropertyKeyConstrainer.spec.ts b/test/generators/csharp/constrainer/PropertyKeyConstrainer.spec.ts
index 90350e6e..bc994429 100644
--- a/test/generators/csharp/constrainer/PropertyKeyConstrainer.spec.ts
+++ b/test/generators/csharp/constrainer/PropertyKeyConstrainer.spec.ts
@@ -1,35 +1,43 @@
 import { CSharpDefaultConstraints } from '../../../../src/generators/csharp/CSharpConstrainer';
-import { ConstrainedObjectModel, ObjectModel } from '../../../../src';
+import { ConstrainedObjectModel, ConstrainedObjectPropertyModel, ObjectModel, ObjectPropertyModel } from '../../../../src';
 import { DefaultPropertyKeyConstraints, defaultPropertyKeyConstraints, PropertyKeyConstraintOptions } from '../../../../src/generators/csharp/constrainer/PropertyKeyConstrainer';
 describe('PropertyKeyConstrainer', () => {
   const objectModel = new ObjectModel('test', undefined, {});
   const constrainedObjectModel = new ConstrainedObjectModel('test', undefined, '', {});
 
+  const constrainPropertyName = (propertyName: string) => {
+    const objectPropertyModel = new ObjectPropertyModel(propertyName, false, objectModel);
+    const constrainedObjectPropertyModel = new ConstrainedObjectPropertyModel('', objectPropertyModel.required, constrainedObjectModel);
+    return CSharpDefaultConstraints.propertyKey({constrainedObjectModel, objectModel, objectPropertyModel, constrainedObjectPropertyModel });
+  };
+
   test('should never render special chars', () => {
-    const constrainedKey = CSharpDefaultConstraints.propertyKey({constrainedObjectModel, objectModel, propertyKey: '%'});
+    const constrainedKey = constrainPropertyName('%');
     expect(constrainedKey).toEqual('Percent');
   });
   test('should not render number as start char', () => {
-    const constrainedKey = CSharpDefaultConstraints.propertyKey({constrainedObjectModel, objectModel, propertyKey: '1'});
+    const constrainedKey = constrainPropertyName('1');
     expect(constrainedKey).toEqual('Number_1');
   });
   test('should never contain empty name', () => {
-    const constrainedKey = CSharpDefaultConstraints.propertyKey({constrainedObjectModel, objectModel, propertyKey: ''});
+    const constrainedKey = constrainPropertyName('');
     expect(constrainedKey).toEqual('Empty');
   });
   test('should use constant naming format', () => {
-    const constrainedKey = CSharpDefaultConstraints.propertyKey({constrainedObjectModel, objectModel, propertyKey: 'some weird_value!"#2'});
+    const constrainedKey = constrainPropertyName('some weird_value!"#2');
     expect(constrainedKey).toEqual('SomeWeirdValueExclamationQuotationHash_2');
   });
   test('should not contain duplicate properties', () => {
     const objectModel = new ObjectModel('test', undefined, {});
-    const propertyModel = new ConstrainedObjectModel('SomeProperty', undefined, '', {});
-    const constrainedObjectModel = new ConstrainedObjectModel('test', undefined, '', {SomeProperty: propertyModel});
-    const constrainedKey = CSharpDefaultConstraints.propertyKey({constrainedObjectModel, objectModel, propertyKey: 'SomeProperty'});
+    const constrainedObjectModel = new ConstrainedObjectModel('test', undefined, '', {});
+    const objectPropertyModel = new ObjectPropertyModel('SomeProperty', false, objectModel);
+    const constrainedObjectPropertyModel = new ConstrainedObjectPropertyModel('SomeProperty', objectPropertyModel.required, constrainedObjectModel);
+    constrainedObjectModel.properties['SomeProperty'] = constrainedObjectPropertyModel;
+    const constrainedKey = CSharpDefaultConstraints.propertyKey({constrainedObjectModel, objectModel, objectPropertyModel, constrainedObjectPropertyModel});
     expect(constrainedKey).toEqual('ReservedSomeProperty');
   });
   test('should never render reserved keywords', () => {
-    const constrainedKey = CSharpDefaultConstraints.propertyKey({constrainedObjectModel, objectModel, propertyKey: 'return'});
+    const constrainedKey = constrainPropertyName('return');
     expect(constrainedKey).toEqual('ReservedReturn');
   });
   describe('custom constraints', () => {
@@ -43,7 +51,9 @@ describe('PropertyKeyConstrainer', () => {
         NO_DUPLICATE_PROPERTIES: jest.fn().mockReturnValue('')
       };
       const constrainFunction = defaultPropertyKeyConstraints(mockedConstraintCallbacks);
-      constrainFunction({constrainedObjectModel, objectModel, propertyKey: ''});
+      const objectPropertyModel = new ObjectPropertyModel('', false, objectModel);
+      const constrainedObjectPropertyModel = new ConstrainedObjectPropertyModel('', objectPropertyModel.required, constrainedObjectModel);
+      constrainFunction({constrainedObjectModel, objectModel, objectPropertyModel, constrainedObjectPropertyModel});
       //Expect all callbacks to be called
       for (const jestMockCallback of Object.values(mockedConstraintCallbacks)) {
         expect(jestMockCallback).toHaveBeenCalled();
@@ -60,7 +70,9 @@ describe('PropertyKeyConstrainer', () => {
       ];
       const jestCallback = jest.fn().mockReturnValue('');
       const constrainFunction = defaultPropertyKeyConstraints({NAMING_FORMATTER: jestCallback});
-      const constrainedValue = constrainFunction({constrainedObjectModel, objectModel, propertyKey: ''});
+      const objectPropertyModel = new ObjectPropertyModel('', false, objectModel);
+      const constrainedObjectPropertyModel = new ConstrainedObjectPropertyModel('', objectPropertyModel.required, constrainedObjectModel);
+      const constrainedValue = constrainFunction({constrainedObjectModel, objectModel, objectPropertyModel, constrainedObjectPropertyModel});
       expect(constrainedValue).toEqual('');
       for (const jestMockCallback of spies) {
         expect(jestMockCallback).toHaveBeenCalled();
diff --git a/test/generators/go/constrainer/PropertyKeyConstrainer.spec.ts b/test/generators/go/constrainer/PropertyKeyConstrainer.spec.ts
index 756cdbcb..561720b8 100644
--- a/test/generators/go/constrainer/PropertyKeyConstrainer.spec.ts
+++ b/test/generators/go/constrainer/PropertyKeyConstrainer.spec.ts
@@ -1,35 +1,43 @@
 import { GoDefaultConstraints } from '../../../../src/generators/go/GoConstrainer';
-import { ConstrainedObjectModel, ObjectModel } from '../../../../src';
+import { ConstrainedObjectModel, ConstrainedObjectPropertyModel, ObjectModel, ObjectPropertyModel } from '../../../../src';
 import { DefaultPropertyKeyConstraints, defaultPropertyKeyConstraints, PropertyKeyConstraintOptions } from '../../../../src/generators/go/constrainer/PropertyKeyConstrainer';
 describe('PropertyKeyConstrainer', () => {
   const objectModel = new ObjectModel('test', undefined, {});
   const constrainedObjectModel = new ConstrainedObjectModel('test', undefined, '', {});
 
+  const constrainPropertyName = (propertyName: string) => {
+    const objectPropertyModel = new ObjectPropertyModel(propertyName, false, objectModel);
+    const constrainedObjectPropertyModel = new ConstrainedObjectPropertyModel('', objectPropertyModel.required, constrainedObjectModel);
+    return GoDefaultConstraints.propertyKey({constrainedObjectModel, objectModel, objectPropertyModel, constrainedObjectPropertyModel });
+  };
+
   test('should never render special chars', () => {
-    const constrainedKey = GoDefaultConstraints.propertyKey({constrainedObjectModel, objectModel, propertyKey: '%'});
+    const constrainedKey = constrainPropertyName('%');
     expect(constrainedKey).toEqual('Percent');
   });
   test('should not render number as start char', () => {
-    const constrainedKey = GoDefaultConstraints.propertyKey({constrainedObjectModel, objectModel, propertyKey: '1'});
+    const constrainedKey = constrainPropertyName('1');
     expect(constrainedKey).toEqual('Number_1');
   });
   test('should never contain empty name', () => {
-    const constrainedKey = GoDefaultConstraints.propertyKey({constrainedObjectModel, objectModel, propertyKey: ''});
+    const constrainedKey = constrainPropertyName('');
     expect(constrainedKey).toEqual('Empty');
   });
   test('should use constant naming format', () => {
-    const constrainedKey = GoDefaultConstraints.propertyKey({constrainedObjectModel, objectModel, propertyKey: 'some weird_value!"#2'});
+    const constrainedKey = constrainPropertyName('some weird_value!"#2');
     expect(constrainedKey).toEqual('SomeWeirdValueExclamationQuotationHash_2');
   });
   test('should not contain duplicate properties', () => {
     const objectModel = new ObjectModel('test', undefined, {});
-    const propertyModel = new ConstrainedObjectModel('SomeProperty', undefined, '', {});
-    const constrainedObjectModel = new ConstrainedObjectModel('test', undefined, '', {SomeProperty: propertyModel});
-    const constrainedKey = GoDefaultConstraints.propertyKey({constrainedObjectModel, objectModel, propertyKey: 'SomeProperty'});
+    const constrainedObjectModel = new ConstrainedObjectModel('test', undefined, '', {});
+    const objectPropertyModel = new ObjectPropertyModel('SomeProperty', false, objectModel);
+    const constrainedObjectPropertyModel = new ConstrainedObjectPropertyModel('SomeProperty', objectPropertyModel.required, constrainedObjectModel);
+    constrainedObjectModel.properties['SomeProperty'] = constrainedObjectPropertyModel;
+    const constrainedKey = GoDefaultConstraints.propertyKey({constrainedObjectModel, objectModel, objectPropertyModel, constrainedObjectPropertyModel});
     expect(constrainedKey).toEqual('ReservedSomeProperty');
   });
   test('should never render reserved keywords', () => {
-    const constrainedKey = GoDefaultConstraints.propertyKey({constrainedObjectModel, objectModel, propertyKey: 'return'});
+    const constrainedKey = constrainPropertyName('return');
     expect(constrainedKey).toEqual('ReservedReturn');
   });
   describe('custom constraints', () => {
@@ -43,7 +51,9 @@ describe('PropertyKeyConstrainer', () => {
         NO_DUPLICATE_PROPERTIES: jest.fn().mockReturnValue('')
       };
       const constrainFunction = defaultPropertyKeyConstraints(mockedConstraintCallbacks);
-      constrainFunction({constrainedObjectModel, objectModel, propertyKey: ''});
+      const objectPropertyModel = new ObjectPropertyModel('', false, objectModel);
+      const constrainedObjectPropertyModel = new ConstrainedObjectPropertyModel('', objectPropertyModel.required, constrainedObjectModel);
+      constrainFunction({constrainedObjectModel, objectModel, objectPropertyModel, constrainedObjectPropertyModel});
       //Expect all callbacks to be called
       for (const jestMockCallback of Object.values(mockedConstraintCallbacks)) {
         expect(jestMockCallback).toHaveBeenCalled();
@@ -60,7 +70,9 @@ describe('PropertyKeyConstrainer', () => {
       ];
       const jestCallback = jest.fn().mockReturnValue('');
       const constrainFunction = defaultPropertyKeyConstraints({NAMING_FORMATTER: jestCallback});
-      const constrainedValue = constrainFunction({constrainedObjectModel, objectModel, propertyKey: ''});
+      const objectPropertyModel = new ObjectPropertyModel('', false, objectModel);
+      const constrainedObjectPropertyModel = new ConstrainedObjectPropertyModel('', objectPropertyModel.required, constrainedObjectModel);
+      const constrainedValue = constrainFunction({constrainedObjectModel, objectModel, objectPropertyModel, constrainedObjectPropertyModel});
       expect(constrainedValue).toEqual('');
       for (const jestMockCallback of spies) {
         expect(jestMockCallback).toHaveBeenCalled();
diff --git a/test/generators/java/constrainer/PropertyKeyConstrainer.spec.ts b/test/generators/java/constrainer/PropertyKeyConstrainer.spec.ts
index c5f300cd..19a4690e 100644
--- a/test/generators/java/constrainer/PropertyKeyConstrainer.spec.ts
+++ b/test/generators/java/constrainer/PropertyKeyConstrainer.spec.ts
@@ -1,35 +1,43 @@
 import { JavaDefaultConstraints } from '../../../../src/generators/java/JavaConstrainer';
-import { ConstrainedObjectModel, ObjectModel } from '../../../../src';
+import { ConstrainedObjectModel, ConstrainedObjectPropertyModel, ObjectModel, ObjectPropertyModel } from '../../../../src';
 import { DefaultPropertyKeyConstraints, defaultPropertyKeyConstraints, PropertyKeyConstraintOptions } from '../../../../src/generators/java/constrainer/PropertyKeyConstrainer';
 describe('PropertyKeyConstrainer', () => {
   const objectModel = new ObjectModel('test', undefined, {});
   const constrainedObjectModel = new ConstrainedObjectModel('test', undefined, '', {});
 
+  const constrainPropertyName = (propertyName: string) => {
+    const objectPropertyModel = new ObjectPropertyModel(propertyName, false, objectModel);
+    const constrainedObjectPropertyModel = new ConstrainedObjectPropertyModel('', objectPropertyModel.required, constrainedObjectModel);
+    return JavaDefaultConstraints.propertyKey({constrainedObjectModel, objectModel, objectPropertyModel, constrainedObjectPropertyModel });
+  };
+
   test('should never render special chars', () => {
-    const constrainedKey = JavaDefaultConstraints.propertyKey({constrainedObjectModel, objectModel, propertyKey: '%'});
+    const constrainedKey = constrainPropertyName('%');
     expect(constrainedKey).toEqual('Percent');
   });
   test('should not render number as start char', () => {
-    const constrainedKey = JavaDefaultConstraints.propertyKey({constrainedObjectModel, objectModel, propertyKey: '1'});
+    const constrainedKey = constrainPropertyName('1');
     expect(constrainedKey).toEqual('Number_1');
   });
   test('should never contain empty name', () => {
-    const constrainedKey = JavaDefaultConstraints.propertyKey({constrainedObjectModel, objectModel, propertyKey: ''});
+    const constrainedKey = constrainPropertyName('');
     expect(constrainedKey).toEqual('Empty');
   });
   test('should use constant naming format', () => {
-    const constrainedKey = JavaDefaultConstraints.propertyKey({constrainedObjectModel, objectModel, propertyKey: 'some weird_value!"#2'});
+    const constrainedKey = constrainPropertyName('some weird_value!"#2');
     expect(constrainedKey).toEqual('SomeWeirdValueExclamationQuotationHash_2');
   });
   test('should not contain duplicate properties', () => {
     const objectModel = new ObjectModel('test', undefined, {});
-    const propertyModel = new ConstrainedObjectModel('SomeProperty', undefined, '', {});
-    const constrainedObjectModel = new ConstrainedObjectModel('test', undefined, '', {SomeProperty: propertyModel});
-    const constrainedKey = JavaDefaultConstraints.propertyKey({constrainedObjectModel, objectModel, propertyKey: 'SomeProperty'});
+    const constrainedObjectModel = new ConstrainedObjectModel('test', undefined, '', {});
+    const objectPropertyModel = new ObjectPropertyModel('SomeProperty', false, objectModel);
+    const constrainedObjectPropertyModel = new ConstrainedObjectPropertyModel('SomeProperty', objectPropertyModel.required, constrainedObjectModel);
+    constrainedObjectModel.properties['SomeProperty'] = constrainedObjectPropertyModel;
+    const constrainedKey = JavaDefaultConstraints.propertyKey({constrainedObjectModel, objectModel, objectPropertyModel, constrainedObjectPropertyModel});
     expect(constrainedKey).toEqual('ReservedSomeProperty');
   });
   test('should never render reserved keywords', () => {
-    const constrainedKey = JavaDefaultConstraints.propertyKey({constrainedObjectModel, objectModel, propertyKey: 'return'});
+    const constrainedKey = constrainPropertyName('return');
     expect(constrainedKey).toEqual('ReservedReturn');
   });
   describe('custom constraints', () => {
@@ -43,7 +51,9 @@ describe('PropertyKeyConstrainer', () => {
         NO_DUPLICATE_PROPERTIES: jest.fn().mockReturnValue('')
       };
       const constrainFunction = defaultPropertyKeyConstraints(mockedConstraintCallbacks);
-      constrainFunction({constrainedObjectModel, objectModel, propertyKey: ''});
+      const objectPropertyModel = new ObjectPropertyModel('', false, objectModel);
+      const constrainedObjectPropertyModel = new ConstrainedObjectPropertyModel('', objectPropertyModel.required, constrainedObjectModel);
+      constrainFunction({constrainedObjectModel, objectModel, objectPropertyModel, constrainedObjectPropertyModel});
       //Expect all callbacks to be called
       for (const jestMockCallback of Object.values(mockedConstraintCallbacks)) {
         expect(jestMockCallback).toHaveBeenCalled();
@@ -60,7 +70,9 @@ describe('PropertyKeyConstrainer', () => {
       ];
       const jestCallback = jest.fn().mockReturnValue('');
       const constrainFunction = defaultPropertyKeyConstraints({NAMING_FORMATTER: jestCallback});
-      const constrainedValue = constrainFunction({constrainedObjectModel, objectModel, propertyKey: ''});
+      const objectPropertyModel = new ObjectPropertyModel('', false, objectModel);
+      const constrainedObjectPropertyModel = new ConstrainedObjectPropertyModel('', objectPropertyModel.required, constrainedObjectModel);
+      const constrainedValue = constrainFunction({constrainedObjectModel, objectModel, objectPropertyModel, constrainedObjectPropertyModel});
       expect(constrainedValue).toEqual('');
       for (const jestMockCallback of spies) {
         expect(jestMockCallback).toHaveBeenCalled();
diff --git a/test/generators/javascript/constrainer/PropertyKeyConstrainer.spec.ts b/test/generators/javascript/constrainer/PropertyKeyConstrainer.spec.ts
index 5f0bfc62..1d66d0f3 100644
--- a/test/generators/javascript/constrainer/PropertyKeyConstrainer.spec.ts
+++ b/test/generators/javascript/constrainer/PropertyKeyConstrainer.spec.ts
@@ -1,35 +1,43 @@
 import { JavaScriptDefaultConstraints } from '../../../../src/generators/javascript/JavaScriptConstrainer';
-import { ConstrainedObjectModel, ObjectModel } from '../../../../src';
+import { ConstrainedObjectModel, ConstrainedObjectPropertyModel, ObjectModel, ObjectPropertyModel } from '../../../../src';
 import { DefaultPropertyKeyConstraints, defaultPropertyKeyConstraints, PropertyKeyConstraintOptions } from '../../../../src/generators/javascript/constrainer/PropertyKeyConstrainer';
 describe('PropertyKeyConstrainer', () => {
   const objectModel = new ObjectModel('test', undefined, {});
   const constrainedObjectModel = new ConstrainedObjectModel('test', undefined, '', {});
 
+  const constrainPropertyName = (propertyName: string) => {
+    const objectPropertyModel = new ObjectPropertyModel(propertyName, false, objectModel);
+    const constrainedObjectPropertyModel = new ConstrainedObjectPropertyModel('', objectPropertyModel.required, constrainedObjectModel);
+    return JavaScriptDefaultConstraints.propertyKey({constrainedObjectModel, objectModel, objectPropertyModel, constrainedObjectPropertyModel });
+  };
+
   test('should never render special chars', () => {
-    const constrainedKey = JavaScriptDefaultConstraints.propertyKey({constrainedObjectModel, objectModel, propertyKey: '%'});
+    const constrainedKey = constrainPropertyName('%');
     expect(constrainedKey).toEqual('Percent');
   });
   test('should not render number as start char', () => {
-    const constrainedKey = JavaScriptDefaultConstraints.propertyKey({constrainedObjectModel, objectModel, propertyKey: '1'});
+    const constrainedKey = constrainPropertyName('1');
     expect(constrainedKey).toEqual('Number_1');
   });
   test('should never contain empty name', () => {
-    const constrainedKey = JavaScriptDefaultConstraints.propertyKey({constrainedObjectModel, objectModel, propertyKey: ''});
+    const constrainedKey = constrainPropertyName('');
     expect(constrainedKey).toEqual('Empty');
   });
   test('should use constant naming format', () => {
-    const constrainedKey = JavaScriptDefaultConstraints.propertyKey({constrainedObjectModel, objectModel, propertyKey: 'some weird_value!"#2'});
+    const constrainedKey = constrainPropertyName('some weird_value!"#2');
     expect(constrainedKey).toEqual('SomeWeirdValueExclamationQuotationHash_2');
   });
   test('should not contain duplicate properties', () => {
     const objectModel = new ObjectModel('test', undefined, {});
-    const propertyModel = new ConstrainedObjectModel('SomeProperty', undefined, '', {});
-    const constrainedObjectModel = new ConstrainedObjectModel('test', undefined, '', {SomeProperty: propertyModel});
-    const constrainedKey = JavaScriptDefaultConstraints.propertyKey({constrainedObjectModel, objectModel, propertyKey: 'SomeProperty'});
+    const constrainedObjectModel = new ConstrainedObjectModel('test', undefined, '', {});
+    const objectPropertyModel = new ObjectPropertyModel('SomeProperty', false, objectModel);
+    const constrainedObjectPropertyModel = new ConstrainedObjectPropertyModel('SomeProperty', objectPropertyModel.required, constrainedObjectModel);
+    constrainedObjectModel.properties['SomeProperty'] = constrainedObjectPropertyModel;
+    const constrainedKey = JavaScriptDefaultConstraints.propertyKey({constrainedObjectModel, objectModel, objectPropertyModel, constrainedObjectPropertyModel});
     expect(constrainedKey).toEqual('ReservedSomeProperty');
   });
   test('should never render reserved keywords', () => {
-    const constrainedKey = JavaScriptDefaultConstraints.propertyKey({constrainedObjectModel, objectModel, propertyKey: 'return'});
+    const constrainedKey = constrainPropertyName('return');
     expect(constrainedKey).toEqual('ReservedReturn');
   });
   describe('custom constraints', () => {
@@ -43,7 +51,9 @@ describe('PropertyKeyConstrainer', () => {
         NO_DUPLICATE_PROPERTIES: jest.fn().mockReturnValue('')
       };
       const constrainFunction = defaultPropertyKeyConstraints(mockedConstraintCallbacks);
-      constrainFunction({constrainedObjectModel, objectModel, propertyKey: ''});
+      const objectPropertyModel = new ObjectPropertyModel('', false, objectModel);
+      const constrainedObjectPropertyModel = new ConstrainedObjectPropertyModel('', objectPropertyModel.required, constrainedObjectModel);
+      constrainFunction({constrainedObjectModel, objectModel, objectPropertyModel, constrainedObjectPropertyModel});
       //Expect all callbacks to be called
       for (const jestMockCallback of Object.values(mockedConstraintCallbacks)) {
         expect(jestMockCallback).toHaveBeenCalled();
@@ -60,7 +70,9 @@ describe('PropertyKeyConstrainer', () => {
       ];
       const jestCallback = jest.fn().mockReturnValue('');
       const constrainFunction = defaultPropertyKeyConstraints({NAMING_FORMATTER: jestCallback});
-      const constrainedValue = constrainFunction({constrainedObjectModel, objectModel, propertyKey: ''});
+      const objectPropertyModel = new ObjectPropertyModel('', false, objectModel);
+      const constrainedObjectPropertyModel = new ConstrainedObjectPropertyModel('', objectPropertyModel.required, constrainedObjectModel);
+      const constrainedValue = constrainFunction({constrainedObjectModel, objectModel, objectPropertyModel, constrainedObjectPropertyModel});
       expect(constrainedValue).toEqual('');
       for (const jestMockCallback of spies) {
         expect(jestMockCallback).toHaveBeenCalled();
diff --git a/test/generators/typescript/constrainer/PropertyKeyConstrainer.spec.ts b/test/generators/typescript/constrainer/PropertyKeyConstrainer.spec.ts
index 0ed09d38..17a0e3e8 100644
--- a/test/generators/typescript/constrainer/PropertyKeyConstrainer.spec.ts
+++ b/test/generators/typescript/constrainer/PropertyKeyConstrainer.spec.ts
@@ -1,35 +1,43 @@
 import { TypeScriptDefaultConstraints } from '../../../../src/generators/typescript/TypeScriptConstrainer';
-import { ConstrainedObjectModel, ObjectModel } from '../../../../src';
+import { ConstrainedObjectModel, ConstrainedObjectPropertyModel, ObjectModel, ObjectPropertyModel } from '../../../../src';
 import { DefaultPropertyKeyConstraints, defaultPropertyKeyConstraints, PropertyKeyConstraintOptions } from '../../../../src/generators/typescript/constrainer/PropertyKeyConstrainer';
 describe('PropertyKeyConstrainer', () => {
   const objectModel = new ObjectModel('test', undefined, {});
   const constrainedObjectModel = new ConstrainedObjectModel('test', undefined, '', {});
 
+  const constrainPropertyName = (propertyName: string) => {
+    const objectPropertyModel = new ObjectPropertyModel(propertyName, false, objectModel);
+    const constrainedObjectPropertyModel = new ConstrainedObjectPropertyModel('', objectPropertyModel.required, constrainedObjectModel);
+    return TypeScriptDefaultConstraints.propertyKey({constrainedObjectModel, objectModel, objectPropertyModel, constrainedObjectPropertyModel });
+  };
+
   test('should never render special chars', () => {
-    const constrainedKey = TypeScriptDefaultConstraints.propertyKey({constrainedObjectModel, objectModel, propertyKey: '%'});
+    const constrainedKey = constrainPropertyName('%');
     expect(constrainedKey).toEqual('Percent');
   });
   test('should not render number as start char', () => {
-    const constrainedKey = TypeScriptDefaultConstraints.propertyKey({constrainedObjectModel, objectModel, propertyKey: '1'});
+    const constrainedKey = constrainPropertyName('1');
     expect(constrainedKey).toEqual('Number_1');
   });
   test('should never contain empty name', () => {
-    const constrainedKey = TypeScriptDefaultConstraints.propertyKey({constrainedObjectModel, objectModel, propertyKey: ''});
+    const constrainedKey = constrainPropertyName('');
     expect(constrainedKey).toEqual('Empty');
   });
   test('should use constant naming format', () => {
-    const constrainedKey = TypeScriptDefaultConstraints.propertyKey({constrainedObjectModel, objectModel, propertyKey: 'some weird_value!"#2'});
+    const constrainedKey = constrainPropertyName('some weird_value!"#2');
     expect(constrainedKey).toEqual('SomeWeirdValueExclamationQuotationHash_2');
   });
   test('should not contain duplicate properties', () => {
     const objectModel = new ObjectModel('test', undefined, {});
-    const propertyModel = new ConstrainedObjectModel('SomeProperty', undefined, '', {});
-    const constrainedObjectModel = new ConstrainedObjectModel('test', undefined, '', {SomeProperty: propertyModel});
-    const constrainedKey = TypeScriptDefaultConstraints.propertyKey({constrainedObjectModel, objectModel, propertyKey: 'SomeProperty'});
+    const constrainedObjectModel = new ConstrainedObjectModel('test', undefined, '', {});
+    const objectPropertyModel = new ObjectPropertyModel('SomeProperty', false, objectModel);
+    const constrainedObjectPropertyModel = new ConstrainedObjectPropertyModel('SomeProperty', objectPropertyModel.required, constrainedObjectModel);
+    constrainedObjectModel.properties['SomeProperty'] = constrainedObjectPropertyModel;
+    const constrainedKey = TypeScriptDefaultConstraints.propertyKey({constrainedObjectModel, objectModel, objectPropertyModel, constrainedObjectPropertyModel});
     expect(constrainedKey).toEqual('ReservedSomeProperty');
   });
   test('should never render reserved keywords', () => {
-    const constrainedKey = TypeScriptDefaultConstraints.propertyKey({constrainedObjectModel, objectModel, propertyKey: 'return'});
+    const constrainedKey = constrainPropertyName('return');
     expect(constrainedKey).toEqual('ReservedReturn');
   });
   describe('custom constraints', () => {
@@ -43,7 +51,9 @@ describe('PropertyKeyConstrainer', () => {
         NO_DUPLICATE_PROPERTIES: jest.fn().mockReturnValue('')
       };
       const constrainFunction = defaultPropertyKeyConstraints(mockedConstraintCallbacks);
-      constrainFunction({constrainedObjectModel, objectModel, propertyKey: ''});
+      const objectPropertyModel = new ObjectPropertyModel('', false, objectModel);
+      const constrainedObjectPropertyModel = new ConstrainedObjectPropertyModel('', objectPropertyModel.required, constrainedObjectModel);
+      constrainFunction({constrainedObjectModel, objectModel, objectPropertyModel, constrainedObjectPropertyModel});
       //Expect all callbacks to be called
       for (const jestMockCallback of Object.values(mockedConstraintCallbacks)) {
         expect(jestMockCallback).toHaveBeenCalled();
@@ -60,7 +70,9 @@ describe('PropertyKeyConstrainer', () => {
       ];
       const jestCallback = jest.fn().mockReturnValue('');
       const constrainFunction = defaultPropertyKeyConstraints({NAMING_FORMATTER: jestCallback});
-      const constrainedValue = constrainFunction({constrainedObjectModel, objectModel, propertyKey: ''});
+      const objectPropertyModel = new ObjectPropertyModel('', false, objectModel);
+      const constrainedObjectPropertyModel = new ConstrainedObjectPropertyModel('', objectPropertyModel.required, constrainedObjectModel);
+      const constrainedValue = constrainFunction({constrainedObjectModel, objectModel, objectPropertyModel, constrainedObjectPropertyModel});
       expect(constrainedValue).toEqual('');
       for (const jestMockCallback of spies) {
         expect(jestMockCallback).toHaveBeenCalled();
diff --git a/test/helpers/Splitter.spec.ts b/test/helpers/Splitter.spec.ts
index 89d94647..fc7ef34d 100644
--- a/test/helpers/Splitter.spec.ts
+++ b/test/helpers/Splitter.spec.ts
@@ -1,13 +1,14 @@
 import { split, SplitOptions } from '../../src/helpers';
-import { ObjectModel, ReferenceModel, StringModel } from '../../src/models';
+import { ObjectModel, ReferenceModel, StringModel, ObjectPropertyModel } from '../../src/models';
 describe('Splitter', () => {
   afterEach(() => {
     jest.restoreAllMocks();
   });
   test('should split models when asked for it', () => { 
     const stringModel = new StringModel('testString', undefined);
+    const propertyModel = new ObjectPropertyModel('test', false, stringModel);
     const model = new ObjectModel('testObj', undefined, {
-      test: stringModel
+      test: propertyModel
     });
     const options: SplitOptions = {
       splitString: true
@@ -15,7 +16,7 @@ describe('Splitter', () => {
     const splittedModels = split(model, options);
     
     const expectedObjectModel = model;
-    expectedObjectModel.properties['test'] = new ReferenceModel(stringModel.name, stringModel.originalInput, stringModel);
+    expectedObjectModel.properties['test'].property = new ReferenceModel(stringModel.name, stringModel.originalInput, stringModel);
     
     expect(splittedModels.length).toEqual(2);
     expect(splittedModels[0] instanceof ObjectModel).toEqual(true);
@@ -24,8 +25,9 @@ describe('Splitter', () => {
   });
   test('should not split models when not asked for', () => { 
     const stringModel = new StringModel('testString', undefined);
+    const propertyModel = new ObjectPropertyModel('test', false, stringModel);
     const model = new ObjectModel('testObj', undefined, {
-      test: stringModel
+      test: propertyModel
     });
     const options: SplitOptions = {
       splitString: false
@@ -37,8 +39,9 @@ describe('Splitter', () => {
   });
   test('should not split models when asked for something else', () => { 
     const stringModel = new StringModel('testString', undefined);
+    const propertyModel = new ObjectPropertyModel('test', false, stringModel);
     const model = new ObjectModel('testObj', undefined, {
-      test: stringModel
+      test: propertyModel
     });
     const options: SplitOptions = {
       splitBoolean: true