Skip to content

Commit

Permalink
refactor: update an argument name to match its type
Browse files Browse the repository at this point in the history
  • Loading branch information
asadali214 committed Oct 30, 2024
1 parent 19b9c17 commit 9ab8bbe
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions packages/schema/src/types/object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,10 +288,10 @@ function validateObjectBeforeMapXml(

function mapObjectFromXml(
xmlObjectSchema: XmlObjectSchema,
allowAdditionalProps: boolean | [string, Schema<any, any>]
mapAdditionalProps: boolean | [string, Schema<any, any>]
) {
const { elementsSchema, attributesSchema } = xmlObjectSchema;
const mapElements = mapObject(elementsSchema, 'mapXml', allowAdditionalProps);
const mapElements = mapObject(elementsSchema, 'mapXml', mapAdditionalProps);
const mapAttributes = mapObject(
attributesSchema,
'mapXml',
Expand All @@ -317,7 +317,7 @@ function mapObjectFromXml(
...mapElements(elements, ctxt),
};

if (allowAdditionalProps) {
if (mapAdditionalProps) {
// Omit known attributes and copy the rest as additional attributes.
const additionalAttrs = omitKeysFromObject(attributes, attributeKeys);
if (Object.keys(additionalAttrs).length > 0) {
Expand All @@ -332,22 +332,18 @@ function mapObjectFromXml(

function unmapObjectToXml(
xmlObjectSchema: XmlObjectSchema,
allowAdditionalProps: boolean | [string, Schema<any, any>]
mapAdditionalProps: boolean | [string, Schema<any, any>]
) {
const { elementsSchema, attributesSchema } = xmlObjectSchema;
const mapElements = mapObject(
elementsSchema,
'unmapXml',
allowAdditionalProps
);
const mapElements = mapObject(elementsSchema, 'unmapXml', mapAdditionalProps);
const mapAttributes = mapObject(
attributesSchema,
'unmapXml',
false // Always false so that element props are not copied during mapping
);

// These are later used to omit attribute props from the value object so that they
// do not get mapped during element mapping, if the allowAdditionalProps is true.
// do not get mapped during element mapping, if the mapAdditionalProps is set.
const attributeKeys = objectEntries(attributesSchema).map(
([_, [name]]) => name
);
Expand All @@ -363,7 +359,7 @@ function unmapObjectToXml(
const additionalAttributes =
typeof attributes === 'object' &&
attributes !== null &&
allowAdditionalProps
mapAdditionalProps
? attributes
: {};

Expand Down

0 comments on commit 9ab8bbe

Please sign in to comment.