Search in sources :

Example 11 with AnnotationAttachmentNode

use of org.ballerinalang.model.tree.AnnotationAttachmentNode in project ballerina by ballerina-lang.

the class SwaggerServiceMapper method createExternalDocModel.

/**
 * Creates external docs swagger definition.
 * @param annotationAttributeValue The ballerina annotation attribute value for external docs.
 * @param swagger The swagger definition which the external docs needs to be build on.
 */
private void createExternalDocModel(AnnotationAttachmentAttributeValueNode annotationAttributeValue, Swagger swagger) {
    if (null != annotationAttributeValue) {
        AnnotationAttachmentNode externalDocAnnotationAttachment = (AnnotationAttachmentNode) annotationAttributeValue.getValue();
        Map<String, AnnotationAttachmentAttributeValueNode> externalDocAttributes = this.listToMap(externalDocAnnotationAttachment);
        ExternalDocs externalDocs = new ExternalDocs();
        if (externalDocAttributes.containsKey("description")) {
            externalDocs.setDescription(this.getStringLiteralValue(externalDocAttributes.get("description")));
        }
        if (externalDocAttributes.containsKey("url")) {
            externalDocs.setUrl(this.getStringLiteralValue(externalDocAttributes.get("url")));
        }
        swagger.setExternalDocs(externalDocs);
    }
}
Also used : AnnotationAttachmentAttributeValueNode(org.ballerinalang.model.tree.expressions.AnnotationAttachmentAttributeValueNode) ExternalDocs(io.swagger.models.ExternalDocs) AnnotationAttachmentNode(org.ballerinalang.model.tree.AnnotationAttachmentNode)

Example 12 with AnnotationAttachmentNode

use of org.ballerinalang.model.tree.AnnotationAttachmentNode in project ballerina by ballerina-lang.

the class ServiceProtoBuilder method process.

@Override
public void process(ServiceNode serviceNode, List<AnnotationAttachmentNode> annotations) {
    for (AnnotationAttachmentNode annotationNode : annotations) {
        if (ANN_MESSAGE_LISTENER.equals(annotationNode.getAnnotationName().getValue())) {
            return;
        }
    }
    try {
        File fileDefinition = ServiceProtoUtils.generateProtoDefinition(serviceNode);
        ServiceConfiguration serviceConfig = ServiceProtoUtils.getServiceConfiguration(serviceNode);
        ServiceProtoUtils.writeServiceFiles(fileDefinition, serviceNode.getName().getValue(), serviceConfig.isGenerateClientConnector());
    } catch (GrpcServerException e) {
        dlog.logDiagnostic(Diagnostic.Kind.WARNING, serviceNode.getPosition(), e.getMessage());
    }
}
Also used : ServiceConfiguration(org.ballerinalang.net.grpc.config.ServiceConfiguration) File(org.ballerinalang.net.grpc.proto.definition.File) AnnotationAttachmentNode(org.ballerinalang.model.tree.AnnotationAttachmentNode) GrpcServerException(org.ballerinalang.net.grpc.exception.GrpcServerException)

Example 13 with AnnotationAttachmentNode

use of org.ballerinalang.model.tree.AnnotationAttachmentNode in project ballerina by ballerina-lang.

the class ServiceProtoUtils method getServiceConfiguration.

static ServiceConfiguration getServiceConfiguration(ServiceNode serviceNode) {
    String rpcEndpoint = null;
    boolean clientStreaming = false;
    boolean serverStreaming = false;
    boolean generateClientConnector = false;
    for (AnnotationAttachmentNode annotationNode : serviceNode.getAnnotationAttachments()) {
        if (!ServiceProtoConstants.ANN_SERVICE_CONFIG.equals(annotationNode.getAnnotationName().getValue())) {
            continue;
        }
        if (annotationNode.getExpression() instanceof BLangRecordLiteral) {
            List<BLangRecordLiteral.BLangRecordKeyValue> attributes = ((BLangRecordLiteral) annotationNode.getExpression()).getKeyValuePairs();
            for (BLangRecordLiteral.BLangRecordKeyValue attributeNode : attributes) {
                String attributeName = attributeNode.getKey().toString();
                String attributeValue = attributeNode.getValue() != null ? attributeNode.getValue().toString() : null;
                switch(attributeName) {
                    case ServiceProtoConstants.SERVICE_CONFIG_RPC_ENDPOINT:
                        {
                            rpcEndpoint = attributeValue != null ? attributeValue : null;
                            break;
                        }
                    case ServiceProtoConstants.SERVICE_CONFIG_CLIENT_STREAMING:
                        {
                            clientStreaming = attributeValue != null && Boolean.parseBoolean(attributeValue);
                            break;
                        }
                    case ServiceProtoConstants.SERVICE_CONFIG_SERVER_STREAMING:
                        {
                            serverStreaming = attributeValue != null && Boolean.parseBoolean(attributeValue);
                            break;
                        }
                    case ServiceProtoConstants.SERVICE_CONFIG_GENERATE_CLIENT:
                        {
                            generateClientConnector = attributeValue != null && Boolean.parseBoolean(attributeValue);
                            break;
                        }
                    default:
                        {
                            break;
                        }
                }
            }
        }
    }
    return new ServiceConfiguration(rpcEndpoint, clientStreaming, serverStreaming, generateClientConnector);
}
Also used : ServiceConfiguration(org.ballerinalang.net.grpc.config.ServiceConfiguration) BLangRecordLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral) AnnotationAttachmentNode(org.ballerinalang.model.tree.AnnotationAttachmentNode)

Example 14 with AnnotationAttachmentNode

use of org.ballerinalang.model.tree.AnnotationAttachmentNode in project ballerina by ballerina-lang.

the class ClientGeneratorPlugin method process.

@Override
public void process(ServiceNode serviceNode, List<AnnotationAttachmentNode> annotations) {
    CodeGenerator codegen = new CodeGenerator();
    PrintStream err = System.err;
    AnnotationAttachmentNode config = GeneratorUtils.getAnnotationFromList("ClientConfig", GeneratorConstants.SWAGGER_PKG_ALIAS, annotations);
    // Generate client only if requested by providing the client config annotation
    if (isClientGenerationEnabled(config)) {
        try {
            ClientContextHolder context = ClientContextHolder.buildContext(serviceNode, endpoints);
            codegen.writeGeneratedSource(GeneratorConstants.GenType.CLIENT, context, getOutputFilePath(serviceNode));
        } catch (CodeGeneratorException e) {
            err.println("Client code was not generated: " + e.getMessage());
        }
    }
}
Also used : PrintStream(java.io.PrintStream) CodeGeneratorException(org.ballerinalang.code.generator.exception.CodeGeneratorException) CodeGenerator(org.ballerinalang.code.generator.CodeGenerator) ClientContextHolder(org.ballerinalang.code.generator.model.ClientContextHolder) AnnotationAttachmentNode(org.ballerinalang.model.tree.AnnotationAttachmentNode)

Example 15 with AnnotationAttachmentNode

use of org.ballerinalang.model.tree.AnnotationAttachmentNode in project ballerina by ballerina-lang.

the class WebSubServiceCompilerPlugin method process.

@Override
public void process(ServiceNode serviceNode, List<AnnotationAttachmentNode> annotations) {
    for (AnnotationAttachmentNode annotation : annotations) {
        if (!HttpConstants.PROTOCOL_PACKAGE_HTTP.equals(((BLangAnnotationAttachment) annotation).annotationSymbol.pkgID.name.value)) {
            continue;
        }
        if (annotation.getAnnotationName().getValue().equals(WebSubSubscriberConstants.ANN_NAME_WEBSUB_SUBSCRIBER_SERVICE_CONFIG)) {
            handleServiceConfigAnnotation(serviceNode, (BLangAnnotationAttachment) annotation);
        }
    }
    if (HttpConstants.HTTP_SERVICE_TYPE.equals(serviceNode.getServiceTypeStruct().getTypeName().getValue())) {
        List<BLangResource> resources = (List<BLangResource>) serviceNode.getResources();
        resources.forEach(resource -> ResourceSignatureValidator.validate(resource.getParameters()));
    }
}
Also used : BLangResource(org.wso2.ballerinalang.compiler.tree.BLangResource) List(java.util.List) AnnotationAttachmentNode(org.ballerinalang.model.tree.AnnotationAttachmentNode)

Aggregations

AnnotationAttachmentNode (org.ballerinalang.model.tree.AnnotationAttachmentNode)35 AnnotationAttachmentAttributeValueNode (org.ballerinalang.model.tree.expressions.AnnotationAttachmentAttributeValueNode)18 HashMap (java.util.HashMap)12 List (java.util.List)12 LinkedList (java.util.LinkedList)11 ExternalDocs (io.swagger.models.ExternalDocs)10 Map (java.util.Map)9 Collectors (java.util.stream.Collectors)9 Lists (com.google.common.collect.Lists)8 Scheme (io.swagger.models.Scheme)8 Swagger (io.swagger.models.Swagger)8 ArrayList (java.util.ArrayList)8 Optional (java.util.Optional)8 AnnotationAttachmentAttributeNode (org.ballerinalang.model.tree.expressions.AnnotationAttachmentAttributeNode)7 LiteralNode (org.ballerinalang.model.tree.expressions.LiteralNode)7 ArrayProperty (io.swagger.models.properties.ArrayProperty)6 BooleanProperty (io.swagger.models.properties.BooleanProperty)6 IntegerProperty (io.swagger.models.properties.IntegerProperty)6 Property (io.swagger.models.properties.Property)6 StringProperty (io.swagger.models.properties.StringProperty)6