diff --git a/pom.xml b/pom.xml
index 797ea75..da89da1 100644
--- a/pom.xml
+++ b/pom.xml
@@ -5,6 +5,7 @@
archidata
0.8.11-SNAPSHOT
+ 21
3.1
21
21
diff --git a/src/org/kar/archidata/dataAccess/DataAccess.java b/src/org/kar/archidata/dataAccess/DataAccess.java
index 9dc6cc1..ac8a0de 100644
--- a/src/org/kar/archidata/dataAccess/DataAccess.java
+++ b/src/org/kar/archidata/dataAccess/DataAccess.java
@@ -1867,4 +1867,4 @@ public class DataAccess {
}
return outs;
}
-}
\ No newline at end of file
+}
diff --git a/src/org/kar/archidata/dataAccess/DataFactoryTsApi.java b/src/org/kar/archidata/dataAccess/DataFactoryTsApi.java
index 8c3ca6d..44375ca 100644
--- a/src/org/kar/archidata/dataAccess/DataFactoryTsApi.java
+++ b/src/org/kar/archidata/dataAccess/DataFactoryTsApi.java
@@ -8,7 +8,6 @@ import java.io.InputStreamReader;
import java.lang.reflect.Method;
import java.lang.reflect.Parameter;
import java.lang.reflect.ParameterizedType;
-import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
@@ -31,11 +30,11 @@ import jakarta.ws.rs.core.Response;
public class DataFactoryTsApi {
static final Logger LOGGER = LoggerFactory.getLogger(DataFactoryTsApi.class);
-
+
record APIModel(
String data,
String className) {}
-
+
/** Request the generation of the TypeScript file for the "Zod" export model
* @param classs List of class used in the model
* @throws Exception */
@@ -59,7 +58,7 @@ public class DataFactoryTsApi {
RESTRequestVoid
} from "./rest-tools"
import {""";
-
+
for (final Class> clazz : classs) {
final Set> includeModel = new HashSet<>();
final Set> includeCheckerModel = new HashSet<>();
@@ -97,7 +96,7 @@ public class DataFactoryTsApi {
}
generatedData.append("\n} from \"./model\"\n");
generatedData.append(api.data());
-
+
String fileName = api.className();
fileName = fileName.replaceAll("([A-Z])", "-$1").toLowerCase();
fileName = fileName.replaceAll("^\\-*", "");
@@ -108,11 +107,11 @@ public class DataFactoryTsApi {
}
return apis;
}
-
+
record OrderedElement(
String methodName,
Method method) {}
-
+
public static APIModel createSingleApi(
final Class> clazz,
final Set> includeModel,
@@ -122,12 +121,12 @@ public class DataFactoryTsApi {
// the basic path has no specific elements...
final String basicPath = ApiTool.apiAnnotationGetPath(clazz);
final String classSimpleName = clazz.getSimpleName();
-
+
builder.append("export namespace ");
builder.append(classSimpleName);
builder.append(" {\n");
LOGGER.info("Parse Class for path: {} => {}", classSimpleName, basicPath);
-
+
final List orderedElements = new ArrayList<>();
for (final Method method : clazz.getDeclaredMethods()) {
final String methodName = method.getName();
@@ -135,7 +134,7 @@ public class DataFactoryTsApi {
}
final Comparator comparator = Comparator.comparing(OrderedElement::methodName);
Collections.sort(orderedElements, comparator);
-
+
for (final OrderedElement orderedElement : orderedElements) {
final Method method = orderedElement.method();
final String methodName = orderedElement.methodName();
@@ -174,22 +173,8 @@ public class DataFactoryTsApi {
produces = null;
} else if (returnTypeModelRaw == Map.class) {
LOGGER.warn("Not manage the Map Model ... set any");
- final ParameterizedType listType = (ParameterizedType) method.getGenericReturnType();
- final Type typeKey = listType.getActualTypeArguments()[0];
- final Type typeValue = listType.getActualTypeArguments()[1];
- if (typeKey == String.class) {
- if (typeValue instanceof ParameterizedType) {
- final Type typeSubKey = listType.getActualTypeArguments()[0];
- final Type typeSubValue = listType.getActualTypeArguments()[1];
- if (typeKey == String.class) {
-
- }
- }
- } else {
- LOGGER.warn("Not manage the Map Model ... set any");
- returnTypeModel = new Class>[] { Map.class };
- tmpReturn = DataFactoryZod.createTables(returnTypeModel, previous);
- }
+ returnTypeModel = new Class>[] { Map.class };
+ tmpReturn = DataFactoryZod.createTables(returnTypeModel, previous);
} else if (returnTypeModelRaw == List.class) {
final ParameterizedType listType = (ParameterizedType) method.getGenericReturnType();
returnTypeModelRaw = (Class>) listType.getActualTypeArguments()[0];
@@ -311,7 +296,7 @@ public class DataFactoryTsApi {
LOGGER.trace(" data type: {}", emptyElement.get(0));
}
// ALL is good can generate the Elements
-
+
if (methodDescription != null) {
builder.append("\n\t/**\n\t * ");
builder.append(methodDescription);
@@ -383,7 +368,7 @@ public class DataFactoryTsApi {
String isFist = null;
for (final String elem : produces) {
String lastElement = null;
-
+
if (MediaType.APPLICATION_JSON.equals(elem)) {
lastElement = "HTTPMimeType.JSON";
}
@@ -495,7 +480,7 @@ public class DataFactoryTsApi {
builder.append("\n}\n");
return new APIModel(builder.toString(), classSimpleName);
}
-
+
public static void generatePackage(
final List> classApi,
final List> classModel,
@@ -507,7 +492,7 @@ public class DataFactoryTsApi {
FileWriter myWriter = new FileWriter(pathPackage + File.separator + "model.ts");
myWriter.write(packageApi.toString());
myWriter.close();
-
+
final StringBuilder index = new StringBuilder("""
/**
* Global import of the package
@@ -535,5 +520,5 @@ public class DataFactoryTsApi {
myWriter.close();
return;
}
-
+
}
diff --git a/src/org/kar/archidata/externalRestApi/AnalyzeApi.java b/src/org/kar/archidata/externalRestApi/AnalyzeApi.java
index ee94dc1..da33df0 100644
--- a/src/org/kar/archidata/externalRestApi/AnalyzeApi.java
+++ b/src/org/kar/archidata/externalRestApi/AnalyzeApi.java
@@ -17,7 +17,7 @@ public class AnalyzeApi {
final ApiGroupModel parsed = new ApiGroupModel(clazz, previousModel);
this.apiModels.add(parsed);
}
-
+
}
}
diff --git a/src/org/kar/archidata/externalRestApi/GeneratePythonModel.java b/src/org/kar/archidata/externalRestApi/GeneratePythonModel.java
index 5a96ed4..ce59eb5 100644
--- a/src/org/kar/archidata/externalRestApi/GeneratePythonModel.java
+++ b/src/org/kar/archidata/externalRestApi/GeneratePythonModel.java
@@ -1,5 +1,5 @@
package org.kar.archidata.externalRestApi;
public class GeneratePythonModel {
-
+
}
diff --git a/src/org/kar/archidata/externalRestApi/GenerateTsApi.java b/src/org/kar/archidata/externalRestApi/GenerateTsApi.java
index de979c2..658f992 100644
--- a/src/org/kar/archidata/externalRestApi/GenerateTsApi.java
+++ b/src/org/kar/archidata/externalRestApi/GenerateTsApi.java
@@ -1,5 +1,5 @@
package org.kar.archidata.externalRestApi;
public class GenerateTsApi {
-
+
}
diff --git a/src/org/kar/archidata/externalRestApi/model/ApiGroupModel.java b/src/org/kar/archidata/externalRestApi/model/ApiGroupModel.java
index 0e02354..512e2e5 100644
--- a/src/org/kar/archidata/externalRestApi/model/ApiGroupModel.java
+++ b/src/org/kar/archidata/externalRestApi/model/ApiGroupModel.java
@@ -24,14 +24,14 @@ public class ApiGroupModel {
// Origin class reference
Class> originClass;
// List of all API
- public List interfaces;
+ public List interfaces = new ArrayList<>();
public ApiGroupModel(final Class> clazz, final ModelGroup previousModel) throws Exception {
this.originClass = clazz;
// the basic path has no specific elements...
this.restEndPoint = ApiTool.apiAnnotationGetPath(clazz);
this.name = clazz.getSimpleName();
-
+
final List consumes = ApiTool.apiAnnotationGetConsumes(clazz);
final List produces = ApiTool.apiAnnotationProduces(clazz);
@@ -44,7 +44,7 @@ public class ApiGroupModel {
}
final Comparator comparator = Comparator.comparing(OrderedElement::methodName);
Collections.sort(orderedElements, comparator);
-
+
for (final OrderedElement orderedElement : orderedElements) {
// Check if the path is available
final RestTypeRequest methodType = ApiTool.apiAnnotationGetTypeRequest2(orderedElement.method());
diff --git a/src/org/kar/archidata/externalRestApi/model/ApiModel.java b/src/org/kar/archidata/externalRestApi/model/ApiModel.java
index 1099851..7324de9 100644
--- a/src/org/kar/archidata/externalRestApi/model/ApiModel.java
+++ b/src/org/kar/archidata/externalRestApi/model/ApiModel.java
@@ -10,19 +10,15 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import org.kar.archidata.dataAccess.DataFactoryZod;
-import org.kar.archidata.dataAccess.DataFactoryZod.ClassElement;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import jakarta.ws.rs.core.Response;
-
public class ApiModel {
static final Logger LOGGER = LoggerFactory.getLogger(ApiModel.class);
Class> originClass;
Method orignMethod;
-
+
// Name of the REST end-point name
public String restEndPoint;
// Type of the request:
@@ -31,7 +27,7 @@ public class ApiModel {
public String description;
// need to generate the progression of stream (if possible)
boolean needGenerateProgress;
-
+
// List of types returned by the API
public List returnTypes = new ArrayList<>();;
// Name of the API (function name)
@@ -46,10 +42,10 @@ public class ApiModel {
// Possible output type of the REST API
public List produces = new ArrayList<>();
- private void updateReturnTypes(final Method method, final ModelGroup previousModel) {
+ private void updateReturnTypes(final Method method, final ModelGroup previousModel) throws Exception {
// get return type from the user specification:
final Class>[] returnTypeModel = ApiTool.apiAnnotationGetAsyncType(method);
-
+ LOGGER.info("Get return Type async = {}", returnTypeModel);
if (returnTypeModel != null) {
if (returnTypeModel.length == 0) {
throw new IOException("Create a @AsyncType with empty elements ...");
@@ -67,23 +63,29 @@ public class ApiModel {
}
return;
}
-
+
final Class> returnTypeModelRaw = method.getReturnType();
- LOGGER.info("Get type: {}", returnTypeModelRaw);
+ LOGGER.info("Get return Type RAW = {}", returnTypeModelRaw.getCanonicalName());
if (returnTypeModelRaw == Map.class) {
- LOGGER.warn("Not manage the Map Model ... set any");
+ LOGGER.warn("Model Map");
final ParameterizedType listType = (ParameterizedType) method.getGenericReturnType();
this.returnTypes.add(new ClassMapModel(listType, previousModel));
return;
- }
- if (returnTypeModelRaw == List.class) {
+ } else if (returnTypeModelRaw == List.class) {
+ LOGGER.warn("Model List");
final ParameterizedType listType = (ParameterizedType) method.getGenericReturnType();
this.returnTypes.add(new ClassListModel(listType, previousModel));
return;
+ } else {
+ LOGGER.warn("Model Object");
+ this.returnTypes.add(previousModel.add(returnTypeModelRaw));
+ }
+ LOGGER.warn("List of returns elements:");
+ for (final ClassModel elem : this.returnTypes) {
+ LOGGER.warn(" - {}", elem);
}
- this.returnTypes.add(previousModel.add(returnTypeModelRaw));
}
-
+
public ApiModel(final Class> clazz, final Method method, final String baseRestEndPoint,
final List consume, final List produce, final ModelGroup previousModel) throws Exception {
this.originClass = clazz;
@@ -98,81 +100,17 @@ public class ApiModel {
this.produces = ApiTool.apiAnnotationProduces2(produce, method);
LOGGER.trace(" [{}] {} => {}/{}", methodType, methodName, baseRestEndPoint, methodPath);
this.needGenerateProgress = ApiTool.apiAnnotationTypeScriptProgress(method);
-
- Class>[] returnTypeModel = ApiTool.apiAnnotationGetAsyncType(method);
- boolean isUnmanagedReturnType = false;
- boolean returnModelIsArray = false;
- List tmpReturn;
- if (returnTypeModel == null) {
- Class> returnTypeModelRaw = method.getReturnType();
- LOGGER.info("Get type: {}", returnTypeModelRaw);
- if (returnTypeModelRaw == Response.class) {
- LOGGER.info("Get type: {}", returnTypeModelRaw);
- }
- if (returnTypeModelRaw == Response.class || returnTypeModelRaw == void.class
- || returnTypeModelRaw == Void.class) {
- if (returnTypeModelRaw == Response.class) {
- isUnmanagedReturnType = true;
- }
- returnTypeModel = new Class>[] { Void.class };
- tmpReturn = new ArrayList<>();
- this.produces = null;
- } else if (returnTypeModelRaw == Map.class) {
- LOGGER.warn("Not manage the Map Model ... set any");
- final ParameterizedType listType = (ParameterizedType) method.getGenericReturnType();
- final Type typeKey = listType.getActualTypeArguments()[0];
- final Type typeValue = listType.getActualTypeArguments()[1];
- if (typeKey == String.class) {
- if (typeValue instanceof ParameterizedType) {
- final Type typeSubKey = listType.getActualTypeArguments()[0];
- final Type typeSubValue = listType.getActualTypeArguments()[1];
- if (typeKey == String.class) {
-
- }
- }
- } else {
- LOGGER.warn("Not manage the Map Model ... set any");
- returnTypeModel = new Class>[] { Map.class };
- tmpReturn = DataFactoryZod.createTables(returnTypeModel, previous);
- }
- } else if (returnTypeModelRaw == List.class) {
- final ParameterizedType listType = (ParameterizedType) method.getGenericReturnType();
- returnTypeModelRaw = (Class>) listType.getActualTypeArguments()[0];
- returnModelIsArray = true;
- returnTypeModel = new Class>[] { returnTypeModelRaw };
- tmpReturn = DataFactoryZod.createTables(returnTypeModel, previous);
- } else {
- returnTypeModel = new Class>[] { returnTypeModelRaw };
- tmpReturn = DataFactoryZod.createTables(returnTypeModel, previous);
- }
- } else if (returnTypeModel.length >= 0 && (returnTypeModel[0] == Response.class
- || returnTypeModel[0] == Void.class || returnTypeModel[0] == void.class)) {
- if (returnTypeModel[0] == Response.class) {
- isUnmanagedReturnType = true;
- }
- returnTypeModel = new Class>[] { Void.class };
- tmpReturn = new ArrayList<>();
- this.produces = null;
- } else if (returnTypeModel.length > 0 && returnTypeModel[0] == Map.class) {
- LOGGER.warn("Not manage the Map Model ...");
- returnTypeModel = new Class>[] { Map.class };
- tmpReturn = DataFactoryZod.createTables(returnTypeModel, previous);
- } else {
- tmpReturn = DataFactoryZod.createTables(returnTypeModel, previous);
- }
- for (final ClassElement elem : tmpReturn) {
- includeModel.add(elem.model[0]);
- includeCheckerModel.add(elem.model[0]);
- }
- LOGGER.trace(" return: {}", tmpReturn.size());
- for (final ClassElement elem : tmpReturn) {
- LOGGER.trace(" - {}", elem.tsTypeName);
+
+ updateReturnTypes(method, previousModel);
+ LOGGER.trace(" return: {}", this.returnTypes.size());
+ for (final ClassModel elem : this.returnTypes) {
+ LOGGER.trace(" - {}", elem);
}
- final Map queryParams = new HashMap<>();
- final Map pathParams = new HashMap<>();
- final Map formDataParams = new HashMap<>();
- final List emptyElement = new ArrayList<>();
+ final Map> queryParams = new HashMap<>();
+ final Map> pathParams = new HashMap<>();
+ final Map> formDataParams = new HashMap<>();
+ final List emptyElement = new ArrayList<>();
// LOGGER.info(" Parameters:");
for (final Parameter parameter : method.getParameters()) {
// Security context are internal parameter (not available from API)
@@ -180,59 +118,33 @@ public class ApiModel {
continue;
}
final Class> parameterType = parameter.getType();
- String parameterTypeString;
+ final List parameterModel = new ArrayList<>();
final Class>[] asyncType = ApiTool.apiAnnotationGetAsyncType(parameter);
- if (parameterType == List.class) {
- if (asyncType == null) {
- LOGGER.warn("Detect List param ==> not managed type ==> any[] !!!");
- parameterTypeString = "any[]";
- } else {
- final List tmp = DataFactoryZod.createTables(asyncType, previous);
- for (final ClassElement elem : tmp) {
- includeModel.add(elem.model[0]);
- }
- parameterTypeString = ApiTool.convertInTypeScriptType(tmp, true);
+ if (asyncType != null) {
+ for (final Class> elem : asyncType) {
+ parameterModel.add(new ClassListModel(elem, previousModel));
}
- } else if (asyncType == null) {
- final ClassElement tmp = DataFactoryZod.createTable(parameterType, previous);
- includeModel.add(tmp.model[0]);
- parameterTypeString = tmp.tsTypeName;
+ } else if (parameterType == List.class) {
+ final Type parameterrizedType = parameter.getParameterizedType();
+ parameterModel.add(ClassModel.getModelBase(parameterType, parameterrizedType, previousModel));
+ } else if (parameterType == Map.class) {
+ final Type parameterrizedType = parameter.getParameterizedType();
+ parameterModel.add(ClassModel.getModelBase(parameterType, parameterrizedType, previousModel));
} else {
- final List tmp = DataFactoryZod.createTables(asyncType, previous);
- for (final ClassElement elem : tmp) {
- includeModel.add(elem.model[0]);
- }
- parameterTypeString = ApiTool.convertInTypeScriptType(tmp, true);
+ parameterModel.add(ClassModel.getModel(parameterType, previousModel));
}
+
final String pathParam = ApiTool.apiAnnotationGetPathParam(parameter);
final String queryParam = ApiTool.apiAnnotationGetQueryParam(parameter);
final String formDataParam = ApiTool.apiAnnotationGetFormDataParam(parameter);
if (queryParam != null) {
- queryParams.put(queryParam, parameterTypeString);
+ queryParams.put(queryParam, parameterModel);
} else if (pathParam != null) {
- pathParams.put(pathParam, parameterTypeString);
+ pathParams.put(pathParam, parameterModel);
} else if (formDataParam != null) {
- formDataParams.put(formDataParam, parameterTypeString);
- } else if (asyncType != null) {
- final List tmp = DataFactoryZod.createTables(asyncType, previous);
- parameterTypeString = "";
- for (final ClassElement elem : tmp) {
- includeModel.add(elem.model[0]);
- if (parameterTypeString.length() != 0) {
- parameterTypeString += " | ";
- }
- parameterTypeString += elem.tsTypeName;
- }
- emptyElement.add(parameterTypeString);
- } else if (parameterType == List.class) {
- parameterTypeString = "any[]";
- final Class> plop = parameterType.arrayType();
- LOGGER.info("ArrayType = {}", plop);
- emptyElement.add(parameterTypeString);
+ formDataParams.put(formDataParam, parameterModel);
} else {
- final ClassElement tmp = DataFactoryZod.createTable(parameterType, previous);
- includeModel.add(tmp.model[0]);
- emptyElement.add(tmp.tsTypeName);
+ emptyElement.addAll(parameterModel);
}
}
}
diff --git a/src/org/kar/archidata/externalRestApi/model/ApiTool.java b/src/org/kar/archidata/externalRestApi/model/ApiTool.java
index ed91546..07fd20b 100644
--- a/src/org/kar/archidata/externalRestApi/model/ApiTool.java
+++ b/src/org/kar/archidata/externalRestApi/model/ApiTool.java
@@ -25,7 +25,7 @@ import jakarta.ws.rs.QueryParam;
import jakarta.ws.rs.core.Context;
public class ApiTool {
-
+
public static String apiAnnotationGetPath(final Class> element) throws Exception {
final Annotation[] annotation = element.getDeclaredAnnotationsByType(Path.class);
if (annotation.length == 0) {
@@ -33,7 +33,7 @@ public class ApiTool {
}
return ((Path) annotation[0]).value();
}
-
+
public static List apiAnnotationProduces(final Class> element) throws Exception {
final Annotation[] annotation = element.getDeclaredAnnotationsByType(Produces.class);
if (annotation.length == 0) {
@@ -41,7 +41,7 @@ public class ApiTool {
}
return Arrays.asList(((Produces) annotation[0]).value());
}
-
+
public static List apiAnnotationProduces(final Method element) throws Exception {
final Annotation[] annotation = element.getDeclaredAnnotationsByType(Produces.class);
if (annotation.length == 0) {
@@ -49,7 +49,7 @@ public class ApiTool {
}
return Arrays.asList(((Produces) annotation[0]).value());
}
-
+
public static boolean apiAnnotationTypeScriptProgress(final Method element) throws Exception {
final Annotation[] annotation = element.getDeclaredAnnotationsByType(TypeScriptProgress.class);
if (annotation.length == 0) {
@@ -74,7 +74,7 @@ public class ApiTool {
}
return parentProduce;
}
-
+
public static String apiAnnotationGetOperationDescription(final Method element) throws Exception {
final Annotation[] annotation = element.getDeclaredAnnotationsByType(Operation.class);
if (annotation.length == 0) {
@@ -82,7 +82,7 @@ public class ApiTool {
}
return ((Operation) annotation[0]).description();
}
-
+
public static String apiAnnotationGetPath(final Method element) throws Exception {
final Annotation[] annotation = element.getDeclaredAnnotationsByType(Path.class);
if (annotation.length == 0) {
@@ -128,7 +128,7 @@ public class ApiTool {
}
return null;
}
-
+
public static String apiAnnotationGetPathParam(final Parameter element) throws Exception {
final Annotation[] annotation = element.getDeclaredAnnotationsByType(PathParam.class);
if (annotation.length == 0) {
@@ -136,7 +136,7 @@ public class ApiTool {
}
return ((PathParam) annotation[0]).value();
}
-
+
public static String apiAnnotationGetQueryParam(final Parameter element) throws Exception {
final Annotation[] annotation = element.getDeclaredAnnotationsByType(QueryParam.class);
if (annotation.length == 0) {
@@ -144,7 +144,7 @@ public class ApiTool {
}
return ((QueryParam) annotation[0]).value();
}
-
+
public static String apiAnnotationGetFormDataParam(final Parameter element) throws Exception {
final Annotation[] annotation = element.getDeclaredAnnotationsByType(FormDataParam.class);
if (annotation.length == 0) {
@@ -152,7 +152,7 @@ public class ApiTool {
}
return ((FormDataParam) annotation[0]).value();
}
-
+
public static Class>[] apiAnnotationGetAsyncType(final Parameter element) throws Exception {
final Annotation[] annotation = element.getDeclaredAnnotationsByType(AsyncType.class);
if (annotation.length == 0) {
@@ -160,7 +160,7 @@ public class ApiTool {
}
return ((AsyncType) annotation[0]).value();
}
-
+
public static Class>[] apiAnnotationGetAsyncType(final Method element) throws Exception {
final Annotation[] annotation = element.getDeclaredAnnotationsByType(AsyncType.class);
if (annotation.length == 0) {
@@ -168,7 +168,7 @@ public class ApiTool {
}
return ((AsyncType) annotation[0]).value();
}
-
+
public static List apiAnnotationGetConsumes(final Method element) throws Exception {
final Annotation[] annotation = element.getDeclaredAnnotationsByType(Consumes.class);
if (annotation.length == 0) {
@@ -176,7 +176,7 @@ public class ApiTool {
}
return Arrays.asList(((Consumes) annotation[0]).value());
}
-
+
public static List apiAnnotationGetConsumes(final Class> element) throws Exception {
final Annotation[] annotation = element.getDeclaredAnnotationsByType(Consumes.class);
if (annotation.length == 0) {
@@ -184,7 +184,7 @@ public class ApiTool {
}
return Arrays.asList(((Consumes) annotation[0]).value());
}
-
+
public static List apiAnnotationGetConsumes(final Class> clazz, final Method method) throws Exception {
final List data = apiAnnotationGetConsumes(method);
if (data != null) {
@@ -192,7 +192,7 @@ public class ApiTool {
}
return apiAnnotationGetConsumes(clazz);
}
-
+
public static List apiAnnotationGetConsumes2(final List parentConsume, final Method method)
throws Exception {
final List data = apiAnnotationGetConsumes(method);
@@ -201,11 +201,11 @@ public class ApiTool {
}
return parentConsume;
}
-
+
public static boolean apiAnnotationIsContext(final Parameter element) throws Exception {
return element.getDeclaredAnnotationsByType(Context.class).length != 0;
}
-
+
public static String convertInTypeScriptType(final List tmp, final boolean isList) {
String out = "";
for (final ClassElement elem : tmp) {
@@ -219,7 +219,7 @@ public class ApiTool {
}
return out;
}
-
+
public static String convertInTypeScriptCheckType(final List tmp) {
String out = "";
for (final ClassElement elem : tmp) {
diff --git a/src/org/kar/archidata/externalRestApi/model/ClassEnumModel.java b/src/org/kar/archidata/externalRestApi/model/ClassEnumModel.java
index 641d8a8..05da453 100644
--- a/src/org/kar/archidata/externalRestApi/model/ClassEnumModel.java
+++ b/src/org/kar/archidata/externalRestApi/model/ClassEnumModel.java
@@ -5,4 +5,15 @@ public class ClassEnumModel extends ClassModel {
protected ClassEnumModel(final Class> clazz) {
this.originClasses.add(clazz);
}
+
+ @Override
+ public String toString() {
+ final StringBuilder out = new StringBuilder();
+ out.append("ClassEnumModel [");
+ for (final Class> elem : this.originClasses) {
+ out.append(elem.getCanonicalName());
+ }
+ out.append("]");
+ return out.toString();
+ }
}
diff --git a/src/org/kar/archidata/externalRestApi/model/ClassListModel.java b/src/org/kar/archidata/externalRestApi/model/ClassListModel.java
index 94529e1..438114b 100644
--- a/src/org/kar/archidata/externalRestApi/model/ClassListModel.java
+++ b/src/org/kar/archidata/externalRestApi/model/ClassListModel.java
@@ -10,10 +10,19 @@ public class ClassListModel extends ClassModel {
public ClassListModel(final ClassModel valueModel) {
this.valueModel = valueModel;
}
-
+
+ public ClassListModel(final Class> clazz, final ModelGroup previousModel) throws IOException {
+ this.valueModel = getModel(clazz, previousModel);
+ }
+
public ClassListModel(final ParameterizedType listType, final ModelGroup previousModel) throws IOException {
final Type model = listType.getActualTypeArguments()[0];
this.valueModel = getModel(model, previousModel);
}
-
+
+ @Override
+ public String toString() {
+ return "ClassListModel [valueModel=" + this.valueModel + "]";
+ }
+
}
diff --git a/src/org/kar/archidata/externalRestApi/model/ClassMapModel.java b/src/org/kar/archidata/externalRestApi/model/ClassMapModel.java
index 4edb14f..4b49f58 100644
--- a/src/org/kar/archidata/externalRestApi/model/ClassMapModel.java
+++ b/src/org/kar/archidata/externalRestApi/model/ClassMapModel.java
@@ -6,7 +6,7 @@ import java.lang.reflect.ParameterizedType;
public class ClassMapModel extends ClassModel {
public ClassModel keyModel;
public ClassModel valueModel;
-
+
public ClassMapModel(final ClassModel keyModel, final ClassModel valueModel) {
this.keyModel = keyModel;
this.valueModel = valueModel;
@@ -17,4 +17,9 @@ public class ClassMapModel extends ClassModel {
this.valueModel = getModel(listType.getActualTypeArguments()[1], previousModel);
}
+ @Override
+ public String toString() {
+ return "ClassMapModel [keyModel=" + this.keyModel + ", valueModel=" + this.valueModel + "]";
+ }
+
}
diff --git a/src/org/kar/archidata/externalRestApi/model/ClassModel.java b/src/org/kar/archidata/externalRestApi/model/ClassModel.java
index 6cfce90..882c6c1 100644
--- a/src/org/kar/archidata/externalRestApi/model/ClassModel.java
+++ b/src/org/kar/archidata/externalRestApi/model/ClassModel.java
@@ -14,7 +14,7 @@ public abstract class ClassModel {
return this.originClasses.contains(clazz);
}
- public ClassModel getModel(final Type type, final ModelGroup previousModel) throws IOException {
+ public static ClassModel getModel(final Type type, final ModelGroup previousModel) throws IOException {
if (type == List.class) {
if (type instanceof final ParameterizedType parameterizedType) {
return new ClassListModel(parameterizedType, previousModel);
@@ -31,5 +31,28 @@ public abstract class ClassModel {
}
return previousModel.add((Class>) type);
}
-
+
+ public static ClassModel getModelBase(
+ final Class> clazz,
+ final Type parameterizedType,
+ final ModelGroup previousModel) throws IOException {
+ if (clazz == List.class) {
+ return new ClassListModel((ParameterizedType) parameterizedType, previousModel);
+ }
+ if (clazz == Map.class) {
+ return new ClassMapModel((ParameterizedType) parameterizedType, previousModel);
+ }
+ return previousModel.add(clazz);
+ }
+
+ public static ClassModel getModel(final Class> type, final ModelGroup previousModel) throws IOException {
+ if (type == List.class) {
+ throw new IOException("Fail to manage parametrized type...");
+ }
+ if (type == Map.class) {
+ throw new IOException("Fail to manage parametrized type...");
+ }
+ return previousModel.add(type);
+ }
+
}
diff --git a/src/org/kar/archidata/externalRestApi/model/ClassObjectModel.java b/src/org/kar/archidata/externalRestApi/model/ClassObjectModel.java
index 58ff668..f40c4ba 100644
--- a/src/org/kar/archidata/externalRestApi/model/ClassObjectModel.java
+++ b/src/org/kar/archidata/externalRestApi/model/ClassObjectModel.java
@@ -5,4 +5,15 @@ public class ClassObjectModel extends ClassModel {
public ClassObjectModel(final Class> clazz) {
this.originClasses.add(clazz);
}
+
+ @Override
+ public String toString() {
+ final StringBuilder out = new StringBuilder();
+ out.append("ClassObjectModel [");
+ for (final Class> elem : this.originClasses) {
+ out.append(elem.getCanonicalName());
+ }
+ out.append("]");
+ return out.toString();
+ }
}
diff --git a/src/org/kar/archidata/externalRestApi/model/ModelGroup.java b/src/org/kar/archidata/externalRestApi/model/ModelGroup.java
index b08ceef..f4eafaa 100644
--- a/src/org/kar/archidata/externalRestApi/model/ModelGroup.java
+++ b/src/org/kar/archidata/externalRestApi/model/ModelGroup.java
@@ -3,26 +3,37 @@ package org.kar.archidata.externalRestApi.model;
import java.util.ArrayList;
import java.util.List;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
public class ModelGroup {
+ static final Logger LOGGER = LoggerFactory.getLogger(ModelGroup.class);
public List previousModel = new ArrayList<>();
-
+
public ModelGroup() {}
public ModelGroup(final List models) {
this.previousModel = models;
}
-
+
public ClassModel add(final Class> clazz) {
+ //LOGGER.trace("Search element {}", clazz.getCanonicalName());
for (final ClassModel value : this.previousModel) {
if (value.isCompatible(clazz)) {
+ //LOGGER.trace(" ==> return {}", value);
return value;
}
}
if (clazz.isEnum()) {
final ClassModel elem = new ClassEnumModel(clazz);
+ this.previousModel.add(elem);
+ //LOGGER.trace(" ==> return enum {}", elem);
+ return elem;
}
// create new model:
-
- return null;
+ final ClassModel elem = new ClassObjectModel(clazz);
+ this.previousModel.add(elem);
+ //LOGGER.trace(" ==> return object {}", elem);
+ return elem;
}
}
diff --git a/test/src/test/kar/archidata/TestRawQuery.java b/test/src/test/kar/archidata/TestRawQuery.java
index 994f28a..3483d02 100644
--- a/test/src/test/kar/archidata/TestRawQuery.java
+++ b/test/src/test/kar/archidata/TestRawQuery.java
@@ -118,4 +118,4 @@ public class TestRawQuery {
}
}
-}
\ No newline at end of file
+}
diff --git a/test/src/test/kar/archidata/TestTypes.java b/test/src/test/kar/archidata/TestTypes.java
index d5d2e24..6b8f3e4 100644
--- a/test/src/test/kar/archidata/TestTypes.java
+++ b/test/src/test/kar/archidata/TestTypes.java
@@ -468,4 +468,4 @@ public class TestTypes {
DataAccess.delete(TypesTable.class, insertedData.id);
}
-}
\ No newline at end of file
+}