Mapping

It helps to map a <structure> based on the value of one of its properties (that you mention in property-name attribute of discriminator). It also helps to override the existing mapping details.

Possible Locations

Attributes


Name Type Description
name
required
String Value of the discriminator <property> based on which you want to map the structure.
structure-name
required
String Name of the structure that you want to map.

Example

Employ the <mapping> when referencing a <structure> from different resource, for which the developer hasn’t specified any discriminator-name. You can also use it to override the previously configured discriminator-name.

In the trips resource, we offer two services: Flight and Accommodation services for customers. Depending on the chosen service, we need to assign a specific structure. Each of these services has an individual resource, and their developers have declared structures for using it in other resources.

The flights resource developer has not specified any discriminator-name but has added the discriminator’s <property> to the structure. The accommodations resource developer has specified Hotel as the discriminator-name.

Below are the structures declared in the <components> of each resource.

    
copy
structure in the flights resource: <components> <structure ref-name="flight_template" name="external_resource_use" > <property name="type" type="string" values="Flight" /> <!-- discriminator's property --> <property name="flight_no" type="string" /> <property name="departure_airport" type="string" /> <property name="arrival_airport" type="string" /> </structure> </components>
    
copy
structure in the accommodations resource: <components> <structure ref-name="accommodation_template" name="external_resource_use" discriminator-name="Hotel"> <property name="hotel_name" type="string" /> <property name="check_in_date" type="string" /> <property name="check_out_date" type="string" /> </structure> </components>

Now, you have to declare a new mapping for the flight_template structure and override the existing mapping of accommodation_template structure in the following way.

    
copy
<property name="service" type="map"> <structure-group name="services" type="one-of"> <structure-ref name="flights.flight_template" /> <structure-ref name="accommodations.accommodation_template" /> <discriminator property-name="type"> <mapping name="Flight" structure-name="flights.flight_template"/> <mapping name="Accommodation" structure-name="accommodations.accommodation_template"/> <!-- Hotel is overridden with Accommodation --> </discriminator> </structure-group> </property>

Last Updated 2025-05-30 16:54:59 +0530 +0530