Configuring the mapping file for generated endpoints
Within the context of Cloud API, a mapping file contains mappers that define how information is mapped from a data model entity to the corresponding element resource. This information is used for GETs, and for the responses of POSTs and PATCHes.
The following sections provide an overview of configuring mapping files for generated endpoints. For a complete description of how to configure mapping files, see Endpoint architecture.
Overview of mapping file syntax
A mapping file contains a mappers
section that lists one or more API
resources. For each resource, the following attributes are specified:
- The
schemaDefinition
that defines the structure of the resource- This references a schema declared in a schema.json file.
- The data model entity that serves as the
root
for mapping information for this resource. - A list of
properties
- Each property includes a
path
attribute. This is a Gosu expression that is used to populate the value of the property. Typically, this expression returns a value from the entity defined in theroot
attribute. - Depending on the nature of the property, there may be additional attributes.
- Each property includes a
For example, the following is a portion of the mapper for the base configuration
Activity
resource:
"Activity": {
"schemaDefinition": "Activity",
"root": "entity.Activity",
"properties": {
"closeDate": {
"path": "Activity.CloseDate"
},
"description": {
"path": "Activity.Description"
},
"mandatory": {
"path": "Activity.Mandatory"
},
...
Note the following:
- This resource is defined in the schema who name is
Activity
(This schema is defined in some other schema.json file.) - The root for the resource mapping is
entity.Activity
. - For each instance of the resource:
- The
closeDate
property is set to theActivity
entity'sCloseDate
field. - The
description
property is set to theActivity
entity'sDescription
field. - The
mandatory
property is set to theActivity
entity'sMandatory
field.
- The
Modifications made to the mapping file
The base configuration includes a set of API-specific extension mapping files. The
purpose of these files is to define mapper information for custom resources for a given
API. These files are named using the pattern
<API>_ext-1.0.mapping.json
, where <API> is the internal name
of the API. For example, the common_ext-1.0.mapping.json
file is used
to define mapper information for custom resources in the Common API. You can access
extension mapping files in Studio through the integration -> mappers -> ext ->
<API>.v1 node.
(There is an exception to the previous statement. When you add endpoints to
the Job API, mapper modifications are not made to a
job_ext-1.0.mapping.json
file, but rather to the
policyperiod_ext-1.0.mapping.json
file.)
Resource-level information
The REST endpoint generator adds the following resource-level information to the mapping file:
"<resourceName>": {
"schemaDefinition": "<schemaNameForResource>",
"root": "entity.<customEntity>",
"properties": {
...
}
}
}
Mappers added by the REST endpoint generator
The REST endpoint generator also adds mappers for any of the fields it added to the
schema, including the id
field.
For example, suppose you generated endpoints for a CustomEntity_Ext
entity with the following fields:
Description
(a varchar field)IsActive
(a Boolean field)ActiveDate
(a datetime field)ActiveCount
(an integer field)
The REST endpoint generator adds the following to the mapping file:
"properties": {
// TODO RestEndpointGenerator : Add mapper properties here
"activeCount": {
"path": "CustomEntity_Ext.ActiveCount"
},
"activeDate": {
"path": "CustomEntity_Ext.ActiveDate"
},
"description": {
"path": "CustomEntity_Ext.Description"
},
"id": {
"path": "CustomEntity_Ext.RestId"
},
"isActive": {
"path": "CustomEntity_Ext.IsActive"
}
...
}
}
Additional configuration work to do
You are responsible for the following configuration work:
- Removing any mappers that were created by the REST endpoint generator but which correspond to fields that are not to be exposed to Cloud API
- Adding mappers for any fields that must be exposed to Cloud API but that were not created by the REST endpoint generator
For more information on how to configure scalar and compound datatype properties in a mapping file, see Adding scalars and Adding compound datatypes.