Skip to content

Commit

Permalink
refactor: add suggested changes to remove duplicate code
Browse files Browse the repository at this point in the history
  • Loading branch information
asadali214 committed Oct 30, 2024
1 parent 3cba023 commit 19b9c17
Showing 1 changed file with 17 additions and 22 deletions.
39 changes: 17 additions & 22 deletions packages/schema/src/types/object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,11 +256,8 @@ function validateObjectBeforeMapXml(
[key: string]: unknown;
};
const { $: attrs, ...elements } = valueObject;
const attributes = attrs ?? {};

// Validate all known elements and attributes using the schema

return validateValueObject({
let validationObj = {
validationMethod: 'validateBeforeMapXml',
propTypeName: 'child elements',
propTypePrefix: 'element',
Expand All @@ -271,20 +268,21 @@ function validateObjectBeforeMapXml(
ctxt,
skipAdditionalPropValidation,
mapAdditionalProps,
}).concat(
validateValueObject({
validationMethod: 'validateBeforeMapXml',
propTypeName: 'attributes',
propTypePrefix: '@',
valueTypeName: 'element',
propMapping: attributesToProps,
objectSchema,
valueObject: attributes,
ctxt,
skipAdditionalPropValidation,
mapAdditionalProps,
})
);
};
// Validate all known elements using the schema
const elementErrors = validateValueObject(validationObj);

validationObj = {
...validationObj,
propTypeName: 'attributes',
propTypePrefix: '@',
propMapping: attributesToProps,
valueObject: attrs ?? {},
};
// Validate all known attributes using the schema
const attributesErrors = validateValueObject(validationObj);

return elementErrors.concat(attributesErrors);
};
}

Expand Down Expand Up @@ -388,10 +386,7 @@ function validateValueObject({
skipAdditionalPropValidation,
mapAdditionalProps,
}: {
validationMethod:
| 'validateBeforeMap'
| 'validateBeforeUnmap'
| 'validateBeforeMapXml';
validationMethod: string;
propTypeName: string;
propTypePrefix: string;
valueTypeName: string;
Expand Down

0 comments on commit 19b9c17

Please sign in to comment.