Search in sources :

Example 1 with ActionDoc

use of org.ballerinalang.docgen.model.ActionDoc in project ballerina by ballerina-lang.

the class Generator method createDocForNode.

/**
 * Create documentation for actions.
 * @param actionNode ballerina action node.
 * @return documentation for actions.
 */
public static ActionDoc createDocForNode(BLangAction actionNode) {
    String actionName = actionNode.getName().value;
    List<Variable> parameters = new ArrayList<>();
    List<Variable> returnParams = new ArrayList<>();
    // Iterate through the parameters
    if (actionNode.getParameters().size() > 0) {
        for (BLangVariable param : actionNode.getParameters()) {
            String dataType = type(param);
            String desc = paramAnnotation(actionNode, param);
            Variable variable = new Variable(param.getName().value, dataType, desc);
            parameters.add(variable);
        }
    }
    // Iterate through the return types
    if (actionNode.getReturnParameters().size() > 0) {
        for (int i = 0; i < actionNode.getReturnParameters().size(); i++) {
            BLangVariable returnParam = actionNode.getReturnParameters().get(i);
            String dataType = type(returnParam);
            String desc = returnParamAnnotation(actionNode, i);
            Variable variable = new Variable(returnParam.getName().value, dataType, desc);
            returnParams.add(variable);
        }
    }
    return new ActionDoc(actionName, description(actionNode), new ArrayList<>(), parameters, returnParams);
}
Also used : ActionDoc(org.ballerinalang.docgen.model.ActionDoc) BLangVariable(org.wso2.ballerinalang.compiler.tree.BLangVariable) Variable(org.ballerinalang.docgen.model.Variable) ArrayList(java.util.ArrayList) BLangVariable(org.wso2.ballerinalang.compiler.tree.BLangVariable)

Example 2 with ActionDoc

use of org.ballerinalang.docgen.model.ActionDoc in project ballerina by ballerina-lang.

the class HtmlDocTest method testConnectorPropertiesExtracted.

@Test(description = "Connector properties should be available via construct", enabled = false)
public void testConnectorPropertiesExtracted() throws Exception {
    BLangPackage bLangPackage = createPackage("package x.y; " + "@Description { value:\"Http client connector for outbound HTTP requests\"}\n" + "@Param { value:\"serviceUri: Url of the service\" }\n" + "@Param { value:\"n: connector options\" }" + "connector HttpClient (string serviceUri, int n) {" + "@Description { value:\"The POST action implementation of the HTTP ConnectorDoc\"}\n" + "@Param { value:\"path: Resource path \" }\n" + "@Param { value:\"req: An HTTP Request struct\" }\n" + "@Return { value:\"The response message\" }\n" + "@Return { value:\"Error occured during HTTP client invocation\" }\n" + "action post(string path, string req) (string, int) { return \"value within filter\"; }}");
    ConnectorDoc connectorDoc = Generator.createDocForNode(bLangPackage.getConnectors().get(0));
    Assert.assertEquals(connectorDoc.name, "HttpClient", "Connector name should be extracted");
    Assert.assertEquals(connectorDoc.description, "Http client connector for outbound HTTP requests", "Description of the connector should be extracted");
    Assert.assertEquals(connectorDoc.parameters.get(0).name, "serviceUri", "Parameter name should be extracted");
    Assert.assertEquals(connectorDoc.parameters.get(0).dataType, "string", "Parameter type should be extracted");
    Assert.assertEquals(connectorDoc.parameters.get(0).description, "Url of the service", "Description of the parameter type should be extracted");
    // For actions inside the connector
    ActionDoc actionDoc = (ActionDoc) connectorDoc.children.get(0);
    Assert.assertEquals(actionDoc.name, "post", "Action name should be extracted");
    Assert.assertEquals(actionDoc.description, "The POST action implementation of the HTTP ConnectorDoc", "Description of the action should be extracted");
    Assert.assertEquals(actionDoc.parameters.get(0).name, "path", "Parameter name should be extracted");
    Assert.assertEquals(actionDoc.parameters.get(0).dataType, "string", "Parameter type should be extracted");
    Assert.assertEquals(actionDoc.parameters.get(0).description, "Resource path", "Description of the " + "parameter should be extracted");
    Assert.assertEquals(actionDoc.returnParams.get(1).dataType, "int", "Return parameter type should be extracted");
    Assert.assertEquals(actionDoc.returnParams.get(1).description, "Error occured during HTTP client invocation", "Description of the return parameter should be extracted");
}
Also used : ActionDoc(org.ballerinalang.docgen.model.ActionDoc) BLangPackage(org.wso2.ballerinalang.compiler.tree.BLangPackage) ConnectorDoc(org.ballerinalang.docgen.model.ConnectorDoc) Test(org.testng.annotations.Test)

Aggregations

ActionDoc (org.ballerinalang.docgen.model.ActionDoc)2 ArrayList (java.util.ArrayList)1 ConnectorDoc (org.ballerinalang.docgen.model.ConnectorDoc)1 Variable (org.ballerinalang.docgen.model.Variable)1 Test (org.testng.annotations.Test)1 BLangPackage (org.wso2.ballerinalang.compiler.tree.BLangPackage)1 BLangVariable (org.wso2.ballerinalang.compiler.tree.BLangVariable)1