Ejemplo de registro de empleado (modelos y plantillas de mapeo de API Gateway) - Amazon API Gateway

Ejemplo de registro de empleado (modelos y plantillas de mapeo de API Gateway)

En las secciones siguientes se proporcionan ejemplos de modelos y plantillas de mapeo que pueden utilizarse para una API de registro de un empleado de ejemplo en API Gateway. Para obtener más información sobre los modelos y plantillas de mapeo en API Gateway, consulte Plantilla de mapeo PetStore.

Datos originales (ejemplo de registro de empleado)

A continuación se presentan los datos JSON originales para el ejemplo de registro de empleado:

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

Modelo de entrada (ejemplo de registro de empleado)

A continuación, se muestra el modelo de entrada que se corresponde con los datos JSON originales para el ejemplo de registro de empleado:

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

Plantilla de mapeo de entrada (ejemplo de registro de empleado)

A continuación, se muestra la plantilla de asignación de entrada que se corresponde con los datos JSON originales para el ejemplo de registro de empleado:

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

Datos transformados (ejemplo de registro de empleado)

A continuación se muestra un ejemplo de cómo se pueden transformar los datos JSON del ejemplo de registro de empleado original para producir el resultado:

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

Modelo de salida (ejemplo de registro de empleado)

A continuación, se muestra el modelo de salida que se corresponde con el formato de datos JSON transformados:

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

Plantilla de mapeo de salida (ejemplo de registro de empleado)

A continuación, se muestra la plantilla de asignación de salida que se corresponde con el formato de datos JSON transformados. Las variables de plantilla aquí se basan en el formato de datos JSON original, no en el transformado:

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