员工记录示例(API Gateway 模型和映射模板) - Amazon API Gateway
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

员工记录示例(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" }