Employee record example (API Gateway models and mapping templates) - Amazon API Gateway

Employee record example (API Gateway models and mapping templates)

The following sections provide examples of models and mapping templates that can be used for a sample employee record API in API Gateway. For more information about models and mapping templates in API Gateway, see PetStore mapping template.

Original data (employee record example)

The following is the original JSON data for the employee record example:

{ "QueryResponse": { "maxResults": "1", "startPosition": "1", "Employee": { "Organization": "false", "Title": "Mrs.", "GivenName": "Jane", "MiddleName": "Lane", "FamilyName": "Doe", "DisplayName": "Jane Lane Doe", "PrintOnCheckName": "Jane Lane Doe", "Active": "true", "PrimaryPhone": { "FreeFormNumber": "505.555.9999" }, "PrimaryEmailAddr": { "Address": "janedoe@example.com" }, "EmployeeType": "Regular", "status": "Synchronized", "Id": "ABC123", "SyncToken": "1", "MetaData": { "CreateTime": "2015-04-26T19:45:03Z", "LastUpdatedTime": "2015-04-27T21:48:23Z" }, "PrimaryAddr": { "Line1": "123 Any Street", "City": "Any City", "CountrySubDivisionCode": "WA", "PostalCode": "01234" } } }, "time": "2015-04-27T22:12:32.012Z" }

Input model (employee record example)

The following is the input model that corresponds to the original JSON data for the employee record example:

{ "$schema": "http://json-schema.org/draft-04/schema#", "title": "EmployeeInputModel", "type": "object", "properties": { "QueryResponse": { "type": "object", "properties": { "maxResults": { "type": "string" }, "startPosition": { "type": "string" }, "Employee": { "type": "object", "properties": { "Organization": { "type": "string" }, "Title": { "type": "string" }, "GivenName": { "type": "string" }, "MiddleName": { "type": "string" }, "FamilyName": { "type": "string" }, "DisplayName": { "type": "string" }, "PrintOnCheckName": { "type": "string" }, "Active": { "type": "string" }, "PrimaryPhone": { "type": "object", "properties": { "FreeFormNumber": { "type": "string" } } }, "PrimaryEmailAddr": { "type": "object", "properties": { "Address": { "type": "string" } } }, "EmployeeType": { "type": "string" }, "status": { "type": "string" }, "Id": { "type": "string" }, "SyncToken": { "type": "string" }, "MetaData": { "type": "object", "properties": { "CreateTime": { "type": "string" }, "LastUpdatedTime": { "type": "string" } } }, "PrimaryAddr": { "type": "object", "properties": { "Line1": { "type": "string" }, "City": { "type": "string" }, "CountrySubDivisionCode": { "type": "string" }, "PostalCode": { "type": "string" } } } } } } }, "time": { "type": "string" } } }

Input mapping template (employee record example)

The following is the input mapping template that corresponds to the original JSON data for the employee record example:

#set($inputRoot = $input.path('$')) { "QueryResponse": { "maxResults": "$inputRoot.QueryResponse.maxResults", "startPosition": "$inputRoot.QueryResponse.startPosition", "Employee": { "Organization": "$inputRoot.QueryResponse.Employee.Organization", "Title": "$inputRoot.QueryResponse.Employee.Title", "GivenName": "$inputRoot.QueryResponse.Employee.GivenName", "MiddleName": "$inputRoot.QueryResponse.Employee.MiddleName", "FamilyName": "$inputRoot.QueryResponse.Employee.FamilyName", "DisplayName": "$inputRoot.QueryResponse.Employee.DisplayName", "PrintOnCheckName": "$inputRoot.QueryResponse.Employee.PrintOnCheckName", "Active": "$inputRoot.QueryResponse.Employee.Active", "PrimaryPhone": { "FreeFormNumber": "$inputRoot.QueryResponse.Employee.PrimaryPhone.FreeFormNumber" }, "PrimaryEmailAddr": { "Address": "$inputRoot.QueryResponse.Employee.PrimaryEmailAddr.Address" }, "EmployeeType": "$inputRoot.QueryResponse.Employee.EmployeeType", "status": "$inputRoot.QueryResponse.Employee.status", "Id": "$inputRoot.QueryResponse.Employee.Id", "SyncToken": "$inputRoot.QueryResponse.Employee.SyncToken", "MetaData": { "CreateTime": "$inputRoot.QueryResponse.Employee.MetaData.CreateTime", "LastUpdatedTime": "$inputRoot.QueryResponse.Employee.MetaData.LastUpdatedTime" }, "PrimaryAddr" : { "Line1": "$inputRoot.QueryResponse.Employee.PrimaryAddr.Line1", "City": "$inputRoot.QueryResponse.Employee.PrimaryAddr.City", "CountrySubDivisionCode": "$inputRoot.QueryResponse.Employee.PrimaryAddr.CountrySubDivisionCode", "PostalCode": "$inputRoot.QueryResponse.Employee.PrimaryAddr.PostalCode" } } }, "time": "$inputRoot.time" }

Transformed data (employee record example)

The following is one example of how the original employee record example JSON data could be transformed for output:

{ "QueryResponse": { "maxResults": "1", "startPosition": "1", "Employees": [ { "Title": "Mrs.", "GivenName": "Jane", "MiddleName": "Lane", "FamilyName": "Doe", "DisplayName": "Jane Lane Doe", "PrintOnCheckName": "Jane Lane Doe", "Active": "true", "PrimaryPhone": "505.555.9999", "Email": [ { "type": "primary", "Address": "janedoe@example.com" } ], "EmployeeType": "Regular", "PrimaryAddr": { "Line1": "123 Any Street", "City": "Any City", "CountrySubDivisionCode": "WA", "PostalCode": "01234" } } ] }, "time": "2015-04-27T22:12:32.012Z" }

Output model (employee record example)

The following is the output model that corresponds to the transformed JSON data format:

{ "$schema": "http://json-schema.org/draft-04/schema#", "title": "EmployeeOutputModel", "type": "object", "properties": { "QueryResponse": { "type": "object", "properties": { "maxResults": { "type": "string" }, "startPosition": { "type": "string" }, "Employees": { "type": "array", "items": { "type": "object", "properties": { "Title": { "type": "string" }, "GivenName": { "type": "string" }, "MiddleName": { "type": "string" }, "FamilyName": { "type": "string" }, "DisplayName": { "type": "string" }, "PrintOnCheckName": { "type": "string" }, "Active": { "type": "string" }, "PrimaryPhone": { "type": "string" }, "Email": { "type": "array", "items": { "type": "object", "properties": { "type": { "type": "string" }, "Address": { "type": "string" } } } }, "EmployeeType": { "type": "string" }, "PrimaryAddr": { "type": "object", "properties": { "Line1": {"type": "string" }, "City": { "type": "string" }, "CountrySubDivisionCode": { "type": "string" }, "PostalCode": { "type": "string" } } } } } } } }, "time": { "type": "string" } } }

Output mapping template (employee record example)

The following is the output mapping template that corresponds to the transformed JSON data format. The template variables here are based on the original, not transformed, JSON data format:

#set($inputRoot = $input.path('$')) { "QueryResponse": { "maxResults": "$inputRoot.QueryResponse.maxResults", "startPosition": "$inputRoot.QueryResponse.startPosition", "Employees": [ { "Title": "$inputRoot.QueryResponse.Employee.Title", "GivenName": "$inputRoot.QueryResponse.Employee.GivenName", "MiddleName": "$inputRoot.QueryResponse.Employee.MiddleName", "FamilyName": "$inputRoot.QueryResponse.Employee.FamilyName", "DisplayName": "$inputRoot.QueryResponse.Employee.DisplayName", "PrintOnCheckName": "$inputRoot.QueryResponse.Employee.PrintOnCheckName", "Active": "$inputRoot.QueryResponse.Employee.Active", "PrimaryPhone": "$inputRoot.QueryResponse.Employee.PrimaryPhone.FreeFormNumber", "Email" : [ { "type": "primary", "Address": "$inputRoot.QueryResponse.Employee.PrimaryEmailAddr.Address" } ], "EmployeeType": "$inputRoot.QueryResponse.Employee.EmployeeType", "PrimaryAddr": { "Line1": "$inputRoot.QueryResponse.Employee.PrimaryAddr.Line1", "City": "$inputRoot.QueryResponse.Employee.PrimaryAddr.City", "CountrySubDivisionCode": "$inputRoot.QueryResponse.Employee.PrimaryAddr.CountrySubDivisionCode", "PostalCode": "$inputRoot.QueryResponse.Employee.PrimaryAddr.PostalCode" } } ] }, "time": "$inputRoot.time" }