Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,7 @@ public List<ParameterData> getFunctionParameters(int functionId) {
rs.getString("description"),
rs.getString("label"),
rs.getBoolean("optional"),
false,
rs.getString("import_statements"),
new ArrayList<>(),
null
Expand Down Expand Up @@ -507,6 +508,7 @@ ParameterData build() {
description,
label,
optional,
false,
importStatements,
typeMembers,
null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,15 @@ public FunctionData build() {
}
}

// Check the index before attempting external package resolution.
// This avoids unnecessary package pulls and resolution failures for already-indexed symbols.
if (enableIndex) {
Optional<FunctionData> indexedResult = getFunctionFromIndex();
if (indexedResult.isPresent()) {
return indexedResult.get();
}
}

// Assume the package is from an external library, and pull the package if not available locally
if (semanticModel == null) {
if (moduleInfo.version() == null) {
Expand All @@ -397,14 +406,6 @@ public FunctionData build() {
}
}

// Check if the function is in the index
if (enableIndex) {
Optional<FunctionData> indexedResult = getFunctionFromIndex();
if (indexedResult.isPresent()) {
return indexedResult.get();
}
}

// Fetch the semantic model if not provided
if (semanticModel == null) {
deriveSemanticModel();
Expand Down Expand Up @@ -792,6 +793,7 @@ private Map<String, ParameterData> getParameters(ParameterSymbol paramSymbol,
String paramName = paramSymbol.getName().orElse("");
String paramDescription = documentationMap.get(paramName);
ParameterData.Kind parameterKind = ParameterData.Kind.fromKind(paramSymbol.paramKind());
boolean deprecated = isDeprecated(paramSymbol.annotAttachments());
String paramType;
boolean optional = true;
String placeholder;
Expand Down Expand Up @@ -834,7 +836,8 @@ private Map<String, ParameterData> getParameters(ParameterSymbol paramSymbol,
typeSymbol = paramForTypeInfer.typeSymbol();
parameters.put(paramName, ParameterData.from(paramName, paramDescription,
getLabel(paramSymbol.annotAttachments(), paramName), paramType, placeholder, defaultValue,
ParameterData.Kind.PARAM_FOR_TYPE_INFER, optional, importStatements, typeSymbol));
ParameterData.Kind.PARAM_FOR_TYPE_INFER, optional, deprecated, importStatements,
typeSymbol));
return parameters;
}
}
Expand All @@ -845,7 +848,7 @@ private Map<String, ParameterData> getParameters(ParameterSymbol paramSymbol,
}
ParameterData parameterData = ParameterData.from(paramName, paramDescription,
getLabel(paramSymbol.annotAttachments(), paramName), paramType, placeholder, defaultValue,
parameterKind, optional,
parameterKind, optional, deprecated,
importStatements, typeSymbol);
parameters.put(paramName, parameterData);
addParameterMemberTypes(typeSymbol, parameterData, union);
Expand Down Expand Up @@ -970,9 +973,10 @@ private Map<String, ParameterData> getIncludedRecordParams(RecordTypeSymbol reco
resolvedPackage, document);
String paramType = getTypeSignature(typeSymbol);
boolean optional = recordFieldSymbol.isOptional() || recordFieldSymbol.hasDefaultValue();
boolean deprecated = isDeprecated(recordFieldSymbol.annotAttachments());
ParameterData parameterData = ParameterData.from(paramName, documentationMap.get(paramName),
getLabel(recordFieldSymbol.annotAttachments(), paramName),
paramType, placeholder, defaultValue, ParameterData.Kind.INCLUDED_FIELD, optional,
paramType, placeholder, defaultValue, ParameterData.Kind.INCLUDED_FIELD, optional, deprecated,
getImportStatements(typeSymbol), typeSymbol);
parameters.put(paramName, parameterData);
addParameterMemberTypes(typeSymbol, parameterData, union);
Expand All @@ -982,7 +986,7 @@ private Map<String, ParameterData> getIncludedRecordParams(RecordTypeSymbol reco
String placeholder = DefaultValueGeneratorUtil.getDefaultValueForType(typeSymbol);
parameters.put("Additional Values", new ParameterData(0, "Additional Values",
paramType, ParameterData.Kind.INCLUDED_RECORD_REST, placeholder, null,
"Capture key value pairs", null, true, getImportStatements(typeSymbol),
"Capture key value pairs", null, true, false, getImportStatements(typeSymbol),
new ArrayList<>(), typeSymbol));
});
return parameters;
Expand Down Expand Up @@ -1164,6 +1168,20 @@ private String getLabel(List<AnnotationAttachmentSymbol> annotationAttachmentSym
return toTitleCase(output);
}

private boolean isDeprecated(List<AnnotationAttachmentSymbol> annotationAttachmentSymbols) {
if (annotationAttachmentSymbols == null) {
return false;
}
for (AnnotationAttachmentSymbol annotAttachment : annotationAttachmentSymbols) {
AnnotationSymbol annotationSymbol = annotAttachment.typeDescriptor();
Optional<String> optName = annotationSymbol.getName();
if (optName.isPresent() && optName.get().equals("deprecated")) {
return true;
}
}
return false;
}

/**
* Converts a camelCase or PascalCase string to Title Case with spaces, including before numbers. E.g., "targetType"
* -> "Target Type", "http1Config" -> "Http1 Config", "account_name" -> "Account Name", etc.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
* @param description the description of the parameter
* @param label the label of the parameter
* @param optional whether the parameter is optional
* @param deprecated whether the parameter is deprecated
* @param importStatements import statements of the dependent types
* @param typeMembers the member types of the parameter
* @param typeSymbol the type symbol of the parameter
Expand All @@ -53,26 +54,29 @@ public record ParameterData(
String description,
String label,
boolean optional,
boolean deprecated,
String importStatements,
List<ParameterMemberTypeData> typeMembers,
io.ballerina.compiler.api.symbols.TypeSymbol typeSymbol) {

public static ParameterData from(String name, String type, Kind kind, String placeholder,
String description, boolean optional) {
return new ParameterData(0, name, type, kind, placeholder, null, description, null, optional,
return new ParameterData(0, name, type, kind, placeholder, null, description, null, optional, false,
null, new ArrayList<>(), null);
}

public static ParameterData from(String name, String type, Kind kind, String placeholder,
String description, boolean optional, TypeSymbol typeSymbol) {
return new ParameterData(0, name, type, kind, placeholder, null, description, null, optional,
return new ParameterData(0, name, type, kind, placeholder, null, description, null, optional, false,
null, new ArrayList<>(), typeSymbol);
}

public static ParameterData from(String name, String description, String label, String type, String placeholder,
String defaultValue, Kind kind, boolean optional, String importStatements,
String defaultValue, Kind kind, boolean optional, boolean deprecated,
String importStatements,
TypeSymbol typeSymbol) {
return new ParameterData(0, name, type, kind, placeholder, defaultValue, description, label, optional,
deprecated,
importStatements, new ArrayList<>(), typeSymbol);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,7 @@ ParameterData build() {
description,
null,
optional,
false,
importStatements,
typeMembers,
null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import io.ballerina.projects.Document;
import io.ballerina.projects.Project;
import io.ballerina.servicemodelgenerator.extension.builder.function.DefaultFunctionBuilder;
import io.ballerina.servicemodelgenerator.extension.builder.function.FTPFunctionBuilder;
import io.ballerina.servicemodelgenerator.extension.builder.function.GraphqlFunctionBuilder;
import io.ballerina.servicemodelgenerator.extension.builder.function.HttpFunctionBuilder;
import io.ballerina.servicemodelgenerator.extension.builder.function.KafkaFunctionBuilder;
Expand All @@ -52,6 +53,7 @@
import java.util.function.Supplier;

import static io.ballerina.servicemodelgenerator.extension.util.Constants.DEFAULT;
import static io.ballerina.servicemodelgenerator.extension.util.Constants.FTP;
import static io.ballerina.servicemodelgenerator.extension.util.Constants.GRAPHQL;
import static io.ballerina.servicemodelgenerator.extension.util.Constants.HTTP;
import static io.ballerina.servicemodelgenerator.extension.util.Constants.KAFKA;
Expand All @@ -78,6 +80,7 @@ public class FunctionBuilderRouter {
put(SOLACE, SolaceFunctionBuilder::new);
put(MSSQL, MssqlCdcFunctionBuilder::new);
put(POSTGRESQL, PostgresqlCdcFunctionBuilder::new);
put(FTP, FTPFunctionBuilder::new);
}};

private static NodeBuilder<Function> getFunctionBuilder(String protocol) {
Expand Down
Loading
Loading