Search in sources :

Example 1 with ConnectorDoc

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

the class Generator method createDocForNode.

/**
 * Create documentation for connectors.
 * @param connectorNode ballerina connector node.
 * @return documentation for connectors.
 */
public static ConnectorDoc createDocForNode(BLangConnector connectorNode) {
    String connectorName = connectorNode.getName().value;
    List<Variable> parameters = new ArrayList<>();
    List<Documentable> actions = new ArrayList<>();
    // Iterate through the connector parameters
    if (connectorNode.getParameters().size() > 0) {
        for (BLangVariable param : connectorNode.getParameters()) {
            String dataType = type(param);
            String desc = paramAnnotation(connectorNode, param);
            Variable variable = new Variable(param.getName().value, dataType, desc);
            parameters.add(variable);
        }
    }
    // Iterate through the actions of the connectors
    if (connectorNode.getActions().size() > 0) {
        for (BLangAction action : connectorNode.getActions()) {
            actions.add(createDocForNode(action));
        }
    }
    return new ConnectorDoc(connectorName, description(connectorNode), actions, parameters);
}
Also used : BLangVariable(org.wso2.ballerinalang.compiler.tree.BLangVariable) Variable(org.ballerinalang.docgen.model.Variable) Documentable(org.ballerinalang.docgen.model.Documentable) ArrayList(java.util.ArrayList) ConnectorDoc(org.ballerinalang.docgen.model.ConnectorDoc) BLangVariable(org.wso2.ballerinalang.compiler.tree.BLangVariable) BLangAction(org.wso2.ballerinalang.compiler.tree.BLangAction)

Example 2 with ConnectorDoc

use of org.ballerinalang.docgen.model.ConnectorDoc 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

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