照片示例(API Gateway 模型和映射模板)
以下各节提供一些可用于 API Gateway 中示例照片 API 的模型和映射模板的示例。有关 API Gateway 中模型和映射模板的更多信息,请参阅使用模型和映射模板。
原始数据(照片示例)
以下是照片示例的原始 JSON 数据:
{ "photos": { "page": 1, "pages": "1234", "perpage": 100, "total": "123398", "photo": [ { "id": "12345678901", "owner": "23456789@A12", "secret": "abc123d456", "server": "1234", "farm": 1, "title": "Sample photo 1", "ispublic": 1, "isfriend": 0, "isfamily": 0 }, { "id": "23456789012", "owner": "34567890@B23", "secret": "bcd234e567", "server": "2345", "farm": 2, "title": "Sample photo 2", "ispublic": 1, "isfriend": 0, "isfamily": 0 } ] } }
输入模型(照片示例)
以下是与照片示例的原始 JSON 数据对应的输入模型:
{ "$schema": "http://json-schema.org/draft-04/schema#", "title": "PhotosInputModel", "type": "object", "properties": { "photos": { "type": "object", "properties": { "page": { "type": "integer" }, "pages": { "type": "string" }, "perpage": { "type": "integer" }, "total": { "type": "string" }, "photo": { "type": "array", "items": { "type": "object", "properties": { "id": { "type": "string" }, "owner": { "type": "string" }, "secret": { "type": "string" }, "server": { "type": "string" }, "farm": { "type": "integer" }, "title": { "type": "string" }, "ispublic": { "type": "integer" }, "isfriend": { "type": "integer" }, "isfamily": { "type": "integer" } } } } } } } }
输入映射模板(照片示例)
以下是与照片示例的原始 JSON 数据对应的输入映射模板:
#set($inputRoot = $input.path('$')) { "photos": { "page": $inputRoot.photos.page, "pages": "$inputRoot.photos.pages", "perpage": $inputRoot.photos.perpage, "total": "$inputRoot.photos.total", "photo": [ #foreach($elem in $inputRoot.photos.photo) { "id": "$elem.id", "owner": "$elem.owner", "secret": "$elem.secret", "server": "$elem.server", "farm": $elem.farm, "title": "$elem.title", "ispublic": $elem.ispublic, "isfriend": $elem.isfriend, "isfamily": $elem.isfamily }#if($foreach.hasNext),#end #end ] } }
转换后的数据(照片示例)
以下是一个介绍如何转换原始照片示例 JSON 数据以供输出的示例:
{ "photos": [ { "id": "12345678901", "owner": "23456789@A12", "title": "Sample photo 1", "ispublic": 1, "isfriend": 0, "isfamily": 0 }, { "id": "23456789012", "owner": "34567890@B23", "title": "Sample photo 2", "ispublic": 1, "isfriend": 0, "isfamily": 0 } ] }
输出模型(照片示例)
以下是与已转换的 JSON 数据格式对应的输出模型:
{ "$schema": "http://json-schema.org/draft-04/schema#", "title": "PhotosOutputModel", "type": "object", "properties": { "photos": { "type": "array", "items": { "type": "object", "properties": { "id": { "type": "string" }, "owner": { "type": "string" }, "title": { "type": "string" }, "ispublic": { "type": "integer" }, "isfriend": { "type": "integer" }, "isfamily": { "type": "integer" } } } } } }
输出映射模板(照片示例)
以下是与已转换的 JSON 数据格式对应的输出映射模板。此处的模板变量基于原始 (而非已转换的) JSON 数据格式:
#set($inputRoot = $input.path('$')) { "photos": [ #foreach($elem in $inputRoot.photos.photo) { "id": "$elem.id", "owner": "$elem.owner", "title": "$elem.title", "ispublic": $elem.ispublic, "isfriend": $elem.isfriend, "isfamily": $elem.isfamily }#if($foreach.hasNext),#end #end ] }