Skip to content
Merged
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 @@ -1062,14 +1062,16 @@ private void doStopRoutes(RouteController controller, Comparator<RouteStartupOrd
routesOrdered.sort(comparator);
for (RouteStartupOrder order : routesOrdered) {
Route route = order.getRoute();
boolean stopped = controller.getRouteStatus(route.getRouteId()).isStopped();
var status = controller.getRouteStatus(route.getRouteId());
boolean stopped = status == null || status.isStopped();
if (!stopped) {
stopRoute(route.getRouteId(), LoggingLevel.DEBUG);
}
}
// stop any remainder routes
for (Route route : getRoutes()) {
boolean stopped = controller.getRouteStatus(route.getRouteId()).isStopped();
var status = controller.getRouteStatus(route.getRouteId());
boolean stopped = status == null || status.isStopped();
if (!stopped) {
stopRoute(route.getRouteId(), LoggingLevel.DEBUG);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public void setName(String name) {
}

public String getDescription() {
return description != null ? description : "";
return description;
}

/**
Expand All @@ -118,7 +118,7 @@ public void setDescription(String description) {
* Sets the parameter default value.
*/
public String getDefaultValue() {
return defaultValue != null ? defaultValue : "";
return defaultValue;
}

public void setDefaultValue(String defaultValue) {
Expand Down Expand Up @@ -159,7 +159,7 @@ public void setArrayType(String arrayType) {
}

public String getDataType() {
return dataType != null ? dataType : "string";
return dataType;
}

/**
Expand Down
17 changes: 8 additions & 9 deletions dsl/camel-kamelet-main/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,14 @@
<groupId>org.apache.camel</groupId>
<artifactId>camel-kamelet</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-xml-jaxp</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-xml-io</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-bean</artifactId>
Expand Down Expand Up @@ -126,21 +134,12 @@
<groupId>org.apache.camel</groupId>
<artifactId>camel-catalog-console</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-openapi-rest-dsl-generator</artifactId>
</dependency>

<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-resourceresolver-github</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-xml-io</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-xml-io-dsl</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@
package org.apache.camel.main.reload;

import java.io.File;
import java.lang.reflect.Method;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.parser.OpenAPIV3Parser;
import org.apache.camel.generator.openapi.RestDslGenerator;
import org.apache.camel.CamelContext;
import org.apache.camel.main.download.DependencyDownloader;
import org.apache.camel.support.FileWatcherResourceReloadStrategy;
import org.apache.camel.support.ObjectHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -40,6 +41,7 @@ public class OpenApiGeneratorReloadStrategy extends FileWatcherResourceReloadStr
private static final String OPENAPI_GENERATED_FILE = ".camel-jbang/generated-openapi.yaml";

private final File openapi;
private Method method;

public OpenApiGeneratorReloadStrategy(File openapi) {
String parent = openapi.getParent();
Expand All @@ -58,14 +60,26 @@ public OpenApiGeneratorReloadStrategy(File openapi) {

LOG.info("Generating open-api rest-dsl from: {}", openapi);
try {
OpenAPIV3Parser parser = new OpenAPIV3Parser();
OpenAPI document = parser.read(openapi.getAbsolutePath());
String out = RestDslGenerator.toYaml(document).generate(getCamelContext(), false);
String out = (String) ObjectHelper.invokeMethodSafe(method, null, getCamelContext(), openapi);
Files.write(Paths.get(OPENAPI_GENERATED_FILE), out.getBytes());
} catch (Exception e) {
LOG.warn("Error generating open-api rest-dsl due: {}", e.getMessage(), e);
}
});
}

@Override
protected void doInit() throws Exception {
super.doInit();

DependencyDownloader downloader = getCamelContext().hasService(DependencyDownloader.class);
// these are extra dependencies used in special use-case so download as hidden
downloader.downloadHiddenDependency("org.apache.camel", "camel-openapi-rest-dsl-generator",
getCamelContext().getVersion());

// the generator is invoked via reflection
Class<?> clazz = getCamelContext().getClassResolver()
.resolveMandatoryClass("org.apache.camel.generator.openapi.RestDslGenerator");
method = clazz.getDeclaredMethod("generateToYaml", CamelContext.class, File.class);
}
}
2 changes: 1 addition & 1 deletion tooling/openapi-rest-dsl-generator/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-xml-jaxb</artifactId>
<artifactId>camel-xml-io</artifactId>
</dependency>
<dependency>
<groupId>com.squareup</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
package org.apache.camel.generator.openapi;

import java.io.File;
import java.net.URI;
import java.nio.file.Path;
import java.util.List;
Expand All @@ -27,6 +28,8 @@
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.servers.Server;
import io.swagger.v3.oas.models.servers.ServerVariable;
import io.swagger.v3.parser.OpenAPIV3Parser;
import org.apache.camel.CamelContext;
import org.apache.camel.model.rest.RestsDefinition;

import static org.apache.camel.util.ObjectHelper.notNull;
Expand Down Expand Up @@ -239,4 +242,14 @@ public static RestDslXmlGenerator toXml(final OpenAPI document) {
public static RestDslYamlGenerator toYaml(final OpenAPI document) {
return new RestDslYamlGenerator(document);
}

public static RestDslYamlGenerator toYaml(File path) {
OpenAPIV3Parser parser = new OpenAPIV3Parser();
OpenAPI document = parser.read(path.getAbsolutePath());
return new RestDslYamlGenerator(document);
}

public static String generateToYaml(CamelContext camelContext, File path) throws Exception {
return toYaml(path).generate(camelContext);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
import io.swagger.v3.oas.models.PathItem;
import org.apache.camel.CamelContext;
import org.apache.camel.model.rest.RestsDefinition;
import org.apache.camel.support.PluginHelper;
import org.apache.camel.util.ObjectHelper;
import org.apache.camel.xml.LwModelToXMLDumper;

public class RestDslXmlGenerator extends RestDslGenerator<RestDslXmlGenerator> {

Expand All @@ -60,7 +60,7 @@ public String generate(final CamelContext context) throws Exception {
}

final RestsDefinition rests = emitter.result();
final String xml = PluginHelper.getModelToXMLDumper(context).dumpModelAsXml(context, rests);
final String xml = new LwModelToXMLDumper().dumpModelAsXml(context, rests);

final DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
builderFactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@
import io.swagger.v3.oas.models.PathItem;
import org.apache.camel.CamelContext;
import org.apache.camel.model.rest.RestsDefinition;
import org.apache.camel.support.PluginHelper;
import org.apache.camel.util.ObjectHelper;
import org.apache.camel.xml.LwModelToXMLDumper;

public class RestDslYamlGenerator extends RestDslGenerator<RestDslYamlGenerator> {

Expand Down Expand Up @@ -85,7 +85,7 @@ public String generate(final CamelContext context, boolean generateRoutes) throw
}

final RestsDefinition rests = emitter.result();
final String xml = PluginHelper.getModelToXMLDumper(context).dumpModelAsXml(context, rests);
final String xml = new LwModelToXMLDumper().dumpModelAsXml(context, rests);

final DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
builderFactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
Expand Down