// REQUEST DEFINITION
// *****************************
ApiDocRequest apiDocRequest = new ApiDocRequest();
ApiDocAttribute reqServiceId = new ApiDocAttribute();
reqServiceId.setFieldName(ServiceConfigurationAPI.API_SERVICE_ID);
reqServiceId.addFieldValues(new ApiDocFieldValue("[identifier]",
"A valid service identifier."));
reqServiceId.setExample("123");
apiDocRequest.addAttribute(reqServiceId);
ApiDocAttribute reqServiceName = new ApiDocAttribute();
reqServiceName
.setFieldName(ServiceConfigurationAPI.API_SERVICE_NAME);
reqServiceName.addFieldValues(new ApiDocFieldValue("[string]",
"A valid service name."));
reqServiceName.setExample("My Service Name");
apiDocRequest.addAttribute(reqServiceName);
// SCHEMA
ApiDocAttribute reqServiceSchema = new ApiDocAttribute();
reqServiceSchema
.setFieldName(ServiceConfigurationAPI.API_SERVICE_SCHEMA);
reqServiceSchema.addFieldValues(new ApiDocFieldValue("[string]",
"A valid JSON Schema definition."));
reqServiceSchema
.setExample("{\"type\":\"object\",\"$schema\": \"http://json-schema.org/draft-03/schema\",\"id\": \"#\",\"required\":false,\"properties\":{ \"address\": { \"type\":\"object\", \"id\": \"address\", \"required\":false, \"properties\":{ \"streetAddress\": { \"type\":\"string\", \"id\": \"streetAddress\", \"required\":false } } } }}");
apiDocRequest.addAttribute(reqServiceSchema);
ApiDocAttribute reqServiceSchemaEnableFlag = new ApiDocAttribute();
reqServiceSchemaEnableFlag
.setFieldName(ServiceConfigurationAPI.API_SERVICE_SCHEMA_ENABLE_FLAG);
reqServiceSchemaEnableFlag
.addFieldValues(new ApiDocFieldValue(
"[boolean]",
"Set to true for the service to validate each Service Scenario JSON response with the provided JSON Schema."));
reqServiceSchemaEnableFlag.setExample("true");
apiDocRequest.addAttribute(reqServiceSchemaEnableFlag);
// REQUEST INSPECTOR RULES
ApiDocAttribute reqInspectorRules = new ApiDocAttribute();
reqInspectorRules
.setFieldName(ServiceConfigurationAPI.API_SERVICE_REQUEST_INSPECTOR_RULES);
reqInspectorRules.addFieldValues(new ApiDocFieldValue("[string]",
"Request evaluation rules in JSON. "));
reqInspectorRules.setExample("");
apiDocRequest.addAttribute(reqInspectorRules);
ApiDocAttribute reqInspectorRulesEnableFlag = new ApiDocAttribute();
reqInspectorRulesEnableFlag
.setFieldName(ServiceConfigurationAPI.API_SERVICE_REQUEST_INSPECTOR_RULES_ENABLE_FLAG);
reqInspectorRulesEnableFlag
.addFieldValues(new ApiDocFieldValue(
"[boolean]",
"Set to true for the service to validate each incoming request to ensure the appropriate parameters are being passed."));
reqInspectorRulesEnableFlag.setExample("true");
apiDocRequest.addAttribute(reqInspectorRulesEnableFlag);
ApiDocAttribute reqScenarioId = new ApiDocAttribute();
reqScenarioId
.setFieldName(ServiceConfigurationAPI.API_SERVICE_SCENARIO_ID);
reqScenarioId.addFieldValues(new ApiDocFieldValue("[identifier]",
"A valid service scenario identifier."));
reqScenarioId.setExample("123");
apiDocRequest.addAttribute(reqScenarioId);
ApiDocAttribute reqScenarioName = new ApiDocAttribute();
reqScenarioName
.setFieldName(ServiceConfigurationAPI.API_SERVICE_NAME);
reqScenarioName.addFieldValues(new ApiDocFieldValue("[string]",
"A valid service scenario name."));
reqScenarioName.setExample("My Service Scenario Name");
apiDocRequest.addAttribute(reqScenarioName);
ApiDocAttribute reqHangtime = new ApiDocAttribute();
reqHangtime
.setFieldName(ServiceConfigurationAPI.API_SERVICE_HANGTIME);
reqHangtime.addFieldValues(new ApiDocFieldValue("[int]",
"Hang time in milliseconds."));
reqHangtime.setExample("500");
apiDocRequest.addAttribute(reqHangtime);
ApiDocAttribute transientSet = new ApiDocAttribute();
transientSet
.setFieldName(ServiceConfigurationAPI.API_TRANSIENT_STATE);
transientSet
.addFieldValues(new ApiDocFieldValue(
"[boolean]",
"If available and set to 'true', then all settings in this call will be in-memory only, not persisted to the file system. Otherwise, state settings will be written to the file system."));
transientSet.setExample("true");
apiDocRequest.addAttribute(transientSet);
ApiDocAttribute reqAttributeAction = new ApiDocAttribute();
reqAttributeAction
.setFieldName(ServiceConfigurationAPI.API_SERVICE_RESPONSE_TYPE);
reqAttributeAction
.addFieldValues(new ApiDocFieldValue(
ServiceConfigurationAPI.API_SERVICE_RESPONSE_TYPE_VALUE_DYNAMIC,
"Sets service to respond as dynamic."));
reqAttributeAction
.addFieldValues(new ApiDocFieldValue(
ServiceConfigurationAPI.API_SERVICE_RESPONSE_TYPE_VALUE_PROXY,
"Sets service to act as a proxy."));
reqAttributeAction
.addFieldValues(new ApiDocFieldValue(
ServiceConfigurationAPI.API_SERVICE_RESPONSE_TYPE_VALUE_STATIC,
"Sets service to respond with a static response"));
apiDocRequest.addAttribute(reqAttributeAction);
apiDocService.setApiRequest(apiDocRequest);
// *****************************
// RESPONSE DEFINITION
// *****************************
ApiDocResponse apiResponse = new ApiDocResponse();
// Building a JSON RESPONSE example
try {
JSONObject jsonResponseObject = new JSONObject();
JSONObject jsonResultObject = new JSONObject();
jsonResultObject
.put("success",
"Some informative coaching message. If success isn't a value, then maybe you have a 'fail' message.");
jsonResultObject.put(ServiceConfigurationAPI.API_SERVICE_ID,
"1234");
jsonResultObject.put(ServiceConfigurationAPI.API_SERVICE_NAME,
"Some service name");
jsonResultObject.put(
ServiceConfigurationAPI.API_SERVICE_SCHEMA,
"JSON Schema");
jsonResultObject
.put(ServiceConfigurationAPI.API_SERVICE_SCENARIO_ID,
"5678");
jsonResultObject.put(
ServiceConfigurationAPI.API_SERVICE_SCENARIO_NAME,
"Some scenario name");
jsonResultObject
.put(ServiceConfigurationAPI.API_SERVICE_RESPONSE_TYPE,
ServiceConfigurationAPI.API_SERVICE_RESPONSE_TYPE_VALUE_PROXY);
jsonResultObject.put(
ServiceConfigurationAPI.API_SERVICE_HANGTIME, "500");
jsonResultObject.put(
ServiceConfigurationAPI.API_TRANSIENT_STATE, "true");
jsonResponseObject.put("result", jsonResultObject);
apiResponse.setExample(jsonResponseObject.toString());
} catch (Exception e) {
log.error("Unabel to build a sample JSON message. ", e);
}
// Response attribute 'planId'
ApiDocAttribute resAttributePlanId = new ApiDocAttribute();
resAttributePlanId
.setFieldName(ServiceConfigurationAPI.API_SERVICE_ID);
resAttributePlanId.setFieldDescription("Identifier of a Service");
apiResponse.addAttribute(resAttributePlanId);
// Response attribute 'planName'
ApiDocAttribute resAttributePlanName = new ApiDocAttribute();
resAttributePlanName
.setFieldName(ServiceConfigurationAPI.API_SERVICE_NAME);
resAttributePlanName.setFieldDescription("Name of a Service");
apiResponse.addAttribute(resAttributePlanName);
// Response attribute 'success'
ApiDocAttribute resAttributeSuccess = new ApiDocAttribute();
resAttributeSuccess.setFieldName("success");
resAttributeSuccess
.setFieldDescription("Successfully set, deleted, or saved a plan. You get 'fail' or 'success', not both.");
apiResponse.addAttribute(resAttributeSuccess);
ApiDocAttribute resAttributeFail = new ApiDocAttribute();
resAttributeFail.setFieldName("fail");
resAttributeFail
.setFieldDescription("Failed to set, delete, or save a plan. You get 'fail' or 'success', not both.");
apiResponse.addAttribute(resAttributeFail);
apiDocService.setApiResponse(apiResponse);
apiStore.saveOrUpdateService(apiDocService);