Skip to content
Open
Show file tree
Hide file tree
Changes from all 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 @@ -26,6 +26,7 @@
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.datatype.jdk8.Jdk8Module;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
Expand Down Expand Up @@ -90,6 +91,7 @@
import javax.tools.JavaCompiler;
import javax.tools.ToolProvider;
import org.apache.commons.lang3.StringUtils;
import org.jspecify.annotations.NonNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -394,6 +396,15 @@ private void checkAdditionalProperties(
if (schema.getExample() != null) {
if (Objects.equals(type, "string")) {
builder.add(".exampleValue($S)", schema.getExample());
} else if (Objects.equals(type, "array")) {
ArrayNode exampleArrayNode = (ArrayNode) schema.getExample();
Object[] exampleArray = new Object[exampleArrayNode.size()];

for (int i = 0; i < exampleArray.length; i++) {
exampleArray[i] = exampleArrayNode.get(i);
}

builder.add(".exampleValue($L)", exampleArray);
} else {
builder.add(".exampleValue($L)", schema.getExample());
}
Expand Down Expand Up @@ -1605,31 +1616,29 @@ private String getPackageName() {
}

private CodeBlock getParametersPropertiesCodeBlock(Operation operation, OpenAPI openAPI) {
List<Parameter> parameters = resolveParameters(operation.getParameters(), openAPI);
List<CodeBlock> codeBlocks = new ArrayList<>();
List<Parameter> parameters = operation.getParameters();

if (parameters != null) {
for (Parameter parameter : parameters) {
CodeBlock.Builder builder = CodeBlock.builder();
for (Parameter parameter : parameters) {
CodeBlock.Builder builder = CodeBlock.builder();

builder.add(
getSchemaCodeBlock(
parameter.getName(), parameter.getDescription(), parameter.getRequired(), null,
parameter.getSchema(), false, false, openAPI, false));
builder.add(
CodeBlock.of(
"""
.metadata(
$T.of(
"type", PropertyType.$L
)
)
""",
Map.class,
StringUtils.upperCase(parameter.getIn())));

codeBlocks.add(builder.build());
}
builder.add(
getSchemaCodeBlock(
parameter.getName(), parameter.getDescription(), parameter.getRequired(), null,
parameter.getSchema(), false, false, openAPI, false));
builder.add(
CodeBlock.of(
"""
.metadata(
$T.of(
"type", PropertyType.$L
)
)
""",
Map.class,
StringUtils.upperCase(parameter.getIn())));

codeBlocks.add(builder.build());
}

return codeBlocks.stream()
Expand Down Expand Up @@ -1736,6 +1745,55 @@ private CodeBlock getRefCodeBlock(
outputSchema, openAPI, bodySchema);
}

private List<Parameter> resolveParameters(List<Parameter> parameters, OpenAPI openAPI) {
if (parameters == null) {
return Collections.emptyList();
}

List<Parameter> resolvedParameters = new ArrayList<>();

parameters.forEach(explicitParameter -> {
if (explicitParameter.get$ref() == null) {
resolvedParameters.add(explicitParameter);

return;
}

resolvedParameters.add(getComponentParameter(openAPI, explicitParameter));
});

return resolvedParameters;
}

private static @NonNull Parameter getComponentParameter(OpenAPI openAPI, Parameter explicitParameter) {
Components components = openAPI.getComponents();

if (components == null) {
throw new IllegalArgumentException(
"Components section of spec misses. Unable to resolve " + explicitParameter.get$ref());
}

Map<String, Parameter> parameterDefinitions = components.getParameters();
String parameterName = getParameterNameFromComponentReference(explicitParameter);

if ((parameterDefinitions == null) || !parameterDefinitions.containsKey(parameterName)) {
throw new IllegalArgumentException(
"Components section of spec misses the parameter definition for " + explicitParameter.get$ref());
}

return parameterDefinitions.get(parameterName);
}

private static String getParameterNameFromComponentReference(Parameter parameter) {
String parameterReference = parameter.get$ref();

if (parameterReference.startsWith("#/components/parameters/")) {
parameterReference = parameterReference.substring("#/components/parameters/".length());
}

return parameterReference;
}

@SuppressWarnings({
"rawtypes"
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ title: "Initial Setup"
This section provides a clear step-by-step guide for setting up a new component in your project, ensuring it is properly integrated into the build system and recognized by the IDE.

1. Create a New Package:
- Navigate to `server/apps/libs/modules/components/`.
- Navigate to `server/libs/modules/components/`.
- Create a new package with the name of your component, e.g., `newcomponent`.

2. Update Settings:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@
*/
public interface ActionContext extends Context {

/**
* Returns trace id which originates from micro meter
*
* @return traceId
*/
String getTraceId();

/**
* @param approvalFunction
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4106,6 +4106,11 @@ public void suspend(Suspend suspend) {
throw new UnsupportedOperationException();
}

@Override
public String getTraceId() {
throw new UnsupportedOperationException();
}

@Override
public <R> R xml(ContextFunction<Xml, R> xmlFunction) {
return context.xml(xmlFunction);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,11 @@ public void suspend(Suspend suspend) {
throw new UnsupportedOperationException();
}

@Override
public String getTraceId() {
throw new UnsupportedOperationException();
}

@Override
public <R> R xml(ContextFunction<Xml, R> xmlFunction) {
return context.xml(xmlFunction);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
*/
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
@SpringJUnitConfig(BaseFtpActionIntTest.TestConfig.class)
public class BaseFtpActionIntTest {

Check failure on line 55 in server/libs/modules/components/ftp/src/test/java/com/bytechef/component/ftp/action/BaseFtpActionIntTest.java

View check run for this annotation

SonarQubeCloud / [server] SonarCloud Code Analysis

Add some tests to this class.

See more on https://sonarcloud.io/project/issues?id=bytechef_server&issues=AZ6Y7otAxuz03-S0t5u8&open=AZ6Y7otAxuz03-S0t5u8&pullRequest=5145

protected static class TestContextImpl implements ActionContext {

Expand Down Expand Up @@ -120,6 +120,11 @@
throw new UnsupportedOperationException("Disabled in test mode");
}

@Override
public String getTraceId() {
throw new UnsupportedOperationException("Disabled in test mode");
}

@Override
public <R> R xml(ContextFunction<Xml, R> xmlFunction) {
throw new UnsupportedOperationException("Disabled in test mode");
Expand Down Expand Up @@ -340,7 +345,7 @@

container.stop();

Thread.sleep(FTP_CONTAINER_START_RETRY_DELAY_MILLIS);

Check warning on line 348 in server/libs/modules/components/ftp/src/test/java/com/bytechef/component/ftp/action/BaseFtpActionIntTest.java

View check run for this annotation

SonarQubeCloud / [server] SonarCloud Code Analysis

Remove this use of "Thread.sleep()".

See more on https://sonarcloud.io/project/issues?id=bytechef_server&issues=AZ6Y7otAxuz03-S0t5u9&open=AZ6Y7otAxuz03-S0t5u9&pullRequest=5145
}
}

Expand Down
1 change: 1 addition & 0 deletions server/libs/modules/components/gaurus/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
version="1.0"
Loading
Loading