従業員レコードの例 (API Gateway のモデルとマッピングテンプレート) - Amazon API Gateway

従業員レコードの例 (API Gateway のモデルとマッピングテンプレート)

以下のセクションでは、API Gateway でサンプル従業員レコード API に使用できるモデルとマッピングテンプレートの例を示します。API Gateway のモデルとマッピングテンプレートの詳細については、「PetStore マッピングテンプレート」を参照してください。

元のデータ (従業員レコードの例)

以下に示しているのは、従業員レコードの例の元の JSON データです。

{ "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" }

入力モデル (従業員レコードの例)

以下に示しているのは、従業員レコードの例の元の JSON データに対応する入力モデルです。

{ "$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" } } }

入力マッピングテンプレート (従業員レコードの例)

以下に示しているのは、従業員レコードの例の元の JSON データに対応するマッピングテンプレートです。

#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" }

変換後のデータ (従業員レコードの例)

以下に示しているのは、元の従業員レコードの例の JSON データが出力用にどのように変換されるかの一例です。

{ "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" }

出力モデル (従業員レコードの例)

以下に、変換された JSON データ形式に対応する出力モデルを示します。

{ "$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" } } }

出力マッピングテンプレート (従業員レコードの例)

次に、変換された JSON データ形式に対応する出力マッピングテンプレートを示します。この場合のテンプレートは、変換されていない元の JSON データ形式に基づいて変化します。

#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" }