Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rest out #13442

Merged
merged 4 commits into from Mar 11, 2024
Merged

Rest out #13442

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -564,6 +564,17 @@ public RestDefinition produces(String mediaType) {
return this;
}

public RestDefinition type(String classType) {
// add to last verb
if (getVerbs().isEmpty()) {
throw new IllegalArgumentException(MISSING_VERB);
}

VerbDefinition verb = getVerbs().get(getVerbs().size() - 1);
verb.setType(classType);
return this;
}

public RestDefinition type(Class<?> classType) {
// add to last verb
if (getVerbs().isEmpty()) {
Expand All @@ -576,6 +587,17 @@ public RestDefinition type(Class<?> classType) {
return this;
}

public RestDefinition outType(String classType) {
// add to last verb
if (getVerbs().isEmpty()) {
throw new IllegalArgumentException(MISSING_VERB);
}

VerbDefinition verb = getVerbs().get(getVerbs().size() - 1);
verb.setOutType(classType);
return this;
}

public RestDefinition outType(Class<?> classType) {
// add to last verb
if (getVerbs().isEmpty()) {
Expand Down
Expand Up @@ -164,6 +164,10 @@ To

We also renamed the `route-curcuit-breaker` console to `circuit-breaker`.

=== camel-jbang

The command `camel generate rest` have removed all the shorthand arguments `such as `-i -o` instead use the long names `--input --output`.

=== camel-jsonpath

The `camel-jsonpath` will now work more similar as `camel-jq` when you specify a `resultType` and have a list of entities.
Expand Down
Expand Up @@ -49,23 +49,23 @@
@CommandLine.Command(name = "rest", description = "Generate REST DSL source code from OpenApi specification")
public class CodeRestGenerator extends CamelCommand {

@CommandLine.Option(names = { "-i", "--input" }, required = true, description = "OpenApi specification file name")
@CommandLine.Option(names = { "--input" }, required = true, description = "OpenApi specification file name")
private String input;
@CommandLine.Option(names = { "-o", "--output" }, description = "Output REST DSL file name")
@CommandLine.Option(names = { "--output" }, description = "Output REST DSL file name")
private String output;
@CommandLine.Option(names = { "-t", "--type" }, description = "REST DSL type (YAML or XML)", defaultValue = "yaml")
@CommandLine.Option(names = { "--type" }, description = "REST DSL type (YAML or XML)", defaultValue = "yaml")
private String type;
@CommandLine.Option(names = { "-r", "--routes" }, description = "Generate routes (only in YAML)")
@CommandLine.Option(names = { "--routes" }, description = "Generate routes (only in YAML)")
private boolean generateRoutes;
@CommandLine.Option(names = { "-d", "--dto" }, description = "Generate Java Data Objects")
@CommandLine.Option(names = { "--dto" }, description = "Generate Java Data Objects")
private boolean generateDataObjects;
@CommandLine.Option(names = { "-run", "--runtime" }, description = "Runtime (quarkus, or spring-boot)",
@CommandLine.Option(names = { "--runtime" }, description = "Runtime (quarkus, or spring-boot)",
defaultValue = "quarkus")
private String runtime;
@CommandLine.Option(names = { "-p", "--package" }, description = "Package for generated Java models",
@CommandLine.Option(names = { "--package" }, description = "Package for generated Java models",
defaultValue = "model")
private String packageName;
@CommandLine.Option(names = { "-v", "--openapi-version" }, description = "Openapi specification 3.0 or 3.1",
@CommandLine.Option(names = { "--openapi-version" }, description = "Openapi specification 3.0 or 3.1",
defaultValue = "3.0")
private String openApiVersion = "3.0";

Expand Down Expand Up @@ -93,9 +93,13 @@ public Integer doCall() throws Exception {
try (CamelContext context = new DefaultCamelContext()) {
String text = null;
if ("yaml".equalsIgnoreCase(type)) {
text = RestDslGenerator.toYaml(doc).generate(context, generateRoutes);
text = RestDslGenerator.toYaml(doc)
.withDtoPackageName(generateDataObjects ? packageName : null)
.generate(context, generateRoutes);
} else if ("xml".equalsIgnoreCase(type)) {
text = RestDslGenerator.toXml(doc).generate(context);
text = RestDslGenerator.toXml(doc)
.withDtoPackageName(generateDataObjects ? packageName : null)
.generate(context);
}
if (text != null) {
if (output == null) {
Expand Down
Expand Up @@ -49,6 +49,10 @@ public class GenerateMojo extends AbstractGenerateMojo {

@Override
public void execute() throws MojoExecutionException {
execute(false);
}

protected void execute(boolean dto) throws MojoExecutionException {
if (skip) {
return;
}
Expand Down Expand Up @@ -87,6 +91,13 @@ public void execute() throws MojoExecutionException {
if (ObjectHelper.isNotEmpty(packageName)) {
generator.withPackageName(packageName);
}
if (dto) {
if (modelPackage != null) {
generator.withDtoPackageName(modelPackage);
} else {
generator.withDtoPackageName(packageName);
}
}

if (ObjectHelper.isNotEmpty(destinationGenerator)) {
final DestinationGenerator destinationGeneratorObject = createDestinationGenerator();
Expand Down
Expand Up @@ -30,7 +30,7 @@ public void execute() throws MojoExecutionException {
if (skip) {
return;
}
super.execute();
super.execute(true);

generateDto("java");
}
Expand Down
Expand Up @@ -47,6 +47,10 @@ public class GenerateXmlMojo extends AbstractGenerateMojo {

@Override
public void execute() throws MojoExecutionException {
execute(false);
}

protected void execute(boolean dto) throws MojoExecutionException {
if (skip) {
return;
}
Expand Down Expand Up @@ -78,6 +82,11 @@ public void execute() throws MojoExecutionException {
if (ObjectHelper.isNotEmpty(filterOperation)) {
generator.withOperationFilter(filterOperation);
}
if (dto) {
if (modelPackage != null) {
generator.withDtoPackageName(modelPackage);
}
}

if (ObjectHelper.isNotEmpty(destinationGenerator)) {
final DestinationGenerator destinationGeneratorObject = createDestinationGenerator();
Expand Down
Expand Up @@ -30,7 +30,7 @@ public void execute() throws MojoExecutionException {
if (skip) {
return;
}
super.execute();
super.execute(true);

generateDto("java");
}
Expand Down
Expand Up @@ -44,6 +44,10 @@ public class GenerateYamlMojo extends AbstractGenerateMojo {

@Override
public void execute() throws MojoExecutionException {
execute(false);
}

protected void execute(boolean dto) throws MojoExecutionException {
if (skip) {
return;
}
Expand Down Expand Up @@ -71,6 +75,11 @@ public void execute() throws MojoExecutionException {
if (ObjectHelper.isNotEmpty(filterOperation)) {
generator.withOperationFilter(filterOperation);
}
if (dto) {
if (modelPackage != null) {
generator.withDtoPackageName(modelPackage);
}
}

if (ObjectHelper.isNotEmpty(destinationGenerator)) {
final DestinationGenerator destinationGeneratorObject = createDestinationGenerator();
Expand Down
Expand Up @@ -30,7 +30,7 @@ public void execute() throws MojoExecutionException {
if (skip) {
return;
}
super.execute();
super.execute(true);

generateDto("java");
}
Expand Down