Beispiel für eine Verkaufsrechnung (Modelle und Mapping-Vorlagen in API Gateway) - Amazon API Gateway

Beispiel für eine Verkaufsrechnung (Modelle und Mapping-Vorlagen in API Gateway)

In den folgenden Abschnitten finden Sie Beispiele für Modelle und Mapping-Vorlagen, die für eine Beispiel-Verkaufsrechnungs-API in Amazon API Gateway verwendet werden könnten. Weitere Informationen über Modelle und Mapping-Vorlagen in API Gateway finden Sie unter Arbeiten mit Modellen und Mapping-Vorlagen.

Originaldaten (Beispiel für eine Verkaufsrechnung)

Im folgenden Beispiel werden die Original-JSON-Daten für das Beispiel einer Verkaufsrechnung dargestellt:

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

Eingabemodell (Beispiel für eine Verkaufsrechnung)

Nachstehend finden Sie das Eingabemodell, das den ursprünglichen JSON-Daten für das Verkaufsrechnungs-Beispiel entspricht:

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

Eingabe-Mapping-Vorlage (Beispiel für eine Verkaufsrechnung)

Nachstehend finden Sie die Mapping-Vorlage, die den ursprünglichen JSON-Daten für das Verkaufsrechnungs-Beispiel entspricht:

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

Transformierte Daten (Beispiel für eine Verkaufsrechnung)

Im Folgenden finden Sie ein Beispiel dafür, wie die ursprünglichen JSON-Daten des Verkaufsrechnungs-Beispiels zur Ausgabe umgewandelt werden könnten:

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

Ausgabemodell (Beispiel für eine Verkaufsrechnung)

Im Folgenden sehen Sie das Ausgabemodell, das dem umgewandelten JSON-Datenformat entspricht:

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

Ausgabe-Mapping-Vorlage (Beispiel für eine Verkaufsrechnung)

Im Folgenden sehen Sie die Ausgabe-Mapping-Vorlage, die dem umgewandelten JSON-Datenformat entspricht. Die Vorlagenvariablen hier basieren auf dem nicht umgewandelten Original-JSON-Datenformat:

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