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);
}
}
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());
}
}
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);
}
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());
}
}
}
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()));
}
}
Aggregations