Skip to content

Commit

Permalink
feat(#1156): generate Java models alongside citrus classes
Browse files Browse the repository at this point in the history
  • Loading branch information
bbortt authored and Thorsten Schlathoelter committed Aug 18, 2024
1 parent d300c17 commit 60cd767
Show file tree
Hide file tree
Showing 49 changed files with 2,203 additions and 611 deletions.
62 changes: 62 additions & 0 deletions test-api-generator/citrus-test-api-generator-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
<name>Citrus :: Test API Generator :: Core</name>
<description>Generates a Citrus Test-API for OpenAPI and WSDL specifications.</description>

<properties>
<openapi-java-folder>${project.build.directory}/openapi-java-resources</openapi-java-folder>
</properties>

<dependencies>
<dependency>
<groupId>org.citrusframework</groupId>
Expand Down Expand Up @@ -118,6 +122,64 @@
</executions>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.7.1</version>
<configuration>
<artifactItems>
<artifactItem>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator</artifactId>
<version>${org.openapitools.version}</version>
<includes>Java/*Annotation*.mustache,Java/*Model*.mustache,Java/model*.mustache,Java/pojo*.mustache</includes>
</artifactItem>
</artifactItems>
<outputDirectory>
${openapi-java-folder}
</outputDirectory>
</configuration>
<executions>
<execution>
<id>unpack-java-templates</id>
<phase>generate-resources</phase>
<goals>
<goal>unpack</goal>
</goals>
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.3.1</version>
<executions>
<execution>
<id>prepare-java-templates</id>
<phase>process-resources</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${project.build.outputDirectory}/java-citrus</outputDirectory>
<resources>
<resource>
<directory>
${openapi-java-folder}/Java
</directory>
<includes>
<include>
*.mustache
</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ public JavaCitrusCodegen() {

// set default
additionalProperties.put(API_TYPE, API_TYPE_REST);
additionalProperties.put("useJakartaEe", true);

// add additional reserved words used in CitrusAbstractTestRequest and its base class to prevent name collisions
Set<String> reservedWordsTemp = reservedWords();
Expand Down Expand Up @@ -119,8 +120,7 @@ public JavaCitrusCodegen() {
newString(API_ENDPOINT,
"Which http client should be used (default " + httpClient + ")."));
cliOptions.add(
newString(
API_TYPE,
newString(API_TYPE,
"Specifies the type of API to be generated specify SOAP to generate a SOAP API. By default a REST API will be generated"
)
);
Expand All @@ -135,10 +135,8 @@ public JavaCitrusCodegen() {
newString(OPENAPI_SCHEMA,
"Which OpenAPI schema should be used (default " + openapiSchema + ")."));
cliOptions.add(
newString(
PREFIX,
"Add a prefix before the name of the files. First character should be upper case (default "
+ apiPrefix + ")."
newString(PREFIX,
"Add a prefix before the name of the files. First character should be upper case (default " + apiPrefix + ")."
)
);
cliOptions.add(newString(PREFIX, "The api prefix (default " + apiPrefix + ")."));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,7 @@
/*
* Copyright the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* ==================================================
* GENERATED CLASS, ALL CHANGES WILL BE LOST
* ==================================================
*/
{{>licenseInfo}}

package {{package}};

import jakarta.annotation.Generated;
import org.citrusframework.testapi.GeneratedApi;
import org.citrusframework.testapi.GeneratedApiRequest;
import jakarta.servlet.http.Cookie;
Expand Down Expand Up @@ -52,7 +31,7 @@ import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Generated(value = "org.citrusframework.openapi.generator.JavaCitrusCodegen")
{{>additionalModelTypeAnnotations}}{{>generatedAnnotation}}{{#discriminator}}{{>typeInfoAnnotation}}{{/discriminator}}{{>xmlAnnotation}}
public class {{classname}} implements GeneratedApi
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,7 @@
/*
* Copyright the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* ==================================================
* GENERATED CLASS, ALL CHANGES WILL BE LOST
* ==================================================
*/
{{>licenseInfo}}

package {{package}};

import jakarta.annotation.Generated;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
Expand All @@ -45,7 +24,7 @@ import org.springframework.util.CollectionUtils;

import {{invokerPackage}}.citrus.{{prefix}}AbstractTestRequest;

@Generated(value = "org.citrusframework.openapi.generator.JavaCitrusCodegen")
{{>additionalModelTypeAnnotations}}{{>generatedAnnotation}}{{#discriminator}}{{>typeInfoAnnotation}}{{/discriminator}}{{>xmlAnnotation}}
public class {{classname}} implements GeneratedApi
{
public static final {{classname}} INSTANCE = new {{classname}}();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,4 @@
/*
* Copyright the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* ==================================================
* GENERATED CLASS, ALL CHANGES WILL BE LOST
* ==================================================
*/
{{>licenseInfo}}

package {{invokerPackage}}.spring;

Expand All @@ -29,13 +9,12 @@ import static org.springframework.beans.factory.config.BeanDefinition.SCOPE_PROT
import {{package}}.{{classname}};
{{/apis}}
{{/apiInfo}}
import javax.annotation.processing.Generated;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Scope;

@Configuration
@Generated(value = "org.citrusframework.openapi.generator.JavaCitrusCodegen")
{{>additionalModelTypeAnnotations}}{{>generatedAnnotation}}{{#discriminator}}{{>typeInfoAnnotation}}{{/discriminator}}{{>xmlAnnotation}}
public class {{prefix}}BeanConfiguration {
{{#apiInfo}}
{{#apis}}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,4 @@
/*
* Copyright the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* ==================================================
* GENERATED CLASS, ALL CHANGES WILL BE LOST
* ==================================================
*/
{{>licenseInfo}}

package {{invokerPackage}}.citrus;

Expand All @@ -28,8 +8,6 @@ import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.annotation.processing.Generated;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
Expand All @@ -42,7 +20,7 @@ import org.w3c.dom.Attr;
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;

@Generated(value = "org.citrusframework.openapi.generator.JavaCitrusCodegen")
{{>additionalModelTypeAnnotations}}{{>generatedAnnotation}}{{#discriminator}}{{>typeInfoAnnotation}}{{/discriminator}}{{>xmlAnnotation}}
public class {{prefix}}BeanDefinitionParser implements BeanDefinitionParser {
private static final String COOKIE = "cookie";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* Copyright the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,24 +1,4 @@
/*
* Copyright the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* ==================================================
* GENERATED CLASS, ALL CHANGES WILL BE LOST
* ==================================================
*/
{{>licenseInfo}}

package {{invokerPackage}}.citrus.extension;

Expand All @@ -29,11 +9,9 @@ import {{package}}.{{classname}};
{{/apiInfo}}
import {{invokerPackage}}.citrus.{{prefix}}BeanDefinitionParser;

import javax.annotation.processing.Generated;

import org.springframework.beans.factory.xml.NamespaceHandlerSupport;

@Generated(value = "org.citrusframework.openapi.generator.JavaCitrusCodegen")
{{>additionalModelTypeAnnotations}}{{>generatedAnnotation}}{{#discriminator}}{{>typeInfoAnnotation}}{{/discriminator}}{{>xmlAnnotation}}
public class {{prefix}}NamespaceHandler extends NamespaceHandlerSupport {
@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,30 +1,9 @@
/*
* Copyright the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* ==================================================
* GENERATED CLASS, ALL CHANGES WILL BE LOST
* ==================================================
*/
{{>licenseInfo}}

package {{invokerPackage}}.citrus;

import static org.springframework.util.CollectionUtils.isEmpty;

import jakarta.annotation.Generated;
import jakarta.annotation.Nullable;
import java.util.List;
import java.util.Map;
Expand All @@ -51,7 +30,7 @@ import org.slf4j.MarkerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;

@Generated(value = "org.citrusframework.openapi.generator.JavaCitrusCodegen")
{{>additionalModelTypeAnnotations}}{{>generatedAnnotation}}{{#discriminator}}{{>typeInfoAnnotation}}{{/discriminator}}{{>xmlAnnotation}}
public abstract class {{prefix}}AbstractTestRequest extends AbstractTestAction {
protected final Marker coverageMarker = MarkerFactory.getMarker("{{#lambda.uppercase}}{{prefix}}{{/lambda.uppercase}}-API-COVERAGE");
Expand Down
Loading

0 comments on commit 60cd767

Please sign in to comment.