Amazon API Gateway
开发人员指南
AWS 文档中描述的 AWS 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 Amazon AWS 入门

销售发票示例 (API Gateway 模型和映射模板)

以下各节提供一些可用于 API Gateway 中示例销售发票 API 的模型和映射模板的示例。有关 API Gateway 中模型和映射模板的更多信息,请参阅为请求和响应映射创建模型和映射模板

原始数据 (销售发票示例)

下面是销售发票示例的原始 JSON 数据:

{ "DueDate": "2013-02-15", "Balance": 1990.19, "DocNumber": "SAMP001", "Status": "Payable", "Line": [ { "Description": "Sample Expense", "Amount": 500, "DetailType": "ExpenseDetail", "ExpenseDetail": { "Customer": { "value": "ABC123", "name": "Sample Customer" }, "Ref": { "value": "DEF234", "name": "Sample Construction" }, "Account": { "value": "EFG345", "name": "Fuel" }, "LineStatus": "Billable" } } ], "Vendor": { "value": "GHI456", "name": "Sample Bank" }, "APRef": { "value": "HIJ567", "name": "Accounts Payable" }, "TotalAmt": 1990.19 }

输入模型 (销售发票示例)

以下是与销售发票示例的原始 JSON 数据对应的输入模型:

{ "$schema": "http://json-schema.org/draft-04/schema#", "title": "InvoiceInputModel", "type": "object", "properties": { "DueDate": { "type": "string" }, "Balance": { "type": "number" }, "DocNumber": { "type": "string" }, "Status": { "type": "string" }, "Line": { "type": "array", "items": { "type": "object", "properties": { "Description": { "type": "string" }, "Amount": { "type": "integer" }, "DetailType": { "type": "string" }, "ExpenseDetail": { "type": "object", "properties": { "Customer": { "type": "object", "properties": { "value": { "type": "string" }, "name": { "type": "string" } } }, "Ref": { "type": "object", "properties": { "value": { "type": "string" }, "name": { "type": "string" } } }, "Account": { "type": "object", "properties": { "value": { "type": "string" }, "name": { "type": "string" } } }, "LineStatus": { "type": "string" } } } } } }, "Vendor": { "type": "object", "properties": { "value": { "type": "string" }, "name": { "type": "string" } } }, "APRef": { "type": "object", "properties": { "value": { "type": "string" }, "name": { "type": "string" } } }, "TotalAmt": { "type": "number" } } }

输入映射模板 (销售发票示例)

以下是与销售发票示例的原始 JSON 数据对应的输入映射模板:

#set($inputRoot = $input.path('$')) { "DueDate": "$inputRoot.DueDate", "Balance": $inputRoot.Balance, "DocNumber": "$inputRoot.DocNumber", "Status": "$inputRoot.Status", "Line": [ #foreach($elem in $inputRoot.Line) { "Description": "$elem.Description", "Amount": $elem.Amount, "DetailType": "$elem.DetailType", "ExpenseDetail": { "Customer": { "value": "$elem.ExpenseDetail.Customer.value", "name": "$elem.ExpenseDetail.Customer.name" }, "Ref": { "value": "$elem.ExpenseDetail.Ref.value", "name": "$elem.ExpenseDetail.Ref.name" }, "Account": { "value": "$elem.ExpenseDetail.Account.value", "name": "$elem.ExpenseDetail.Account.name" }, "LineStatus": "$elem.ExpenseDetail.LineStatus" } }#if($foreach.hasNext),#end #end ], "Vendor": { "value": "$inputRoot.Vendor.value", "name": "$inputRoot.Vendor.name" }, "APRef": { "value": "$inputRoot.APRef.value", "name": "$inputRoot.APRef.name" }, "TotalAmt": $inputRoot.TotalAmt }

转换后的数据 (销售发票示例)

以下是一个介绍如何转换原始销售发票示例 JSON 数据以供输出的示例:

{ "DueDate": "2013-02-15", "Balance": 1990.19, "DocNumber": "SAMP001", "Status": "Payable", "Line": [ { "Description": "Sample Expense", "Amount": 500, "DetailType": "ExpenseDetail", "Customer": "ABC123 (Sample Customer)", "Ref": "DEF234 (Sample Construction)", "Account": "EFG345 (Fuel)", "LineStatus": "Billable" } ], "TotalAmt": 1990.19 }

输出模型 (销售发票示例)

以下是与已转换的 JSON 数据格式对应的输出模型:

{ "$schema": "http://json-schema.org/draft-04/schema#", "title": "InvoiceOutputModel", "type": "object", "properties": { "DueDate": { "type": "string" }, "Balance": { "type": "number" }, "DocNumber": { "type": "string" }, "Status": { "type": "string" }, "Line": { "type": "array", "items": { "type": "object", "properties": { "Description": { "type": "string" }, "Amount": { "type": "integer" }, "DetailType": { "type": "string" }, "Customer": { "type": "string" }, "Ref": { "type": "string" }, "Account": { "type": "string" }, "LineStatus": { "type": "string" } } } }, "TotalAmt": { "type": "number" } } }

输出映射模板 (销售发票示例)

以下是与已转换的 JSON 数据格式对应的输出映射模板。此处的模板变量基于原始 (而非已转换的) JSON 数据格式:

#set($inputRoot = $input.path('$')) { "DueDate": "$inputRoot.DueDate", "Balance": $inputRoot.Balance, "DocNumber": "$inputRoot.DocNumber", "Status": "$inputRoot.Status", "Line": [ #foreach($elem in $inputRoot.Line) { "Description": "$elem.Description", "Amount": $elem.Amount, "DetailType": "$elem.DetailType", "Customer": "$elem.ExpenseDetail.Customer.value ($elem.ExpenseDetail.Customer.name)", "Ref": "$elem.ExpenseDetail.Ref.value ($elem.ExpenseDetail.Ref.name)", "Account": "$elem.ExpenseDetail.Account.value ($elem.ExpenseDetail.Account.name)", "LineStatus": "$elem.ExpenseDetail.LineStatus" }#if($foreach.hasNext),#end #end ], "TotalAmt": $inputRoot.TotalAmt }