A machine-readable version of the Ordering End-to-End data feed and fulfillment API definitions are made available to generate client source code and validate the structure of JSON data. This allows you to spend more time in developing application capabilities and business logic required for the integration.
In this example, we use quicktype CLI to generate an easy-to-use client library.
Download the JSON Schemas
These machine-readable versions of data feeds and APIs are needed for code generation and validation.
Generate codes
Quicktype can be used to regenerate codes when APIs are changed so you can simply update the affected application code. QuickType supports C++, Java, JavaScript, Python and other programming languages.
You can also use other available code generator tools that support JSON Schema definitions to generate the client libraries.
Use Node package manager (npm) to install quicktype in the project directory for your Ordering End-to-End integration.
npm install quicktype
TypeScript
- Generate client source code for Ordering End-to-End data feeds.
quicktype --lang typescript --src-lang schema inventory-v2-json-schema.json#top_level_definitions/ -o ./owg-inventory.ts
- Generate client source code for the fulfillment API.
quicktype --lang typescript --src-lang schema fulfillment-actions-json-schema.json#top_level_definitions/ -o ./owg-fulfillment.ts
- Generate client source code for the real-time updates API.
quicktype --lang typescript --src-lang schema realtime-updates-json-schema.json#top_level_definitions/ -o ./owg-realtime-updates.ts
- Copy the generated files to your workspace and implement your business logic.
Usage and validation
Example of creating entities and converting them to JSON:
import { Convert, Fee, OperationHours, Restaurant, Service, ServiceArea, ServiceHours, Menu, MenuSection, Availability, MenuItem, MenuItemOption, MenuItemOffer, FeeType, FeeTypeEnum, RestaurantType } from './owg-inventory'; const restaurant: Restaurant = { "@id": "McDonalds", "@type": RestaurantType.Restaurant, "addressCountry": "US", "addressLocality": "123 Local", "addressRegion": "Region", "name": "MacDonald's", "postalCode": "1234", "streetAddress": "123", "telephone": "+15552999983", "url": "https://example.com", "dateModified": new Date() } const fee: Fee = { "@id": "123", "@type": FeeTypeEnum.Fee, "priceCurrency": "US", "serviceId": "123", "feeType": FeeType.Delivery, "dateModified": new Date() } const restaurantJson: string = Convert.restaurantToJson(restaurant); const feeJson: string = Convert.feeToJson(fee);
Java
- Generate client source code for Ordering End-to-End data feeds.
quicktype --lang java --src-lang schema inventory-v2-json-schema.json#top_level_definitions/ -o ./java/ --no-date-times --package com.example.inventory
- Generate client source code for the fulfillment API.
quicktype --lang java --src-lang schema fulfillment-actions-json-schema.json#top_level_definitions/ -o ./java/ --no-date-times --package com.example.fulfillment
- Generate client source code for the real-time updates API.
quicktype --lang java --src-lang schema realtime-updates-json-schema.json#top_level_definitions/ -o ./java/ --no-date-times --package com.example.realtime
- Copy the generated files to your workspace and implement your business logic.
Usage and validation
Example of creating entities and converting them to JSON:
package com.example; import com.example.inventory.Converter; import com.example.inventory.Fee; import com.example.inventory.FeeType; import com.example.inventory.Restaurant; import com.example.inventory.RestaurantType; public class FoodOrderingResponse { public static void main(String[] args) { Restaurant restaurant = new Restaurant(); restaurant.setId("MacDonalds"); restaurant.setType(RestaurantType.RESTAURANT); restaurant.setAddressCountry("US"); restaurant.setAddressLocality("123 Local"); restaurant.setAddressRegion("Region"); restaurant.setName("MacDonald's"); restaurant.setPostalCode("1234"); restaurant.setStreetAddress("123"); restaurant.setTelephone("+15552999983"); restaurant.setUrl("https://example.com"); restaurant.setDateModified("2022-09-19T13:10:00.000Z"); Fee fee = new Fee(); fee.setId("123"); fee.setType(FeeTypeEnum.FEE); fee.setPriceCurrency("US"); fee.setServiceId("123"); fee.setFeeType(FeeType.DELIVERY); fee.setDateModified("2022-09-19T13:13:10.000Z"); String restaurantJson = Converter.RestaurantToJsonString(restaurant); String feeJson = Converter.FeeToJsonString(fee); } }
JavaScript
- Generate client source code for Ordering End-to-End data feeds.
quicktype --lang javascript --src-lang schema inventory-v2-json-schema.json#top_level_definitions/ -o owg-inventory.js
- Generate client source code for the fulfillment API.
quicktype --lang javascript --src-lang schema fulfillment-actions-json-schema.json#top_level_definitions/ -o owg-fulfillment.js
- Generate client source code for the real-time updates API.
quicktype --lang javascript --src-lang schema realtime-updates-json-schema.json#top_level_definitions/ -o owg-realtime-updates.js
- Copy the generated files to your workspace and implement your business logic.
Usage and validation
Example of creating entities and converting them to JSON:
// Converts JSON strings to/from your types // and asserts the results of JSON.parse at runtime const Convert = require("./owg-inventory"); const restaurantJson = Convert.restaurantToJson({ "@id": "McDonalds", "@type": 'Restaurant', "addressCountry": "US", "addressLocality": "123 Local", "addressRegion": "Region", "name": "MacDonald's", "postalCode": "1234", "streetAddress": "123", "telephone": "+15552999983", "url": "https://example.com", "dateModified": new Date() })); const restaurant = Convert.toRestaurant(restaurantJson);
Python
- Generate client source code for Ordering End-to-End data feeds.
quicktype --lang python --src-lang schema inventory-v2-json-schema.json#top_level_definitions/ -o owg_inventory.py
- Generate client source code for the fulfillment API.
quicktype --lang python --src-lang schema fulfillment-actions-json-schema.json#top_level_definitions/ -o owg_fulfillment.py
- Generate client source code for the real-time updates API.
quicktype --lang python --src-lang schema realtime-updates-json-schema.json#top_level_definitions/ -o owg_realtime_updates.py
- Copy the generated files to your workspace and implement your business logic.
Usage
Example of creating entities and converting them to JSON:
import json import owg_inventory restaurant: owg_inventory.Restaurant = owg_inventory.restaurant_from_dict({ "@id": "McDonalds", "@type": "Restaurant", "addressCountry": "US", "addressLocality": "123 Local", "addressRegion": "Region", "name": "MacDonald's", "postalCode": "1234", "streetAddress": "123", "telephone": "+15552999983", "url": "https://example.com", "dateModified": "2022-09-19T13:10:00.000Z" }) restaurant_json: str = json.dumps(owg_inventory.restaurant_to_dict(restaurant))