Map file examples
Examples of map files that define all mapping operations for data transformations.
One to one mapping
- Maps parameters from the request's query to an object in the message body.
- Maps a string to a string.
- Maps an integer to an integer.
The output referenced definition defines an object that contains a string, a name, and an integer.
- map:
title: 1-1 map
inputs:
input_string:
schema:
type: string
variable: request.parameters.name_in
input_integer:
schema:
type: integer
variable: request.parameters.age_in
outputs:
output:
schema:
$ref: '#/definitions/output'
variable: message.body
actions:
- set: output.name_out
from: input_string
- set: output.age_out
from: input_integerMany to one mapping
- Maps parameters from the request's query to an object in the message body.
- Maps two strings to one string by concatenating them.
- Maps two integers to one integer by summing them.
The output referenced definition defines
an object that contains a string and an integer.
- map:
title: many-1 map
inputs:
input_string_1:
schema:
type: string
variable: request.parameters.first_name
input_string_2:
schema:
type: string
variable: request.parameters.last_name
input_integer_1:
schema:
type: integer
variable: request.parameters.balance_1
input_integer_2:
schema:
type: integer
variable: request.parameters.balance_2
outputs:
output:
schema:
$ref: '#/definitions/output'
variable: message.body
actions:
- set: output.full_name
from:
- input_string_1
- input_string_2
value: |
var retValue = undefined;
if ($(input_string_1) !== undefined && $(input_string_2) !== undefined) {
retValue = $(input_string_1).toUpperCase() + ' ' + $(input_string_2).toUpperCase()"
}
retValue;
- set: output.total_balance
from:
- input_integer_1
- input_integer_2
value: |
var i1 = 0;
var i2 = 0;
if ($(input_integer_1) !== undefined) i1 = $(input_integer_1);
if ($(input_integer_2) !== undefined) i2 = $(input_integer_2);
i1 + i2;A simple transformation by using the value field
- Maps a parameter from the request's query to an object in the message body.
- Maps a string featuring lowercase characters to a string that contains only uppercase characters.
The output referenced definition defines
an object that contains a string.
- map:
title: Uppercase map
inputs:
input_lowercase:
schema:
type: string
variable: request.parameters.name_in
outputs:
output_uppercase:
schema:
$ref: '#/definitions/output'
variable: message.body
actions:
- set: output_uppercase.name_out
from: input_lowercase
value: $(input_lowercase).toUpperCase()Mapping from multiple contexts into a new context
- Maps an integer from the request header to an integer in a new message body.
- Maps a string from the message body to the body of the custom new_context context.
- map:
title: Context map
inputs:
input_integer:
schema:
type: integer
variable: request.headers.age_in
input_string:
schema:
type: string
variable: message.body.name_in
outputs:
output_integer:
schema:
type: integer
variable: message.body.age_out
output_string:
schema:
type: string
variable: new_context.body.name_internal
actions:
- set: output_string
from: input_string
- set: output_integer
from: input_integerMapping to an inline schema definition
- Maps parameters from the request headers to an object in the message body, which is defined within the map policy.
- Maps one string directly to a single string.
- Maps one integer directly to a single integer.
- map:
title: Inline schema map
inputs:
input_integer:
schema:
type: integer
variable: request.headers.age_in
input_string:
schema:
type: string
variable: request.headers.name_in
outputs:
output:
schema:
type: object
properties:
name_out:
type: string
name: name_out
age_out:
type: integer
format: int32
name: age_out
title: output
variable: message.body
actions:
- set: output.age_out
from: input_integer
- set: output.name_out
from: input_stringMapping with a default value
- Maps one string directly to a single string.
- Provides a default value for the output string when a valid input string is not provided.
- map:
title: Default Map
inputs:
input_string:
schema:
type: string
variable: request.headers.name_in
outputs:
output_string:
schema:
type: string
variable: message.body.name_out
actions:
- set: output_string
from: input_string
default: John SmithMapping an array into a single value
- Maps a single array of integers into a single integer.
- Sums the integers in the array.
$(0)represents the accumulated output because map evaluates all array element values.
- map:
title: Summation map
inputs:
input:
schema:
$ref: '#/definitions/balance_array_in'
variable: request.body
outputs:
output:
schema:
type: integer
variable: message.body.total_balance_out
actions:
- set: output
from: input
foreach: input
value: $(0)+$(input)Mapping array elements to an array
- Maps an array, whose elements are objects with two integers, to an array, whose entries contain a single integer field.
- Maps an array to an array of the same length.
- Takes the difference of the values of the integers in each array element to create a single integer in each array element.
- map:
title: Array summation
inputs:
input:
schema:
$ref: '#/definitions/balance_and_credit_array'
variable: request.body
outputs:
output_array:
schema:
type: array
variable: message.body
actions:
- create: output_array
from: input
foreach: input
actions:
- set: total_balance_out
from:
- integer_in_1
- integer_in_2
value: $(integer_in_1)-$(integer_in_2)Advanced options
The following example shows
how advanced options control the XML output.
- Includes empty elements in the XML output for every element in the schema that has no mapped value.
- Indicates that all namespace declarations are placed on the root XML element.
- Indicates that an array of all array element values is returned.
- Indicates that any variable that is found in the assembly map action configuration is resolved.
actions:
- set: output, two
from: input, one
options:
includeEmptyXMLElements: false
inlineNamespaces: false
mapArrayFirstElementValue: false
mapResolveApicVariables: trueThe following
example shows how advanced options control the JSON output.
- Indicates that an array of all array element values is returned.
- Indicates that all empty arrays, including empty children arrays, are outputted.
actions:
- set: output, two
from: input, one
options:
mapArrayFirstElementValue: false
mapCreateEmptyArray: all