swagger: '2.0' info: description: This example demonstrates the JSON-to-XML transformation process using Gravitee policies. version: 1.1.0 title: JSON-to-XML Transformation Policy Documentation tags: - name: JSON to XML Policy description: | # 🔄 **JSON to XML Policy** #### This example showcases the JSON-to-XML Transformation Policy in Gravitee. ## Role of JSON-to-XML and Mock Policies in the API Flow ### JSON to XML Policy in the Request Phase: - Converts the incoming JSON payload from Postman into XML. - This prepares the data for further processing within Gravitee or for forwarding to the next step. ### Mock Policy with {#request.content}: - Using {#request.content} dynamically retrieves the transformed XML payload from the request phase. - The Mock Policy then sends this XML back as the response to Postman. - Adding `Content-Type: application/xml` ensures the response is interpreted correctly. ## How to Test via Postman 1. Open **Postman**. 2. Create a new **POST** request with the URL: ``` https://gateway-internal.dev.apim.rewe.local/referenceapi/json-to-xml ``` 3. In the **Headers** section, add: - **Key:** `X-Gravitee-Api-Key` - **Value:** `89d582a0-63b7-447c-9582-a063b7f47c08` 4. In the **Body** section, add sample JSON data (please check example in Description part). 5. Click **Send**. 6. You should receive an XML response converted from the JSON input. paths: /json-to-xml: post: tags: - JSON to XML Policy summary: Convert JSON Employee Data to XML description: 'Transforms JSON input into XML using Gravitee policies. The response contains the converted XML output.' operationId: postConvertJson consumes: - application/json produces: - application/xml parameters: - in: body name: body description: | JSON input containing employee details. Example: ```json { "organization": { "employees": { "employee": { "id": 1001, "personalDetails": { "firstName": "Max", "lastName": "Mustermann", "dateOfBirth": "1985-07-20", "gender": "Male", "contact": { "email": "max.mustermann@example.com", "phone": "+1234567890" }, "address": { "street": "123 Hauptstraße", "city": "Munich", "state": "Bavaria", "zipCode": 80331, "country": "Germany" } }, "professionalDetails": { "designation": "Software Engineer", "department": "IT", "dateOfJoining": "2015-06-15", "salary": { "currency": "USD", "content": 90000 }, "skills": { "skill": [ "Java", "Python", "SQL" ] } } } } } } ``` required: true schema: type: string responses: '200': description: Successfully transformed JSON to XML examples: application/xml: | 1001 Max Mustermann 1985-07-20 Male max.mustermann@example.com +1234567890
123 Hauptstraße Munich Bavaria 80331 Germany
Software Engineer IT 2015-06-15 USD90000 Java Python SQL