Skip to content

Commit

Permalink
255 openapiasyncapi homogenize mappercontentutils for both specificat…
Browse files Browse the repository at this point in the history
…ions (#349)


* Refactor
  • Loading branch information
jemacineiras authored Oct 16, 2024
1 parent 2f20b8d commit 8babf34
Show file tree
Hide file tree
Showing 429 changed files with 6,565 additions and 8,922 deletions.
25 changes: 15 additions & 10 deletions multiapi-engine/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,28 @@

<groupId>com.sngular</groupId>
<artifactId>multiapi-engine</artifactId>
<version>5.4.3</version>
<version>6.0.0</version>
<packaging>jar</packaging>

<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<swagger-parser.version>2.1.12</swagger-parser.version>
<commons-lang3.version>3.12.0</commons-lang3.version>
<commons-io.version>2.11.0</commons-io.version>
<commons-lang3.version>3.13.0</commons-lang3.version>
<commons-io.version>2.13.0</commons-io.version>
<commons-collections4.version>4.4</commons-collections4.version>
<jackson.version>2.15.0</jackson.version>
<jackson.version>2.15.3</jackson.version>
<freemarker.version>2.3.32</freemarker.version>
<assertj-core.version>3.24.2</assertj-core.version>
<junit-jupiter-engine.version>5.9.2</junit-jupiter-engine.version>
<junit-jupiter-engine.version>5.10.1</junit-jupiter-engine.version>
<swagger-core.version>2.2.9</swagger-core.version>
<maven-surefire-plugin.version>3.0.0</maven-surefire-plugin.version>

<commons-text.version>1.12.0</commons-text.version>
<lombok.version>1.18.30</lombok.version>
<slf4j-api.version>2.0.11</slf4j-api.version>
<commons-codec.version>1.16.0</commons-codec.version>
<maven-artifact.version>3.9.1</maven-artifact.version>
</properties>

<dependencies>
Expand All @@ -32,7 +37,7 @@
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-text</artifactId>
<version>1.10.0</version>
<version>${commons-text.version}</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
Expand Down Expand Up @@ -63,18 +68,18 @@
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.30</version>
<version>${lombok.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.28</version>
<version>${slf4j-api.version}</version>
</dependency>

<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.15</version>
<version>${commons-codec.version}</version>
</dependency>
<dependency>
<groupId>io.swagger.parser.v3</groupId>
Expand Down Expand Up @@ -143,7 +148,7 @@
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-artifact</artifactId>
<version>3.9.1</version>
<version>${maven-artifact.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
package com.sngular.api.generator.plugin.asyncapi.model;

import java.util.Objects;

import com.sngular.api.generator.plugin.asyncapi.util.BindingTypeEnum;
import com.sngular.api.generator.plugin.common.model.SchemaObject;
import lombok.Builder;
import lombok.Value;
import org.apache.commons.lang3.StringUtils;
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,54 +12,31 @@

package com.sngular.api.generator.plugin.asyncapi.parameter;


import java.util.List;
import java.util.Map;

import com.sngular.api.generator.plugin.common.model.TimeType;
import com.sngular.api.generator.plugin.common.model.CommonSpecFile;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Builder.Default;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
import org.apache.commons.lang3.StringUtils;

@Data
@Builder
@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
public final class OperationParameterObject {
@EqualsAndHashCode(callSuper = true)
public final class OperationParameterObject extends CommonSpecFile {

private String ids;

private String apiPackage;

private String modelPackage;

private String modelNameSuffix;

private String classNamePostfix;

private boolean useLombokModelAnnotation;

@Builder.Default
private String dateTimeFormat = "yyyy-MM-dd'T'HH:mm:ss";

@Builder.Default
private String dateFormat = "yyyy-MM-dd";

@Default
private TimeType useTimeType = TimeType.LOCAL;

@SuppressWarnings("unused")
private List<String> operationIds;

public List<String> getOperationIds() {
return StringUtils.isEmpty(ids) ? List.of() : List.of(ids.replace(" ", "").split(","));
}

public Map<String, String> getFormats() {
return Map.of("DATE_TIME", dateTimeFormat, "DATE", dateFormat);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
package com.sngular.api.generator.plugin.asyncapi.template;

import java.nio.file.Path;

import com.sngular.api.generator.plugin.asyncapi.model.SchemaObject;
import com.sngular.api.generator.plugin.common.model.SchemaObject;
import lombok.Builder;
import lombok.Value;

Expand All @@ -28,4 +27,6 @@ public class ClassTemplate {

SchemaObject classSchema;

boolean useLombok;

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,74 +6,36 @@

package com.sngular.api.generator.plugin.asyncapi.template;

import com.sngular.api.generator.plugin.common.template.CommonTemplateLoader;
import com.sngular.api.generator.plugin.exception.GeneratorTemplateException;

import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;
import java.io.StringReader;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;

import com.sngular.api.generator.plugin.exception.GeneratorTemplateException;
import freemarker.cache.TemplateLoader;
public class ClasspathTemplateLoader extends CommonTemplateLoader {

public class ClasspathTemplateLoader implements TemplateLoader {

private static final List<String> TEMPLATE_FILES = List.of("templateSuppliers.ftlh", "interfaceConsumer.ftlh", "templateConsumers.ftlh",
"interfaceSupplier.ftlh", "templateStreamBridge.ftlh", "templateSchema.ftlh",
"templateSchemaWithLombok.ftlh", "templateModelClassException.ftlh",
"interfaceSupplierWithKafkaBindings.ftlh", "templateSuppliersWithKafkaBindings.ftlh",
"interfaceSupplier.ftlh", "templateStreamBridge.ftlh",
"interfaceSupplierWithKafkaBindings.ftlh", "templateSuppliersWithKafkaBindings.ftlh",
"interfaceConsumerWithKafkaBindings.ftlh", "templateConsumersWithKafkaBindings.ftlh",
"templateStreamBridgeWithKafkaBindings.ftlh", "templateMessageWrapper.ftlh");

private static final List<String> TEMPLATE_ANNOTATION_FILES = List.of(TemplateIndexConstants.TEMPLATE_NOT_NULL_ANNOTATION,
TemplateIndexConstants.TEMPLATE_NOT_NULL_VALIDATOR_ANNOTATION,
TemplateIndexConstants.TEMPLATE_MAX_ANNOTATION, TemplateIndexConstants.TEMPLATE_MAX_VALIDATOR_ANNOTATION,
TemplateIndexConstants.TEMPLATE_MIN_ANNOTATION, TemplateIndexConstants.TEMPLATE_MIN_VALIDATOR_ANNOTATION,
TemplateIndexConstants.TEMPLATE_SIZE_ANNOTATION, TemplateIndexConstants.TEMPLATE_SIZE_VALIDATOR_ANNOTATION,
TemplateIndexConstants.TEMPLATE_PATTERN_ANNOTATION,
TemplateIndexConstants.TEMPLATE_PATTERN_VALIDATOR_ANNOTATION,
TemplateIndexConstants.TEMPLATE_MULTIPLEOF_ANNOTATION,
TemplateIndexConstants.TEMPLATE_MULTIPLEOF_VALIDATOR_ANNOTATION,
TemplateIndexConstants.TEMPLATE_MAX_ITEMS_ANNOTATION,
TemplateIndexConstants.TEMPLATE_MAX_ITEMS_VALIDATOR_ANNOTATION,
TemplateIndexConstants.TEMPLATE_MIN_ITEMS_ANNOTATION,
TemplateIndexConstants.TEMPLATE_MIN_ITEMS_VALIDATOR_ANNOTATION,
TemplateIndexConstants.TEMPLATE_UNIQUE_ITEMS_ANNOTATION,
TemplateIndexConstants.TEMPLATE_UNIQUE_ITEMS_VALIDATOR_ANNOTATION);

private static final ClassLoader LOADER = ClasspathTemplateLoader.class.getClassLoader();

private final Map<String, String> templatesMap = new HashMap<>();

public ClasspathTemplateLoader() {
templatesMap.putAll(getResourceFolderFiles());
}

@Override
public final Object findTemplateSource(final String templateName) {
return templatesMap.get(templateName);
}

@Override
public final long getLastModified(final Object o) {
return 0;
}

@Override
public final Reader getReader(final Object template, final String charSet) {
return new StringReader(template.toString());
}

@Override
public void closeTemplateSource(final Object o) {
// Not required to implement
super();
init(getResourceFolderFiles());
}

private Map<String, String> getResourceFolderFiles() {
final Map<String, String> templates = new HashMap<>();
try {
for (var templateFile : TEMPLATE_MODEL_FILES) {
templates.put(templateFile,
readFile((InputStream) Objects.requireNonNull(LOADER.getResource("templates/model/" + templateFile)).getContent()));
}
for (var templateFile : TEMPLATE_FILES) {
templates.put(templateFile,
readFile((InputStream) Objects.requireNonNull(LOADER.getResource("templates/asyncapi/" + templateFile)).getContent()));
Expand All @@ -88,8 +50,4 @@ private Map<String, String> getResourceFolderFiles() {
return templates;

}

private String readFile(final InputStream file) throws IOException {
return new String(file.readAllBytes());
}
}
Loading

0 comments on commit 8babf34

Please sign in to comment.