Compare commits
7 Commits
v0.9.0
...
feat_refac
Author | SHA1 | Date | |
---|---|---|---|
4fc5f68813 | |||
a7220e0f76 | |||
d28c31290f | |||
be1e189d60 | |||
be1bb9c52a | |||
b64825eaba | |||
592243ddc6 |
@@ -1,14 +1,4 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
version_file="version.txt"
|
|
||||||
|
|
||||||
# update the Maven version number
|
mvn versions:set -DnewVersion=$(cat version.txt)
|
||||||
mvn versions:set -DnewVersion=$(sed 's/dev/SNAPSHOT/g' $version_file)
|
|
||||||
if grep -q "DEV" "$version_file"; then
|
|
||||||
# update all versions release of dependency
|
|
||||||
mvn versions:use-latest-releases
|
|
||||||
# update our manage dependency as snapshoot
|
|
||||||
mvn versions:use-latest-versions -Dincludes=kangaroo-and-rabbit
|
|
||||||
else
|
|
||||||
# update our manage dependency as release (must be done before)
|
|
||||||
mvn versions:use-latest-releases -Dincludes=kangaroo-and-rabbit
|
|
||||||
fi
|
|
||||||
|
14
pom.xml
14
pom.xml
@@ -3,7 +3,7 @@
|
|||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>kangaroo-and-rabbit</groupId>
|
<groupId>kangaroo-and-rabbit</groupId>
|
||||||
<artifactId>archidata</artifactId>
|
<artifactId>archidata</artifactId>
|
||||||
<version>0.9.0</version>
|
<version>0.8.10-SNAPSHOOT</version>
|
||||||
<properties>
|
<properties>
|
||||||
<java.version>21</java.version>
|
<java.version>21</java.version>
|
||||||
<maven.compiler.version>3.1</maven.compiler.version>
|
<maven.compiler.version>3.1</maven.compiler.version>
|
||||||
@@ -136,24 +136,24 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.xerial</groupId>
|
<groupId>org.xerial</groupId>
|
||||||
<artifactId>sqlite-jdbc</artifactId>
|
<artifactId>sqlite-jdbc</artifactId>
|
||||||
<version>3.45.3.0</version>
|
<version>3.40.0.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!-- Interface for JWT token -->
|
<!-- Interface for JWT token -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.nimbusds</groupId>
|
<groupId>com.nimbusds</groupId>
|
||||||
<artifactId>nimbus-jose-jwt</artifactId>
|
<artifactId>nimbus-jose-jwt</artifactId>
|
||||||
<version>9.39.1</version>
|
<version>9.39</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>jakarta.persistence</groupId>
|
<groupId>jakarta.persistence</groupId>
|
||||||
<artifactId>jakarta.persistence-api</artifactId>
|
<artifactId>jakarta.persistence-api</artifactId>
|
||||||
<version>3.2.0</version>
|
<version>3.2.0-M2</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!-- Swagger dependencies -->
|
<!-- Swagger dependencies -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>io.swagger.core.v3</groupId>
|
<groupId>io.swagger.core.v3</groupId>
|
||||||
<artifactId>swagger-jaxrs2-jakarta</artifactId>
|
<artifactId>swagger-jaxrs2-jakarta</artifactId>
|
||||||
<version>2.2.22</version>
|
<version>2.2.21</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!--
|
<!--
|
||||||
************************************************************
|
************************************************************
|
||||||
@@ -163,13 +163,13 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.junit.jupiter</groupId>
|
<groupId>org.junit.jupiter</groupId>
|
||||||
<artifactId>junit-jupiter-api</artifactId>
|
<artifactId>junit-jupiter-api</artifactId>
|
||||||
<version>5.11.0-M2</version>
|
<version>5.11.0-M1</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.junit.jupiter</groupId>
|
<groupId>org.junit.jupiter</groupId>
|
||||||
<artifactId>junit-jupiter-engine</artifactId>
|
<artifactId>junit-jupiter-engine</artifactId>
|
||||||
<version>5.11.0-M2</version>
|
<version>5.11.0-M1</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
|
524
src/org/kar/archidata/dataAccess/DataFactoryTsApi.java
Normal file
524
src/org/kar/archidata/dataAccess/DataFactoryTsApi.java
Normal file
@@ -0,0 +1,524 @@
|
|||||||
|
package org.kar.archidata.dataAccess;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileWriter;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.lang.reflect.Parameter;
|
||||||
|
import java.lang.reflect.ParameterizedType;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Comparator;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import org.kar.archidata.catcher.RestErrorResponse;
|
||||||
|
import org.kar.archidata.dataAccess.DataFactoryZod.ClassElement;
|
||||||
|
import org.kar.archidata.dataAccess.DataFactoryZod.GeneratedTypes;
|
||||||
|
import org.kar.archidata.externalRestApi.model.ApiTool;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import jakarta.ws.rs.core.MediaType;
|
||||||
|
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 */
|
||||||
|
public static List<String> createApi(
|
||||||
|
final List<Class<?>> classs,
|
||||||
|
final GeneratedTypes previous,
|
||||||
|
final String pathPackage) throws Exception {
|
||||||
|
final List<String> apis = new ArrayList<>();
|
||||||
|
final String globalheader = """
|
||||||
|
/**
|
||||||
|
* API of the server (auto-generated code)
|
||||||
|
*/
|
||||||
|
import {
|
||||||
|
HTTPMimeType,
|
||||||
|
HTTPRequestModel,
|
||||||
|
ModelResponseHttp,
|
||||||
|
RESTCallbacks,
|
||||||
|
RESTConfig,
|
||||||
|
RESTRequestJson,
|
||||||
|
RESTRequestJsonArray,
|
||||||
|
RESTRequestVoid
|
||||||
|
} from "./rest-tools"
|
||||||
|
import {""";
|
||||||
|
|
||||||
|
for (final Class<?> clazz : classs) {
|
||||||
|
final Set<Class<?>> includeModel = new HashSet<>();
|
||||||
|
final Set<Class<?>> includeCheckerModel = new HashSet<>();
|
||||||
|
final APIModel api = createSingleApi(clazz, includeModel, includeCheckerModel, previous);
|
||||||
|
final StringBuilder generatedData = new StringBuilder();
|
||||||
|
generatedData.append(globalheader);
|
||||||
|
final List<String> includedElements = new ArrayList<>();
|
||||||
|
for (final Class<?> elem : includeModel) {
|
||||||
|
if (elem == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
final ClassElement classElement = DataFactoryZod.createTable(elem, previous);
|
||||||
|
if (classElement.nativeType) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
includedElements.add(classElement.tsTypeName);
|
||||||
|
}
|
||||||
|
Collections.sort(includedElements);
|
||||||
|
for (final String elem : includedElements) {
|
||||||
|
generatedData.append("\n ");
|
||||||
|
generatedData.append(elem);
|
||||||
|
generatedData.append(",");
|
||||||
|
}
|
||||||
|
for (final Class<?> elem : includeCheckerModel) {
|
||||||
|
if (elem == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
final ClassElement classElement = DataFactoryZod.createTable(elem, previous);
|
||||||
|
if (classElement.nativeType) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
generatedData.append("\n ");
|
||||||
|
generatedData.append(classElement.tsCheckType);
|
||||||
|
generatedData.append(",");
|
||||||
|
}
|
||||||
|
generatedData.append("\n} from \"./model\"\n");
|
||||||
|
generatedData.append(api.data());
|
||||||
|
|
||||||
|
String fileName = api.className();
|
||||||
|
fileName = fileName.replaceAll("([A-Z])", "-$1").toLowerCase();
|
||||||
|
fileName = fileName.replaceAll("^\\-*", "");
|
||||||
|
apis.add(fileName);
|
||||||
|
final FileWriter myWriter = new FileWriter(pathPackage + File.separator + fileName + ".ts");
|
||||||
|
myWriter.write(generatedData.toString());
|
||||||
|
myWriter.close();
|
||||||
|
}
|
||||||
|
return apis;
|
||||||
|
}
|
||||||
|
|
||||||
|
record OrderedElement(
|
||||||
|
String methodName,
|
||||||
|
Method method) {}
|
||||||
|
|
||||||
|
public static APIModel createSingleApi(
|
||||||
|
final Class<?> clazz,
|
||||||
|
final Set<Class<?>> includeModel,
|
||||||
|
final Set<Class<?>> includeCheckerModel,
|
||||||
|
final GeneratedTypes previous) throws Exception {
|
||||||
|
final StringBuilder builder = new StringBuilder();
|
||||||
|
// 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<OrderedElement> orderedElements = new ArrayList<>();
|
||||||
|
for (final Method method : clazz.getDeclaredMethods()) {
|
||||||
|
final String methodName = method.getName();
|
||||||
|
orderedElements.add(new OrderedElement(methodName, method));
|
||||||
|
}
|
||||||
|
final Comparator<OrderedElement> comparator = Comparator.comparing(OrderedElement::methodName);
|
||||||
|
Collections.sort(orderedElements, comparator);
|
||||||
|
|
||||||
|
for (final OrderedElement orderedElement : orderedElements) {
|
||||||
|
final Method method = orderedElement.method();
|
||||||
|
final String methodName = orderedElement.methodName();
|
||||||
|
final String methodPath = ApiTool.apiAnnotationGetPath(method);
|
||||||
|
final String methodType = ApiTool.apiAnnotationGetTypeRequest(method);
|
||||||
|
if (methodType == null) {
|
||||||
|
LOGGER.error(" [{}] {} => {}/{} ==> No methode type @PATH, @GET ...", methodType, methodName,
|
||||||
|
basicPath, methodPath);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
final String methodDescription = ApiTool.apiAnnotationGetOperationDescription(method);
|
||||||
|
final List<String> consumes = ApiTool.apiAnnotationGetConsumes(clazz, method);
|
||||||
|
List<String> produces = ApiTool.apiAnnotationProduces(clazz, method);
|
||||||
|
LOGGER.trace(" [{}] {} => {}/{}", methodType, methodName, basicPath, methodPath);
|
||||||
|
if (methodDescription != null) {
|
||||||
|
LOGGER.trace(" description: {}", methodDescription);
|
||||||
|
}
|
||||||
|
final boolean needGenerateProgress = ApiTool.apiAnnotationTypeScriptProgress(method);
|
||||||
|
Class<?>[] returnTypeModel = ApiTool.apiAnnotationGetAsyncType(method);
|
||||||
|
boolean isUnmanagedReturnType = false;
|
||||||
|
boolean returnModelIsArray = false;
|
||||||
|
List<ClassElement> 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<>();
|
||||||
|
produces = null;
|
||||||
|
} else if (returnTypeModelRaw == Map.class) {
|
||||||
|
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<>();
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
final Map<String, String> queryParams = new HashMap<>();
|
||||||
|
final Map<String, String> pathParams = new HashMap<>();
|
||||||
|
final Map<String, String> formDataParams = new HashMap<>();
|
||||||
|
final List<String> emptyElement = new ArrayList<>();
|
||||||
|
// LOGGER.info(" Parameters:");
|
||||||
|
for (final Parameter parameter : method.getParameters()) {
|
||||||
|
// Security context are internal parameter (not available from API)
|
||||||
|
if (ApiTool.apiAnnotationIsContext(parameter)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
final Class<?> parameterType = parameter.getType();
|
||||||
|
String parameterTypeString;
|
||||||
|
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<ClassElement> tmp = DataFactoryZod.createTables(asyncType, previous);
|
||||||
|
for (final ClassElement elem : tmp) {
|
||||||
|
includeModel.add(elem.model[0]);
|
||||||
|
}
|
||||||
|
parameterTypeString = ApiTool.convertInTypeScriptType(tmp, true);
|
||||||
|
}
|
||||||
|
} else if (asyncType == null) {
|
||||||
|
final ClassElement tmp = DataFactoryZod.createTable(parameterType, previous);
|
||||||
|
includeModel.add(tmp.model[0]);
|
||||||
|
parameterTypeString = tmp.tsTypeName;
|
||||||
|
} else {
|
||||||
|
final List<ClassElement> tmp = DataFactoryZod.createTables(asyncType, previous);
|
||||||
|
for (final ClassElement elem : tmp) {
|
||||||
|
includeModel.add(elem.model[0]);
|
||||||
|
}
|
||||||
|
parameterTypeString = ApiTool.convertInTypeScriptType(tmp, true);
|
||||||
|
}
|
||||||
|
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);
|
||||||
|
} else if (pathParam != null) {
|
||||||
|
pathParams.put(pathParam, parameterTypeString);
|
||||||
|
} else if (formDataParam != null) {
|
||||||
|
formDataParams.put(formDataParam, parameterTypeString);
|
||||||
|
} else if (asyncType != null) {
|
||||||
|
final List<ClassElement> 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);
|
||||||
|
} else {
|
||||||
|
final ClassElement tmp = DataFactoryZod.createTable(parameterType, previous);
|
||||||
|
includeModel.add(tmp.model[0]);
|
||||||
|
emptyElement.add(tmp.tsTypeName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!queryParams.isEmpty()) {
|
||||||
|
LOGGER.trace(" Query parameter:");
|
||||||
|
for (final Entry<String, String> queryEntry : queryParams.entrySet()) {
|
||||||
|
LOGGER.trace(" - {}: {}", queryEntry.getKey(), queryEntry.getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!pathParams.isEmpty()) {
|
||||||
|
LOGGER.trace(" Path parameter:");
|
||||||
|
for (final Entry<String, String> pathEntry : pathParams.entrySet()) {
|
||||||
|
LOGGER.trace(" - {}: {}", pathEntry.getKey(), pathEntry.getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (emptyElement.size() > 1) {
|
||||||
|
LOGGER.error(" Fail to parse: Too much element in the model for the data ...");
|
||||||
|
continue;
|
||||||
|
} else if (emptyElement.size() == 1 && formDataParams.size() != 0) {
|
||||||
|
LOGGER.error(" Fail to parse: Incompatible form data & direct data ...");
|
||||||
|
continue;
|
||||||
|
} else if (emptyElement.size() == 1) {
|
||||||
|
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);
|
||||||
|
builder.append("\n\t */");
|
||||||
|
}
|
||||||
|
if (isUnmanagedReturnType) {
|
||||||
|
builder.append(
|
||||||
|
"\n\t// TODO: unmanaged \"Response\" type: please specify @AsyncType or considered as 'void'.");
|
||||||
|
}
|
||||||
|
builder.append("\n\texport function ");
|
||||||
|
builder.append(methodName);
|
||||||
|
builder.append("({\n\t\t\trestConfig,");
|
||||||
|
if (!queryParams.isEmpty()) {
|
||||||
|
builder.append("\n\t\t\tqueries,");
|
||||||
|
}
|
||||||
|
if (!pathParams.isEmpty()) {
|
||||||
|
builder.append("\n\t\t\tparams,");
|
||||||
|
}
|
||||||
|
if (produces != null && produces.size() > 1) {
|
||||||
|
builder.append("\n\t\t\tproduce,");
|
||||||
|
}
|
||||||
|
if (emptyElement.size() == 1 || formDataParams.size() != 0) {
|
||||||
|
builder.append("\n\t\t\tdata,");
|
||||||
|
}
|
||||||
|
if (needGenerateProgress) {
|
||||||
|
builder.append("\n\t\t\tcallback,");
|
||||||
|
}
|
||||||
|
builder.append("\n\t\t}: {");
|
||||||
|
builder.append("\n\t\trestConfig: RESTConfig,");
|
||||||
|
if (!queryParams.isEmpty()) {
|
||||||
|
builder.append("\n\t\tqueries: {");
|
||||||
|
for (final Entry<String, String> queryEntry : queryParams.entrySet()) {
|
||||||
|
builder.append("\n\t\t\t");
|
||||||
|
builder.append(queryEntry.getKey());
|
||||||
|
builder.append("?: ");
|
||||||
|
builder.append(queryEntry.getValue());
|
||||||
|
builder.append(",");
|
||||||
|
}
|
||||||
|
builder.append("\n\t\t},");
|
||||||
|
}
|
||||||
|
if (!pathParams.isEmpty()) {
|
||||||
|
builder.append("\n\t\tparams: {");
|
||||||
|
for (final Entry<String, String> pathEntry : pathParams.entrySet()) {
|
||||||
|
builder.append("\n\t\t\t");
|
||||||
|
builder.append(pathEntry.getKey());
|
||||||
|
builder.append(": ");
|
||||||
|
builder.append(pathEntry.getValue());
|
||||||
|
builder.append(",");
|
||||||
|
}
|
||||||
|
builder.append("\n\t\t},");
|
||||||
|
}
|
||||||
|
if (emptyElement.size() == 1) {
|
||||||
|
builder.append("\n\t\tdata: ");
|
||||||
|
builder.append(emptyElement.get(0));
|
||||||
|
builder.append(",");
|
||||||
|
} else if (formDataParams.size() != 0) {
|
||||||
|
builder.append("\n\t\tdata: {");
|
||||||
|
for (final Entry<String, String> pathEntry : formDataParams.entrySet()) {
|
||||||
|
builder.append("\n\t\t\t");
|
||||||
|
builder.append(pathEntry.getKey());
|
||||||
|
builder.append(": ");
|
||||||
|
builder.append(pathEntry.getValue());
|
||||||
|
builder.append(",");
|
||||||
|
}
|
||||||
|
builder.append("\n\t\t},");
|
||||||
|
}
|
||||||
|
if (produces != null && produces.size() > 1) {
|
||||||
|
builder.append("\n\t\tproduce: ");
|
||||||
|
String isFist = null;
|
||||||
|
for (final String elem : produces) {
|
||||||
|
String lastElement = null;
|
||||||
|
|
||||||
|
if (MediaType.APPLICATION_JSON.equals(elem)) {
|
||||||
|
lastElement = "HTTPMimeType.JSON";
|
||||||
|
}
|
||||||
|
if (MediaType.MULTIPART_FORM_DATA.equals(elem)) {
|
||||||
|
lastElement = "HTTPMimeType.MULTIPART";
|
||||||
|
}
|
||||||
|
if (DataExport.CSV_TYPE.equals(elem)) {
|
||||||
|
lastElement = "HTTPMimeType.CSV";
|
||||||
|
}
|
||||||
|
if (lastElement != null) {
|
||||||
|
if (isFist == null) {
|
||||||
|
isFist = lastElement;
|
||||||
|
} else {
|
||||||
|
builder.append(" | ");
|
||||||
|
}
|
||||||
|
builder.append(lastElement);
|
||||||
|
} else {
|
||||||
|
LOGGER.error("Unmanaged model type: {}", elem);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
builder.append(",");
|
||||||
|
}
|
||||||
|
if (needGenerateProgress) {
|
||||||
|
builder.append("\n\t\tcallback?: RESTCallbacks,");
|
||||||
|
}
|
||||||
|
builder.append("\n\t}): Promise<");
|
||||||
|
if (tmpReturn.size() == 0 //
|
||||||
|
|| tmpReturn.get(0).tsTypeName == null //
|
||||||
|
|| tmpReturn.get(0).tsTypeName.equals("void")) {
|
||||||
|
builder.append("void");
|
||||||
|
} else {
|
||||||
|
builder.append(ApiTool.convertInTypeScriptType(tmpReturn, returnModelIsArray));
|
||||||
|
}
|
||||||
|
builder.append("> {");
|
||||||
|
if (tmpReturn.size() == 0 //
|
||||||
|
|| tmpReturn.get(0).tsTypeName == null //
|
||||||
|
|| tmpReturn.get(0).tsTypeName.equals("void")) {
|
||||||
|
builder.append("\n\t\treturn RESTRequestVoid({");
|
||||||
|
} else if (returnModelIsArray) {
|
||||||
|
builder.append("\n\t\treturn RESTRequestJsonArray({");
|
||||||
|
} else {
|
||||||
|
builder.append("\n\t\treturn RESTRequestJson({");
|
||||||
|
}
|
||||||
|
builder.append("\n\t\t\trestModel: {");
|
||||||
|
builder.append("\n\t\t\t\tendPoint: \"");
|
||||||
|
builder.append(basicPath);
|
||||||
|
if (methodPath != null) {
|
||||||
|
builder.append("/");
|
||||||
|
builder.append(methodPath);
|
||||||
|
}
|
||||||
|
builder.append("\",");
|
||||||
|
builder.append("\n\t\t\t\trequestType: HTTPRequestModel.");
|
||||||
|
builder.append(methodType);
|
||||||
|
builder.append(",");
|
||||||
|
if (consumes != null) {
|
||||||
|
for (final String elem : consumes) {
|
||||||
|
if (MediaType.APPLICATION_JSON.equals(elem)) {
|
||||||
|
builder.append("\n\t\t\t\tcontentType: HTTPMimeType.JSON,");
|
||||||
|
break;
|
||||||
|
} else if (MediaType.MULTIPART_FORM_DATA.equals(elem)) {
|
||||||
|
builder.append("\n\t\t\t\tcontentType: HTTPMimeType.MULTIPART,");
|
||||||
|
break;
|
||||||
|
} else if (MediaType.TEXT_PLAIN.equals(elem)) {
|
||||||
|
builder.append("\n\t\t\t\tcontentType: HTTPMimeType.TEXT_PLAIN,");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if ("DELETE".equals(methodType)) {
|
||||||
|
builder.append("\n\t\t\t\tcontentType: HTTPMimeType.TEXT_PLAIN,");
|
||||||
|
}
|
||||||
|
if (produces != null) {
|
||||||
|
if (produces.size() > 1) {
|
||||||
|
builder.append("\n\t\t\t\taccept: produce,");
|
||||||
|
} else {
|
||||||
|
for (final String elem : produces) {
|
||||||
|
if (MediaType.APPLICATION_JSON.equals(elem)) {
|
||||||
|
builder.append("\n\t\t\t\taccept: HTTPMimeType.JSON,");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
builder.append("\n\t\t\t},");
|
||||||
|
builder.append("\n\t\t\trestConfig,");
|
||||||
|
if (!pathParams.isEmpty()) {
|
||||||
|
builder.append("\n\t\t\tparams,");
|
||||||
|
}
|
||||||
|
if (!queryParams.isEmpty()) {
|
||||||
|
builder.append("\n\t\t\tqueries,");
|
||||||
|
}
|
||||||
|
if (emptyElement.size() == 1) {
|
||||||
|
builder.append("\n\t\t\tdata,");
|
||||||
|
} else if (formDataParams.size() != 0) {
|
||||||
|
builder.append("\n\t\t\tdata,");
|
||||||
|
}
|
||||||
|
if (needGenerateProgress) {
|
||||||
|
builder.append("\n\t\t\tcallback,");
|
||||||
|
}
|
||||||
|
builder.append("\n\t\t}");
|
||||||
|
if (tmpReturn.size() != 0 && tmpReturn.get(0).tsTypeName != null
|
||||||
|
&& !tmpReturn.get(0).tsTypeName.equals("void")) {
|
||||||
|
builder.append(", ");
|
||||||
|
// TODO: correct this it is really bad ...
|
||||||
|
builder.append(ApiTool.convertInTypeScriptCheckType(tmpReturn));
|
||||||
|
}
|
||||||
|
builder.append(");");
|
||||||
|
builder.append("\n\t};");
|
||||||
|
}
|
||||||
|
builder.append("\n}\n");
|
||||||
|
return new APIModel(builder.toString(), classSimpleName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void generatePackage(
|
||||||
|
final List<Class<?>> classApi,
|
||||||
|
final List<Class<?>> classModel,
|
||||||
|
final String pathPackage) throws Exception {
|
||||||
|
final GeneratedTypes previous = DataFactoryZod.createBasicType();
|
||||||
|
DataFactoryZod.createTable(RestErrorResponse.class, previous);
|
||||||
|
final List<String> listApi = createApi(classApi, previous, pathPackage);
|
||||||
|
final String packageApi = DataFactoryZod.createTables(new ArrayList<>(classModel), previous);
|
||||||
|
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
|
||||||
|
*/
|
||||||
|
export * from "./model";
|
||||||
|
""");
|
||||||
|
for (final String api : listApi) {
|
||||||
|
index.append("export * from \"./").append(api).append("\";\n");
|
||||||
|
}
|
||||||
|
myWriter = new FileWriter(pathPackage + File.separator + "index.ts");
|
||||||
|
myWriter.write(index.toString());
|
||||||
|
myWriter.close();
|
||||||
|
final InputStream ioStream = DataFactoryTsApi.class.getClassLoader().getResourceAsStream("rest-tools.ts");
|
||||||
|
if (ioStream == null) {
|
||||||
|
throw new IllegalArgumentException("rest-tools.ts is not found");
|
||||||
|
}
|
||||||
|
final BufferedReader buffer = new BufferedReader(new InputStreamReader(ioStream));
|
||||||
|
myWriter = new FileWriter(pathPackage + File.separator + "rest-tools.ts");
|
||||||
|
String line;
|
||||||
|
while ((line = buffer.readLine()) != null) {
|
||||||
|
myWriter.write(line);
|
||||||
|
myWriter.write("\n");
|
||||||
|
}
|
||||||
|
ioStream.close();
|
||||||
|
myWriter.close();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
471
src/org/kar/archidata/dataAccess/DataFactoryZod.java
Normal file
471
src/org/kar/archidata/dataAccess/DataFactoryZod.java
Normal file
@@ -0,0 +1,471 @@
|
|||||||
|
package org.kar.archidata.dataAccess;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.lang.reflect.ParameterizedType;
|
||||||
|
import java.sql.Timestamp;
|
||||||
|
import java.time.Instant;
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.time.LocalTime;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
|
||||||
|
import org.kar.archidata.annotation.AnnotationTools;
|
||||||
|
import org.kar.archidata.exception.DataAccessException;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import jakarta.ws.rs.core.Response;
|
||||||
|
|
||||||
|
public class DataFactoryZod {
|
||||||
|
static final Logger LOGGER = LoggerFactory.getLogger(DataFactoryZod.class);
|
||||||
|
|
||||||
|
static public class ClassElement {
|
||||||
|
public Class<?>[] model;
|
||||||
|
public String zodName;
|
||||||
|
public String tsTypeName;
|
||||||
|
public String tsCheckType;
|
||||||
|
public String declaration;
|
||||||
|
public String comment = null;
|
||||||
|
public boolean isEnum = false;
|
||||||
|
public boolean nativeType;
|
||||||
|
|
||||||
|
public ClassElement(final Class<?> model[], final String zodName, final String tsTypeName,
|
||||||
|
final String tsCheckType, final String declaration, final boolean nativeType) {
|
||||||
|
this.model = model;
|
||||||
|
this.zodName = zodName;
|
||||||
|
this.tsTypeName = tsTypeName;
|
||||||
|
this.tsCheckType = tsCheckType;
|
||||||
|
this.declaration = declaration;
|
||||||
|
this.nativeType = nativeType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ClassElement(final Class<?> model) {
|
||||||
|
this(new Class<?>[] { model });
|
||||||
|
}
|
||||||
|
|
||||||
|
public ClassElement(final Class<?> model[]) {
|
||||||
|
this.model = model;
|
||||||
|
this.zodName = "Zod" + model[0].getSimpleName();
|
||||||
|
this.tsTypeName = model[0].getSimpleName();
|
||||||
|
this.tsCheckType = "is" + model[0].getSimpleName();
|
||||||
|
this.declaration = null;
|
||||||
|
this.nativeType = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class GeneratedTypes {
|
||||||
|
final List<ClassElement> previousGeneration = new ArrayList<>();
|
||||||
|
final List<Class<?>> order = new ArrayList<>();
|
||||||
|
|
||||||
|
public ClassElement find(final Class<?> clazz) {
|
||||||
|
for (final ClassElement elem : this.previousGeneration) {
|
||||||
|
for (final Class<?> elemClass : elem.model) {
|
||||||
|
if (elemClass == clazz) {
|
||||||
|
return elem;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void add(final ClassElement elem) {
|
||||||
|
this.previousGeneration.add(elem);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void add(final ClassElement elem, final boolean addOrder) {
|
||||||
|
this.previousGeneration.add(elem);
|
||||||
|
if (addOrder) {
|
||||||
|
this.order.add(elem.model[0]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addOrder(final ClassElement elem) {
|
||||||
|
this.order.add(elem.model[0]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ClassElement convertTypeZodEnum(final Class<?> clazz, final GeneratedTypes previous)
|
||||||
|
throws Exception {
|
||||||
|
final ClassElement element = new ClassElement(clazz);
|
||||||
|
previous.add(element);
|
||||||
|
final Object[] arr = clazz.getEnumConstants();
|
||||||
|
final StringBuilder out = new StringBuilder();
|
||||||
|
if (System.getenv("ARCHIDATA_GENERATE_ZOD_ENUM") != null) {
|
||||||
|
boolean first = true;
|
||||||
|
out.append("zod.enum([");
|
||||||
|
for (final Object elem : arr) {
|
||||||
|
if (!first) {
|
||||||
|
out.append(",\n\t");
|
||||||
|
} else {
|
||||||
|
out.append("\n\t");
|
||||||
|
first = false;
|
||||||
|
}
|
||||||
|
out.append("'");
|
||||||
|
out.append(elem.toString());
|
||||||
|
out.append("'");
|
||||||
|
}
|
||||||
|
if (first) {
|
||||||
|
out.append("]}");
|
||||||
|
} else {
|
||||||
|
out.append("\n\t])");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
element.isEnum = true;
|
||||||
|
boolean first = true;
|
||||||
|
out.append("{");
|
||||||
|
for (final Object elem : arr) {
|
||||||
|
if (!first) {
|
||||||
|
out.append(",\n\t");
|
||||||
|
} else {
|
||||||
|
out.append("\n\t");
|
||||||
|
first = false;
|
||||||
|
}
|
||||||
|
out.append(elem.toString());
|
||||||
|
out.append(" = '");
|
||||||
|
out.append(elem.toString());
|
||||||
|
out.append("'");
|
||||||
|
}
|
||||||
|
if (first) {
|
||||||
|
out.append("}");
|
||||||
|
} else {
|
||||||
|
out.append(",\n\t}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
element.declaration = out.toString();
|
||||||
|
previous.addOrder(element);
|
||||||
|
return element;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String convertTypeZod(final Class<?> type, final GeneratedTypes previous) throws Exception {
|
||||||
|
final ClassElement previousType = previous.find(type);
|
||||||
|
if (previousType != null) {
|
||||||
|
return previousType.zodName;
|
||||||
|
}
|
||||||
|
if (type.isEnum()) {
|
||||||
|
return convertTypeZodEnum(type, previous).zodName;
|
||||||
|
}
|
||||||
|
if (type == List.class) {
|
||||||
|
throw new DataAccessException("Imcompatible type of element in object for: " + type.getCanonicalName()
|
||||||
|
+ " Unmanaged List of List ... ");
|
||||||
|
}
|
||||||
|
final ClassElement elemCreated = createTable(type, previous);
|
||||||
|
if (elemCreated != null) {
|
||||||
|
return elemCreated.zodName;
|
||||||
|
}
|
||||||
|
throw new DataAccessException("Imcompatible type of element in object for: " + type.getCanonicalName());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String convertTypeZod(final Field field, final GeneratedTypes previous) throws Exception {
|
||||||
|
final Class<?> type = field.getType();
|
||||||
|
final ClassElement previousType = previous.find(type);
|
||||||
|
if (previousType != null) {
|
||||||
|
return previousType.zodName;
|
||||||
|
}
|
||||||
|
if (type.isEnum()) {
|
||||||
|
return convertTypeZodEnum(type, previous).zodName;
|
||||||
|
}
|
||||||
|
if (type == List.class) {
|
||||||
|
final ParameterizedType listType = (ParameterizedType) field.getGenericType();
|
||||||
|
final Class<?> listClass = (Class<?>) listType.getActualTypeArguments()[0];
|
||||||
|
final String simpleSubType = convertTypeZod(listClass, previous);
|
||||||
|
return "zod.array(" + simpleSubType + ")";
|
||||||
|
}
|
||||||
|
final ClassElement elemCreated = createTable(type, previous);
|
||||||
|
if (elemCreated != null) {
|
||||||
|
return elemCreated.zodName;
|
||||||
|
}
|
||||||
|
throw new DataAccessException("Imcompatible type of element in object for: " + type.getCanonicalName());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String optionalTypeZod(final Class<?> type) throws Exception {
|
||||||
|
if (type.isPrimitive()) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
return ".optional()";
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void createTablesSpecificType(
|
||||||
|
final Field elem,
|
||||||
|
final int fieldId,
|
||||||
|
final StringBuilder builder,
|
||||||
|
final GeneratedTypes previous) throws Exception {
|
||||||
|
final String name = elem.getName();
|
||||||
|
final Class<?> classModel = elem.getType();
|
||||||
|
final int limitSize = AnnotationTools.getLimitSize(elem);
|
||||||
|
|
||||||
|
final String comment = AnnotationTools.getComment(elem);
|
||||||
|
|
||||||
|
if (fieldId != 0) {
|
||||||
|
builder.append(",");
|
||||||
|
}
|
||||||
|
if (comment != null) {
|
||||||
|
builder.append("\n\t// ");
|
||||||
|
builder.append(comment);
|
||||||
|
}
|
||||||
|
builder.append("\n\t");
|
||||||
|
builder.append(name);
|
||||||
|
builder.append(": ");
|
||||||
|
builder.append(convertTypeZod(elem, previous));
|
||||||
|
if (limitSize > 0 && classModel == String.class) {
|
||||||
|
builder.append(".max(");
|
||||||
|
builder.append(limitSize);
|
||||||
|
builder.append(")");
|
||||||
|
}
|
||||||
|
if (AnnotationTools.getSchemaReadOnly(elem)) {
|
||||||
|
builder.append(".readonly()");
|
||||||
|
}
|
||||||
|
builder.append(optionalTypeZod(classModel));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean isFieldFromSuperClass(final Class<?> model, final String filedName) {
|
||||||
|
final Class<?> superClass = model.getSuperclass();
|
||||||
|
if (superClass == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
for (final Field field : superClass.getFields()) {
|
||||||
|
String name;
|
||||||
|
try {
|
||||||
|
name = AnnotationTools.getFieldName(field);
|
||||||
|
if (filedName.equals(name)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} catch (final Exception e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
LOGGER.trace("Catch error field name in parent create data table: {}", e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static GeneratedTypes createBasicType() throws Exception {
|
||||||
|
final GeneratedTypes previous = new GeneratedTypes();
|
||||||
|
previous.add(new ClassElement(new Class<?>[] { Void.class, void.class }, "void", "void", null, null, true));
|
||||||
|
// Map is binded to any ==> can not determine this complex model for now
|
||||||
|
previous.add(new ClassElement(new Class<?>[] { Map.class }, "any", "any", null, null, true));
|
||||||
|
previous.add(new ClassElement(new Class<?>[] { String.class }, "zod.string()", "string", null, "zod.string()",
|
||||||
|
true));
|
||||||
|
previous.add(new ClassElement(new Class<?>[] { InputStream.class, FormDataContentDisposition.class },
|
||||||
|
"z.instanceof(File)", "File", null, "z.instanceof(File)", true));
|
||||||
|
previous.add(new ClassElement(new Class<?>[] { Boolean.class, boolean.class }, "zod.boolean()", "boolean", null,
|
||||||
|
"zod.boolean()", true));
|
||||||
|
previous.add(new ClassElement(new Class<?>[] { UUID.class }, "ZodUUID", "UUID", "isUUID", "zod.string().uuid()",
|
||||||
|
false), true);
|
||||||
|
previous.add(new ClassElement(new Class<?>[] { Long.class, long.class }, "ZodLong", "Long", "isLong",
|
||||||
|
// "zod.bigint()",
|
||||||
|
"zod.number()", false), true);
|
||||||
|
previous.add(new ClassElement(new Class<?>[] { Integer.class, int.class }, "ZodInteger", "Integer", "isInteger",
|
||||||
|
"zod.number().safe()", false), true);
|
||||||
|
previous.add(new ClassElement(new Class<?>[] { Double.class, double.class }, "ZodDouble", "Double", "isDouble",
|
||||||
|
"zod.number()", true), true);
|
||||||
|
previous.add(new ClassElement(new Class<?>[] { Float.class, float.class }, "ZodFloat", "Float", "isFloat",
|
||||||
|
"zod.number()", false), true);
|
||||||
|
previous.add(new ClassElement(new Class<?>[] { Instant.class }, "ZodInstant", "Instant", "isInstant",
|
||||||
|
"zod.string()", false), true);
|
||||||
|
previous.add(new ClassElement(new Class<?>[] { Date.class }, "ZodDate", "Date", "isDate",
|
||||||
|
"zod.string().datetime({ precision: 3 })", false), true);
|
||||||
|
previous.add(new ClassElement(new Class<?>[] { Timestamp.class }, "ZodTimestamp", "Timestamp", "isTimestamp",
|
||||||
|
"zod.string().datetime({ precision: 3 })", false), true);
|
||||||
|
previous.add(new ClassElement(new Class<?>[] { LocalDate.class }, "ZodLocalDate", "LocalDate", "isLocalDate",
|
||||||
|
"zod.string().date()", false), true);
|
||||||
|
previous.add(new ClassElement(new Class<?>[] { LocalTime.class }, "ZodLocalTime", "LocalTime", "isLocalTime",
|
||||||
|
"zod.string().time()", false), true);
|
||||||
|
return previous;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Request the generation of the TypeScript file for the "Zod" export model
|
||||||
|
* @param classs List of class used in the model
|
||||||
|
* @return A string representing the Server models
|
||||||
|
* @throws Exception */
|
||||||
|
public static String createTables(final List<Class<?>> classs) throws Exception {
|
||||||
|
return createTables(classs, createBasicType());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String createTables(final List<Class<?>> classs, final GeneratedTypes previous) throws Exception {
|
||||||
|
for (final Class<?> clazz : classs) {
|
||||||
|
createTable(clazz, previous);
|
||||||
|
}
|
||||||
|
|
||||||
|
final StringBuilder generatedData = new StringBuilder();
|
||||||
|
generatedData.append("""
|
||||||
|
/**
|
||||||
|
* Interface of the server (auto-generated code)
|
||||||
|
*/
|
||||||
|
import { z as zod } from \"zod\";
|
||||||
|
|
||||||
|
""");
|
||||||
|
for (final Class<?> elem : previous.order) {
|
||||||
|
final ClassElement data = previous.find(elem);
|
||||||
|
if (!data.nativeType) {
|
||||||
|
if (data.comment != null) {
|
||||||
|
generatedData.append(data.comment);
|
||||||
|
}
|
||||||
|
generatedData.append(createDeclaration(data));
|
||||||
|
generatedData.append("\n\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
LOGGER.info("generated: {}", generatedData.toString());
|
||||||
|
return generatedData.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<ClassElement> createTables(final Class<?>[] classs, final GeneratedTypes previous)
|
||||||
|
throws Exception {
|
||||||
|
final List<ClassElement> out = new ArrayList<>();
|
||||||
|
for (final Class<?> clazz : classs) {
|
||||||
|
if (clazz == Response.class) {
|
||||||
|
throw new IOException("Can not generate a Zod element for an unknow type Response");
|
||||||
|
}
|
||||||
|
out.add(createTable(clazz, previous));
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ClassElement createTable(final Class<?> clazz, final GeneratedTypes previous) throws Exception {
|
||||||
|
if (clazz == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (clazz == Response.class) {
|
||||||
|
throw new IOException("Can not generate a Zod element for an unknow type Response");
|
||||||
|
}
|
||||||
|
final ClassElement alreadyExist = previous.find(clazz);
|
||||||
|
if (previous.find(clazz) != null) {
|
||||||
|
return alreadyExist;
|
||||||
|
}
|
||||||
|
if (clazz.isPrimitive()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (clazz.isEnum()) {
|
||||||
|
return convertTypeZodEnum(clazz, previous);
|
||||||
|
}
|
||||||
|
|
||||||
|
// add the current class to prevent multiple creation
|
||||||
|
final ClassElement curentElementClass = new ClassElement(clazz);
|
||||||
|
previous.add(curentElementClass);
|
||||||
|
// Local generation of class:
|
||||||
|
final StringBuilder internalBuilder = new StringBuilder();
|
||||||
|
final List<String> alreadyAdded = new ArrayList<>();
|
||||||
|
LOGGER.trace("parse class: '{}'", clazz.getCanonicalName());
|
||||||
|
int fieldId = 0;
|
||||||
|
for (final Field elem : clazz.getFields()) {
|
||||||
|
// static field is only for internal global declaration ==> remove it ..
|
||||||
|
if (java.lang.reflect.Modifier.isStatic(elem.getModifiers())) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
final String dataName = elem.getName();
|
||||||
|
if (isFieldFromSuperClass(clazz, dataName)) {
|
||||||
|
LOGGER.trace(" SKIP: '{}'", elem.getName());
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (alreadyAdded.contains(dataName)) {
|
||||||
|
LOGGER.trace(" SKIP2: '{}'", elem.getName());
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
alreadyAdded.add(dataName);
|
||||||
|
LOGGER.trace(" + '{}'", elem.getName());
|
||||||
|
if (false && DataAccess.isAddOnField(elem)) {
|
||||||
|
final DataAccessAddOn addOn = DataAccess.findAddOnforField(elem);
|
||||||
|
LOGGER.error("Create type for: {} ==> {} (ADD-ON) ==> Not managed now ....",
|
||||||
|
AnnotationTools.getFieldName(elem), elem.getType());
|
||||||
|
/* LOGGER.trace("Create type for: {} ==> {} (ADD-ON)", AnnotationTools.getFieldName(elem), elem.getType()); if (addOn != null) { addOn.createTables(tableName, elem, tmpOut,
|
||||||
|
* preActionList, postActionList, createIfNotExist, createDrop, fieldId); } else { throw new DataAccessException( "Element matked as add-on but add-on does not loaded: table:" +
|
||||||
|
* tableName + " field name=" + AnnotationTools.getFieldName(elem) + " type=" + elem.getType()); } fieldId++; */
|
||||||
|
} else {
|
||||||
|
LOGGER.trace("Create type for: {} ==> {}", AnnotationTools.getFieldName(elem), elem.getType());
|
||||||
|
DataFactoryZod.createTablesSpecificType(elem, fieldId, internalBuilder, previous);
|
||||||
|
fieldId++;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
final String description = AnnotationTools.getSchemaDescription(clazz);
|
||||||
|
final String example = AnnotationTools.getSchemaExample(clazz);
|
||||||
|
final StringBuilder generatedCommentedData = new StringBuilder();
|
||||||
|
if (description != null || example != null) {
|
||||||
|
generatedCommentedData.append("/**\n");
|
||||||
|
if (description != null) {
|
||||||
|
for (final String elem : description.split("\n")) {
|
||||||
|
generatedCommentedData.append(" * ");
|
||||||
|
generatedCommentedData.append(elem);
|
||||||
|
generatedCommentedData.append("\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (example != null) {
|
||||||
|
generatedCommentedData.append(" * Example:\n");
|
||||||
|
generatedCommentedData.append(" * ```\n");
|
||||||
|
for (final String elem : example.split("\n")) {
|
||||||
|
generatedCommentedData.append(" * ");
|
||||||
|
generatedCommentedData.append(elem);
|
||||||
|
generatedCommentedData.append("\n");
|
||||||
|
}
|
||||||
|
generatedCommentedData.append(" * ```\n");
|
||||||
|
}
|
||||||
|
generatedCommentedData.append(" */\n");
|
||||||
|
}
|
||||||
|
curentElementClass.comment = generatedCommentedData.toString();
|
||||||
|
final StringBuilder generatedData = new StringBuilder();
|
||||||
|
final Class<?> parentClass = clazz.getSuperclass();
|
||||||
|
if (parentClass != null && parentClass != Object.class && parentClass != Record.class) {
|
||||||
|
final ClassElement parentDeclaration = createTable(parentClass, previous);
|
||||||
|
generatedData.append(parentDeclaration.zodName);
|
||||||
|
generatedData.append(".extend({");
|
||||||
|
} else {
|
||||||
|
generatedData.append("zod.object({");
|
||||||
|
}
|
||||||
|
generatedData.append(internalBuilder.toString());
|
||||||
|
generatedData.append("\n})");
|
||||||
|
// Remove the previous to reorder the map ==> parent must be inserted before us.
|
||||||
|
curentElementClass.declaration = generatedData.toString();
|
||||||
|
previous.addOrder(curentElementClass);
|
||||||
|
return curentElementClass;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String createDeclaration(final ClassElement elem) {
|
||||||
|
final StringBuilder generatedData = new StringBuilder();
|
||||||
|
if (elem.isEnum) {
|
||||||
|
generatedData.append("export enum ");
|
||||||
|
generatedData.append(elem.tsTypeName);
|
||||||
|
generatedData.append(" ");
|
||||||
|
generatedData.append(elem.declaration);
|
||||||
|
generatedData.append(";");
|
||||||
|
generatedData.append("\nexport const ");
|
||||||
|
generatedData.append(elem.zodName);
|
||||||
|
generatedData.append(" = zod.nativeEnum(");
|
||||||
|
generatedData.append(elem.tsTypeName);
|
||||||
|
generatedData.append(");");
|
||||||
|
} else {
|
||||||
|
generatedData.append("export const ");
|
||||||
|
generatedData.append(elem.zodName);
|
||||||
|
generatedData.append(" = ");
|
||||||
|
generatedData.append(elem.declaration);
|
||||||
|
generatedData.append(";");
|
||||||
|
generatedData.append("\nexport type ");
|
||||||
|
generatedData.append(elem.tsTypeName);
|
||||||
|
generatedData.append(" = zod.infer<typeof ");
|
||||||
|
generatedData.append(elem.zodName);
|
||||||
|
generatedData.append(">;");
|
||||||
|
}
|
||||||
|
// declare generic isXXX:
|
||||||
|
generatedData.append("\nexport function ");
|
||||||
|
generatedData.append(elem.tsCheckType);
|
||||||
|
generatedData.append("(data: any): data is ");
|
||||||
|
generatedData.append(elem.tsTypeName);
|
||||||
|
generatedData.append(" {\n\ttry {\n\t\t");
|
||||||
|
generatedData.append(elem.zodName);
|
||||||
|
generatedData.append("""
|
||||||
|
.parse(data);
|
||||||
|
return true;
|
||||||
|
} catch (e: any) {
|
||||||
|
console.log(`Fail to parse data ${e}`);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
""");
|
||||||
|
return generatedData.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -13,7 +13,7 @@ public class AnalyzeApi {
|
|||||||
static final Logger LOGGER = LoggerFactory.getLogger(AnalyzeApi.class);
|
static final Logger LOGGER = LoggerFactory.getLogger(AnalyzeApi.class);
|
||||||
protected final List<ApiGroupModel> apiModels = new ArrayList<>();
|
protected final List<ApiGroupModel> apiModels = new ArrayList<>();
|
||||||
protected final ModelGroup modelGroup = new ModelGroup();
|
protected final ModelGroup modelGroup = new ModelGroup();
|
||||||
|
|
||||||
public void addAllModel(final List<Class<?>> classes) throws Exception {
|
public void addAllModel(final List<Class<?>> classes) throws Exception {
|
||||||
this.modelGroup.addAll(classes);
|
this.modelGroup.addAll(classes);
|
||||||
analyzeModels();
|
analyzeModels();
|
||||||
@@ -35,15 +35,15 @@ public class AnalyzeApi {
|
|||||||
}
|
}
|
||||||
analyzeModels();
|
analyzeModels();
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<ApiGroupModel> getAllApi() {
|
public List<ApiGroupModel> getAllApi() {
|
||||||
return this.apiModels;
|
return this.apiModels;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<ClassModel> getAllModel() {
|
public List<ClassModel> getAllModel() {
|
||||||
return this.modelGroup.getModels();
|
return this.modelGroup.getModels();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void analyzeModels() throws Exception {
|
private void analyzeModels() throws Exception {
|
||||||
final List<ClassModel> dones = new ArrayList<>();
|
final List<ClassModel> dones = new ArrayList<>();
|
||||||
while (dones.size() < getAllModel().size()) {
|
while (dones.size() < getAllModel().size()) {
|
||||||
|
@@ -1,8 +1,8 @@
|
|||||||
package org.kar.archidata.externalRestApi;
|
package org.kar.archidata.externalRestApi;
|
||||||
|
|
||||||
public class PythonGenerateApi {
|
public class PythonGenerateApi {
|
||||||
|
|
||||||
public static void generateApi(final AnalyzeApi api) {
|
public static void generateApi(final AnalyzeApi api) {
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -27,7 +27,7 @@ import jakarta.ws.rs.core.MediaType;
|
|||||||
|
|
||||||
public class TsApiGeneration {
|
public class TsApiGeneration {
|
||||||
static final Logger LOGGER = LoggerFactory.getLogger(TsApiGeneration.class);
|
static final Logger LOGGER = LoggerFactory.getLogger(TsApiGeneration.class);
|
||||||
|
|
||||||
public static String getBaseHeader() {
|
public static String getBaseHeader() {
|
||||||
return """
|
return """
|
||||||
/**
|
/**
|
||||||
@@ -130,14 +130,14 @@ public class TsApiGeneration {
|
|||||||
}
|
}
|
||||||
return out.toString();
|
return out.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String capitalizeFirstLetter(final String str) {
|
public static String capitalizeFirstLetter(final String str) {
|
||||||
if (str == null || str.isEmpty()) {
|
if (str == null || str.isEmpty()) {
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
return str.substring(0, 1).toUpperCase() + str.substring(1);
|
return str.substring(0, 1).toUpperCase() + str.substring(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void generateApiFile(
|
public static void generateApiFile(
|
||||||
final ApiGroupModel element,
|
final ApiGroupModel element,
|
||||||
final String pathPackage,
|
final String pathPackage,
|
||||||
@@ -429,5 +429,5 @@ public class TsApiGeneration {
|
|||||||
myWriter.write(out.toString());
|
myWriter.write(out.toString());
|
||||||
myWriter.close();
|
myWriter.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@@ -7,7 +7,6 @@ import java.nio.file.Files;
|
|||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map.Entry;
|
|
||||||
|
|
||||||
import org.kar.archidata.externalRestApi.model.ClassEnumModel;
|
import org.kar.archidata.externalRestApi.model.ClassEnumModel;
|
||||||
import org.kar.archidata.externalRestApi.model.ClassListModel;
|
import org.kar.archidata.externalRestApi.model.ClassListModel;
|
||||||
@@ -20,13 +19,13 @@ import org.slf4j.LoggerFactory;
|
|||||||
|
|
||||||
public class TsClassElement {
|
public class TsClassElement {
|
||||||
static final Logger LOGGER = LoggerFactory.getLogger(TsClassElement.class);
|
static final Logger LOGGER = LoggerFactory.getLogger(TsClassElement.class);
|
||||||
|
|
||||||
public enum DefinedPosition {
|
public enum DefinedPosition {
|
||||||
NATIVE, // Native element of TS language.
|
NATIVE, // Native element of TS language.
|
||||||
BASIC, // basic wrapping for JAVA type.
|
BASIC, // basic wrapping for JAVA type.
|
||||||
NORMAL // Normal Object to interpret.
|
NORMAL // Normal Object to interpret.
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<ClassModel> models;
|
public List<ClassModel> models;
|
||||||
public String zodName;
|
public String zodName;
|
||||||
public String tsTypeName;
|
public String tsTypeName;
|
||||||
@@ -35,7 +34,7 @@ public class TsClassElement {
|
|||||||
public String fileName = null;
|
public String fileName = null;
|
||||||
public String comment = null;
|
public String comment = null;
|
||||||
public DefinedPosition nativeType = DefinedPosition.NORMAL;
|
public DefinedPosition nativeType = DefinedPosition.NORMAL;
|
||||||
|
|
||||||
public static String determineFileName(final String className) {
|
public static String determineFileName(final String className) {
|
||||||
return className.replaceAll("([a-z])([A-Z])", "$1-$2").replaceAll("([A-Z])([A-Z][a-z])", "$1-$2").toLowerCase();
|
return className.replaceAll("([a-z])([A-Z])", "$1-$2").replaceAll("([A-Z])([A-Z][a-z])", "$1-$2").toLowerCase();
|
||||||
}
|
}
|
||||||
@@ -50,7 +49,7 @@ public class TsClassElement {
|
|||||||
this.nativeType = nativeType;
|
this.nativeType = nativeType;
|
||||||
this.fileName = determineFileName(tsTypeName);
|
this.fileName = determineFileName(tsTypeName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public TsClassElement(final ClassModel model) {
|
public TsClassElement(final ClassModel model) {
|
||||||
this.models = List.of(model);
|
this.models = List.of(model);
|
||||||
this.zodName = "Zod" + model.getOriginClasses().getSimpleName();
|
this.zodName = "Zod" + model.getOriginClasses().getSimpleName();
|
||||||
@@ -59,34 +58,34 @@ public class TsClassElement {
|
|||||||
this.declaration = null;
|
this.declaration = null;
|
||||||
this.fileName = determineFileName(this.tsTypeName);
|
this.fileName = determineFileName(this.tsTypeName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isCompatible(final ClassModel model) {
|
public boolean isCompatible(final ClassModel model) {
|
||||||
return this.models.contains(model);
|
return this.models.contains(model);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getBaseHeader() {
|
public String getBaseHeader() {
|
||||||
return """
|
return """
|
||||||
/**
|
/**
|
||||||
* Interface of the server (auto-generated code)
|
* Interface of the server (auto-generated code)
|
||||||
*/
|
*/
|
||||||
import { z as zod } from "zod";
|
import { z as zod } from "zod";
|
||||||
|
|
||||||
""";
|
""";
|
||||||
}
|
}
|
||||||
|
|
||||||
public String generateEnum(final ClassEnumModel model, final TsClassElementGroup tsGroup) throws IOException {
|
public String generateEnum(final ClassEnumModel model, final TsClassElementGroup tsGroup) throws IOException {
|
||||||
final StringBuilder out = new StringBuilder();
|
final StringBuilder out = new StringBuilder();
|
||||||
out.append(getBaseHeader());
|
out.append(getBaseHeader());
|
||||||
out.append("\n");
|
out.append("\n");
|
||||||
//out.append(generateComment(model));
|
//out.append(generateComment(model));
|
||||||
|
|
||||||
if (System.getenv("ARCHIDATA_GENERATE_ZOD_ENUM") != null) {
|
if (System.getenv("ARCHIDATA_GENERATE_ZOD_ENUM") != null) {
|
||||||
boolean first = true;
|
boolean first = true;
|
||||||
out.append("export const ");
|
out.append("export const ");
|
||||||
out.append(this.tsTypeName);
|
out.append(this.tsTypeName);
|
||||||
out.append(" = ");
|
out.append(" = ");
|
||||||
out.append("zod.enum([");
|
out.append("zod.enum([");
|
||||||
for (final Entry<String, Object> elem : model.getListOfValues().entrySet()) {
|
for (final String elem : model.getListOfValues()) {
|
||||||
if (!first) {
|
if (!first) {
|
||||||
out.append(",\n\t");
|
out.append(",\n\t");
|
||||||
} else {
|
} else {
|
||||||
@@ -94,7 +93,7 @@ public class TsClassElement {
|
|||||||
first = false;
|
first = false;
|
||||||
}
|
}
|
||||||
out.append("'");
|
out.append("'");
|
||||||
out.append(elem.getKey());
|
out.append(elem);
|
||||||
out.append("'");
|
out.append("'");
|
||||||
}
|
}
|
||||||
if (first) {
|
if (first) {
|
||||||
@@ -109,22 +108,17 @@ public class TsClassElement {
|
|||||||
out.append("export enum ");
|
out.append("export enum ");
|
||||||
out.append(this.tsTypeName);
|
out.append(this.tsTypeName);
|
||||||
out.append(" {");
|
out.append(" {");
|
||||||
for (final Entry<String, Object> elem : model.getListOfValues().entrySet()) {
|
for (final String elem : model.getListOfValues()) {
|
||||||
if (!first) {
|
if (!first) {
|
||||||
out.append(",\n\t");
|
out.append(",\n\t");
|
||||||
} else {
|
} else {
|
||||||
out.append("\n\t");
|
out.append("\n\t");
|
||||||
first = false;
|
first = false;
|
||||||
}
|
}
|
||||||
out.append(elem.getKey());
|
out.append(elem);
|
||||||
out.append(" = ");
|
out.append(" = '");
|
||||||
if (elem.getValue() instanceof final Integer value) {
|
out.append(elem);
|
||||||
out.append(value);
|
out.append("'");
|
||||||
} else {
|
|
||||||
out.append("'");
|
|
||||||
out.append(elem.getValue());
|
|
||||||
out.append("'");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (first) {
|
if (first) {
|
||||||
out.append("}");
|
out.append("}");
|
||||||
@@ -141,7 +135,7 @@ public class TsClassElement {
|
|||||||
out.append(generateExportCheckFunctionWrite(""));
|
out.append(generateExportCheckFunctionWrite(""));
|
||||||
return out.toString();
|
return out.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String generateExportCheckFunction(
|
private static String generateExportCheckFunction(
|
||||||
final String tsCheckType,
|
final String tsCheckType,
|
||||||
final String tsTypeName,
|
final String tsTypeName,
|
||||||
@@ -167,12 +161,12 @@ public class TsClassElement {
|
|||||||
""");
|
""");
|
||||||
return out.toString();
|
return out.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
private String generateExportCheckFunctionWrite(final String writeString) {
|
private String generateExportCheckFunctionWrite(final String writeString) {
|
||||||
return generateExportCheckFunction(this.tsCheckType + writeString, this.tsTypeName + writeString,
|
return generateExportCheckFunction(this.tsCheckType + writeString, this.tsTypeName + writeString,
|
||||||
this.zodName + writeString);
|
this.zodName + writeString);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String generateImports(final List<ClassModel> depModels, final TsClassElementGroup tsGroup)
|
public String generateImports(final List<ClassModel> depModels, final TsClassElementGroup tsGroup)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
final StringBuilder out = new StringBuilder();
|
final StringBuilder out = new StringBuilder();
|
||||||
@@ -188,7 +182,7 @@ public class TsClassElement {
|
|||||||
}
|
}
|
||||||
return out.toString();
|
return out.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
private Object generateComment(final ClassObjectModel model) {
|
private Object generateComment(final ClassObjectModel model) {
|
||||||
final StringBuilder out = new StringBuilder();
|
final StringBuilder out = new StringBuilder();
|
||||||
if (model.getDescription() != null || model.getExample() != null) {
|
if (model.getDescription() != null || model.getExample() != null) {
|
||||||
@@ -214,7 +208,7 @@ public class TsClassElement {
|
|||||||
}
|
}
|
||||||
return out.toString();
|
return out.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String optionalTypeZod(final FieldProperty field) {
|
public String optionalTypeZod(final FieldProperty field) {
|
||||||
if (field.model().getOriginClasses() == null || field.model().getOriginClasses().isPrimitive()) {
|
if (field.model().getOriginClasses() == null || field.model().getOriginClasses().isPrimitive()) {
|
||||||
return "";
|
return "";
|
||||||
@@ -242,12 +236,12 @@ public class TsClassElement {
|
|||||||
}
|
}
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
public String generateBaseObject() {
|
public String generateBaseObject() {
|
||||||
final StringBuilder out = new StringBuilder();
|
final StringBuilder out = new StringBuilder();
|
||||||
out.append(getBaseHeader());
|
out.append(getBaseHeader());
|
||||||
out.append("\n");
|
out.append("\n");
|
||||||
|
|
||||||
out.append("export const ");
|
out.append("export const ");
|
||||||
out.append(this.zodName);
|
out.append(this.zodName);
|
||||||
out.append(" = ");
|
out.append(" = ");
|
||||||
@@ -262,12 +256,12 @@ public class TsClassElement {
|
|||||||
out.append(getBaseHeader());
|
out.append(getBaseHeader());
|
||||||
out.append(generateImports(model.getDependencyModels(), tsGroup));
|
out.append(generateImports(model.getDependencyModels(), tsGroup));
|
||||||
out.append("\n");
|
out.append("\n");
|
||||||
|
|
||||||
out.append(generateComment(model));
|
out.append(generateComment(model));
|
||||||
out.append("export const ");
|
out.append("export const ");
|
||||||
out.append(this.zodName);
|
out.append(this.zodName);
|
||||||
out.append(" = ");
|
out.append(" = ");
|
||||||
|
|
||||||
if (model.getExtendsClass() != null) {
|
if (model.getExtendsClass() != null) {
|
||||||
final ClassModel parentClass = model.getExtendsClass();
|
final ClassModel parentClass = model.getExtendsClass();
|
||||||
final TsClassElement tsParentModel = tsGroup.find(parentClass);
|
final TsClassElement tsParentModel = tsGroup.find(parentClass);
|
||||||
@@ -307,7 +301,7 @@ public class TsClassElement {
|
|||||||
out.append("\n});\n");
|
out.append("\n});\n");
|
||||||
out.append(generateZodInfer(this.tsTypeName, this.zodName));
|
out.append(generateZodInfer(this.tsTypeName, this.zodName));
|
||||||
out.append(generateExportCheckFunctionWrite(""));
|
out.append(generateExportCheckFunctionWrite(""));
|
||||||
|
|
||||||
// Generate the Write Type associated.
|
// Generate the Write Type associated.
|
||||||
out.append("\nexport const ");
|
out.append("\nexport const ");
|
||||||
out.append(this.zodName);
|
out.append(this.zodName);
|
||||||
@@ -324,10 +318,10 @@ public class TsClassElement {
|
|||||||
}
|
}
|
||||||
out.append(".partial();\n");
|
out.append(".partial();\n");
|
||||||
out.append(generateZodInfer(this.tsTypeName + "Write", this.zodName + "Write"));
|
out.append(generateZodInfer(this.tsTypeName + "Write", this.zodName + "Write"));
|
||||||
|
|
||||||
// Check only the input value ==> no need of the output
|
// Check only the input value ==> no need of the output
|
||||||
out.append(generateExportCheckFunctionWrite("Write"));
|
out.append(generateExportCheckFunctionWrite("Write"));
|
||||||
|
|
||||||
return out.toString();
|
return out.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -374,17 +368,17 @@ public class TsClassElement {
|
|||||||
out.append(")");
|
out.append(")");
|
||||||
return out.toString();
|
return out.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String generateTsEnum(final ClassEnumModel model, final TsClassElementGroup tsGroup) {
|
private static String generateTsEnum(final ClassEnumModel model, final TsClassElementGroup tsGroup) {
|
||||||
final TsClassElement tsParentModel = tsGroup.find(model);
|
final TsClassElement tsParentModel = tsGroup.find(model);
|
||||||
return tsParentModel.zodName;
|
return tsParentModel.zodName;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String generateTsObject(final ClassObjectModel model, final TsClassElementGroup tsGroup) {
|
private static String generateTsObject(final ClassObjectModel model, final TsClassElementGroup tsGroup) {
|
||||||
final TsClassElement tsParentModel = tsGroup.find(model);
|
final TsClassElement tsParentModel = tsGroup.find(model);
|
||||||
return tsParentModel.zodName;
|
return tsParentModel.zodName;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String generateTsList(final ClassListModel model, final TsClassElementGroup tsGroup) {
|
private static String generateTsList(final ClassListModel model, final TsClassElementGroup tsGroup) {
|
||||||
final StringBuilder out = new StringBuilder();
|
final StringBuilder out = new StringBuilder();
|
||||||
out.append("zod.array(");
|
out.append("zod.array(");
|
||||||
@@ -401,7 +395,7 @@ public class TsClassElement {
|
|||||||
out.append(")");
|
out.append(")");
|
||||||
return out.toString();
|
return out.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void generateFile(final String pathPackage, final TsClassElementGroup tsGroup) throws IOException {
|
public void generateFile(final String pathPackage, final TsClassElementGroup tsGroup) throws IOException {
|
||||||
if (this.nativeType == DefinedPosition.NATIVE) {
|
if (this.nativeType == DefinedPosition.NATIVE) {
|
||||||
return;
|
return;
|
||||||
@@ -475,5 +469,5 @@ public class TsClassElement {
|
|||||||
out.append(generateExportCheckFunction("is" + ModelName, ModelName, "Zod" + ModelName));
|
out.append(generateExportCheckFunction("is" + ModelName, ModelName, "Zod" + ModelName));
|
||||||
return out.toString();
|
return out.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@@ -18,6 +18,7 @@ import java.util.Map;
|
|||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.kar.archidata.catcher.RestErrorResponse;
|
import org.kar.archidata.catcher.RestErrorResponse;
|
||||||
|
import org.kar.archidata.dataAccess.DataFactoryTsApi;
|
||||||
import org.kar.archidata.externalRestApi.TsClassElement.DefinedPosition;
|
import org.kar.archidata.externalRestApi.TsClassElement.DefinedPosition;
|
||||||
import org.kar.archidata.externalRestApi.model.ApiGroupModel;
|
import org.kar.archidata.externalRestApi.model.ApiGroupModel;
|
||||||
import org.kar.archidata.externalRestApi.model.ClassModel;
|
import org.kar.archidata.externalRestApi.model.ClassModel;
|
||||||
@@ -33,7 +34,7 @@ public class TsGenerateApi {
|
|||||||
}
|
}
|
||||||
// Generate index of model files
|
// Generate index of model files
|
||||||
createModelIndex(pathPackage, tsGroup);
|
createModelIndex(pathPackage, tsGroup);
|
||||||
|
|
||||||
for (final ApiGroupModel element : api.apiModels) {
|
for (final ApiGroupModel element : api.apiModels) {
|
||||||
TsApiGeneration.generateApiFile(element, pathPackage, tsGroup);
|
TsApiGeneration.generateApiFile(element, pathPackage, tsGroup);
|
||||||
}
|
}
|
||||||
@@ -42,7 +43,7 @@ public class TsGenerateApi {
|
|||||||
createIndex(pathPackage);
|
createIndex(pathPackage);
|
||||||
copyResourceFile("rest-tools.ts", pathPackage + File.separator + "rest-tools.ts");
|
copyResourceFile("rest-tools.ts", pathPackage + File.separator + "rest-tools.ts");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void createIndex(final String pathPackage) throws IOException {
|
private static void createIndex(final String pathPackage) throws IOException {
|
||||||
final String out = """
|
final String out = """
|
||||||
/**
|
/**
|
||||||
@@ -79,7 +80,7 @@ public class TsGenerateApi {
|
|||||||
myWriter.write(out.toString());
|
myWriter.write(out.toString());
|
||||||
myWriter.close();
|
myWriter.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void createModelIndex(final String pathPackage, final TsClassElementGroup tsGroup)
|
private static void createModelIndex(final String pathPackage, final TsClassElementGroup tsGroup)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
final StringBuilder out = new StringBuilder("""
|
final StringBuilder out = new StringBuilder("""
|
||||||
@@ -105,7 +106,7 @@ public class TsGenerateApi {
|
|||||||
myWriter.write(out.toString());
|
myWriter.write(out.toString());
|
||||||
myWriter.close();
|
myWriter.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static List<TsClassElement> generateApiModel(final AnalyzeApi api) throws Exception {
|
private static List<TsClassElement> generateApiModel(final AnalyzeApi api) throws Exception {
|
||||||
// First step is to add all specific basic elements the wrap correctly the model
|
// First step is to add all specific basic elements the wrap correctly the model
|
||||||
final List<TsClassElement> tsModels = new ArrayList<>();
|
final List<TsClassElement> tsModels = new ArrayList<>();
|
||||||
@@ -209,11 +210,11 @@ public class TsGenerateApi {
|
|||||||
tsModels.add(new TsClassElement(model));
|
tsModels.add(new TsClassElement(model));
|
||||||
}
|
}
|
||||||
return tsModels;
|
return tsModels;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void copyResourceFile(final String name, final String destinationPath) throws IOException {
|
public static void copyResourceFile(final String name, final String destinationPath) throws IOException {
|
||||||
final InputStream ioStream = TsGenerateApi.class.getClassLoader().getResourceAsStream(name);
|
final InputStream ioStream = DataFactoryTsApi.class.getClassLoader().getResourceAsStream(name);
|
||||||
if (ioStream == null) {
|
if (ioStream == null) {
|
||||||
throw new IllegalArgumentException("rest-tools.ts is not found");
|
throw new IllegalArgumentException("rest-tools.ts is not found");
|
||||||
}
|
}
|
||||||
|
@@ -14,10 +14,10 @@ import org.slf4j.LoggerFactory;
|
|||||||
|
|
||||||
public class ApiModel {
|
public class ApiModel {
|
||||||
static final Logger LOGGER = LoggerFactory.getLogger(ApiModel.class);
|
static final Logger LOGGER = LoggerFactory.getLogger(ApiModel.class);
|
||||||
|
|
||||||
Class<?> originClass;
|
Class<?> originClass;
|
||||||
Method orignMethod;
|
Method orignMethod;
|
||||||
|
|
||||||
// Name of the REST end-point name
|
// Name of the REST end-point name
|
||||||
public String restEndPoint;
|
public String restEndPoint;
|
||||||
// Type of the request:
|
// Type of the request:
|
||||||
@@ -26,7 +26,7 @@ public class ApiModel {
|
|||||||
public String description;
|
public String description;
|
||||||
// need to generate the progression of stream (if possible)
|
// need to generate the progression of stream (if possible)
|
||||||
public boolean needGenerateProgress;
|
public boolean needGenerateProgress;
|
||||||
|
|
||||||
// List of types returned by the API
|
// List of types returned by the API
|
||||||
public List<ClassModel> returnTypes = new ArrayList<>();;
|
public List<ClassModel> returnTypes = new ArrayList<>();;
|
||||||
// Name of the API (function name)
|
// Name of the API (function name)
|
||||||
@@ -39,12 +39,12 @@ public class ApiModel {
|
|||||||
public final Map<String, List<ClassModel>> multiPartParameters = new HashMap<>();
|
public final Map<String, List<ClassModel>> multiPartParameters = new HashMap<>();
|
||||||
// model of data available
|
// model of data available
|
||||||
public final List<ClassModel> unnamedElement = new ArrayList<>();
|
public final List<ClassModel> unnamedElement = new ArrayList<>();
|
||||||
|
|
||||||
// Possible input type of the REST API
|
// Possible input type of the REST API
|
||||||
public List<String> consumes = new ArrayList<>();
|
public List<String> consumes = new ArrayList<>();
|
||||||
// Possible output type of the REST API
|
// Possible output type of the REST API
|
||||||
public List<String> produces = new ArrayList<>();
|
public List<String> produces = new ArrayList<>();
|
||||||
|
|
||||||
private void updateReturnTypes(final Method method, final ModelGroup previousModel) throws Exception {
|
private void updateReturnTypes(final Method method, final ModelGroup previousModel) throws Exception {
|
||||||
// get return type from the user specification:
|
// get return type from the user specification:
|
||||||
final Class<?>[] returnTypeModel = ApiTool.apiAnnotationGetAsyncType(method);
|
final Class<?>[] returnTypeModel = ApiTool.apiAnnotationGetAsyncType(method);
|
||||||
@@ -66,7 +66,7 @@ public class ApiModel {
|
|||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final Class<?> returnTypeModelRaw = method.getReturnType();
|
final Class<?> returnTypeModelRaw = method.getReturnType();
|
||||||
LOGGER.info("Get return Type RAW = {}", returnTypeModelRaw.getCanonicalName());
|
LOGGER.info("Get return Type RAW = {}", returnTypeModelRaw.getCanonicalName());
|
||||||
if (returnTypeModelRaw == Map.class) {
|
if (returnTypeModelRaw == Map.class) {
|
||||||
@@ -92,12 +92,12 @@ public class ApiModel {
|
|||||||
LOGGER.warn(" - {}", elem);
|
LOGGER.warn(" - {}", elem);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public ApiModel(final Class<?> clazz, final Method method, final String baseRestEndPoint,
|
public ApiModel(final Class<?> clazz, final Method method, final String baseRestEndPoint,
|
||||||
final List<String> consume, final List<String> produce, final ModelGroup previousModel) throws Exception {
|
final List<String> consume, final List<String> produce, final ModelGroup previousModel) throws Exception {
|
||||||
this.originClass = clazz;
|
this.originClass = clazz;
|
||||||
this.orignMethod = method;
|
this.orignMethod = method;
|
||||||
|
|
||||||
String tmpPath = ApiTool.apiAnnotationGetPath(method);
|
String tmpPath = ApiTool.apiAnnotationGetPath(method);
|
||||||
if (tmpPath == null) {
|
if (tmpPath == null) {
|
||||||
tmpPath = "";
|
tmpPath = "";
|
||||||
@@ -105,19 +105,19 @@ public class ApiModel {
|
|||||||
this.restEndPoint = baseRestEndPoint + "/" + tmpPath;
|
this.restEndPoint = baseRestEndPoint + "/" + tmpPath;
|
||||||
this.restTypeRequest = ApiTool.apiAnnotationGetTypeRequest2(method);
|
this.restTypeRequest = ApiTool.apiAnnotationGetTypeRequest2(method);
|
||||||
this.name = method.getName();
|
this.name = method.getName();
|
||||||
|
|
||||||
this.description = ApiTool.apiAnnotationGetOperationDescription(method);
|
this.description = ApiTool.apiAnnotationGetOperationDescription(method);
|
||||||
this.consumes = ApiTool.apiAnnotationGetConsumes2(consume, method);
|
this.consumes = ApiTool.apiAnnotationGetConsumes2(consume, method);
|
||||||
this.produces = ApiTool.apiAnnotationProduces2(produce, method);
|
this.produces = ApiTool.apiAnnotationProduces2(produce, method);
|
||||||
LOGGER.trace(" [{}] {} => {}/{}", baseRestEndPoint, this.name, this.restEndPoint);
|
LOGGER.trace(" [{}] {} => {}/{}", baseRestEndPoint, this.name, this.restEndPoint);
|
||||||
this.needGenerateProgress = ApiTool.apiAnnotationTypeScriptProgress(method);
|
this.needGenerateProgress = ApiTool.apiAnnotationTypeScriptProgress(method);
|
||||||
|
|
||||||
updateReturnTypes(method, previousModel);
|
updateReturnTypes(method, previousModel);
|
||||||
LOGGER.trace(" return: {}", this.returnTypes.size());
|
LOGGER.trace(" return: {}", this.returnTypes.size());
|
||||||
for (final ClassModel elem : this.returnTypes) {
|
for (final ClassModel elem : this.returnTypes) {
|
||||||
LOGGER.trace(" - {}", elem);
|
LOGGER.trace(" - {}", elem);
|
||||||
}
|
}
|
||||||
|
|
||||||
// LOGGER.info(" Parameters:");
|
// LOGGER.info(" Parameters:");
|
||||||
for (final Parameter parameter : method.getParameters()) {
|
for (final Parameter parameter : method.getParameters()) {
|
||||||
// Security context are internal parameter (not available from API)
|
// Security context are internal parameter (not available from API)
|
||||||
@@ -142,7 +142,7 @@ public class ApiModel {
|
|||||||
} else {
|
} else {
|
||||||
parameterModel.add(previousModel.add(parameterType));
|
parameterModel.add(previousModel.add(parameterType));
|
||||||
}
|
}
|
||||||
|
|
||||||
final String pathParam = ApiTool.apiAnnotationGetPathParam(parameter);
|
final String pathParam = ApiTool.apiAnnotationGetPathParam(parameter);
|
||||||
final String queryParam = ApiTool.apiAnnotationGetQueryParam(parameter);
|
final String queryParam = ApiTool.apiAnnotationGetQueryParam(parameter);
|
||||||
final String formDataParam = ApiTool.apiAnnotationGetFormDataParam(parameter);
|
final String formDataParam = ApiTool.apiAnnotationGetFormDataParam(parameter);
|
||||||
@@ -159,6 +159,6 @@ public class ApiModel {
|
|||||||
if (this.unnamedElement.size() > 1) {
|
if (this.unnamedElement.size() > 1) {
|
||||||
throw new IOException("Can not parse the API, enmpty element is more than 1 in " + this.name);
|
throw new IOException("Can not parse the API, enmpty element is more than 1 in " + this.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -9,6 +9,7 @@ import java.util.List;
|
|||||||
import org.glassfish.jersey.media.multipart.FormDataParam;
|
import org.glassfish.jersey.media.multipart.FormDataParam;
|
||||||
import org.kar.archidata.annotation.AsyncType;
|
import org.kar.archidata.annotation.AsyncType;
|
||||||
import org.kar.archidata.annotation.TypeScriptProgress;
|
import org.kar.archidata.annotation.TypeScriptProgress;
|
||||||
|
import org.kar.archidata.dataAccess.DataFactoryZod.ClassElement;
|
||||||
|
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
import jakarta.ws.rs.Consumes;
|
import jakarta.ws.rs.Consumes;
|
||||||
@@ -205,4 +206,28 @@ public class ApiTool {
|
|||||||
return element.getDeclaredAnnotationsByType(Context.class).length != 0;
|
return element.getDeclaredAnnotationsByType(Context.class).length != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String convertInTypeScriptType(final List<ClassElement> tmp, final boolean isList) {
|
||||||
|
String out = "";
|
||||||
|
for (final ClassElement elem : tmp) {
|
||||||
|
if (out.length() != 0) {
|
||||||
|
out += " | ";
|
||||||
|
}
|
||||||
|
out += elem.tsTypeName;
|
||||||
|
if (isList) {
|
||||||
|
out += "[]";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String convertInTypeScriptCheckType(final List<ClassElement> tmp) {
|
||||||
|
String out = "";
|
||||||
|
for (final ClassElement elem : tmp) {
|
||||||
|
if (out.length() != 0) {
|
||||||
|
out += " | ";
|
||||||
|
}
|
||||||
|
out += elem.tsCheckType;
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,17 +1,16 @@
|
|||||||
package org.kar.archidata.externalRestApi.model;
|
package org.kar.archidata.externalRestApi.model;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.lang.reflect.Method;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public class ClassEnumModel extends ClassModel {
|
public class ClassEnumModel extends ClassModel {
|
||||||
|
|
||||||
protected ClassEnumModel(final Class<?> clazz) {
|
protected ClassEnumModel(final Class<?> clazz) {
|
||||||
this.originClasses = clazz;
|
this.originClasses = clazz;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
final StringBuilder out = new StringBuilder();
|
final StringBuilder out = new StringBuilder();
|
||||||
@@ -20,45 +19,33 @@ public class ClassEnumModel extends ClassModel {
|
|||||||
out.append("]");
|
out.append("]");
|
||||||
return out.toString();
|
return out.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
final Map<String, Object> listOfValues = new HashMap<>();
|
final List<String> listOfValues = new ArrayList<>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void analyze(final ModelGroup group) throws IOException {
|
public void analyze(final ModelGroup group) throws IOException {
|
||||||
if (this.analyzeDone) {
|
if (this.analyzeDone) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.analyzeDone = true;
|
this.analyzeDone = true;
|
||||||
|
// TODO: check if we really need to have multiple type for enums ???
|
||||||
|
// TODO: manage enum with int, String and bitField ...
|
||||||
final Class<?> clazz = this.originClasses;
|
final Class<?> clazz = this.originClasses;
|
||||||
final Object[] constants = clazz.getEnumConstants();
|
final Object[] arr = clazz.getEnumConstants();
|
||||||
|
for (final Object elem : arr) {
|
||||||
// Try to get a get Value element to serialize:
|
this.listOfValues.add(elem.toString());
|
||||||
try {
|
|
||||||
final Method getValueMethod = clazz.getMethod("getValue");
|
|
||||||
for (final Object constant : constants) {
|
|
||||||
final String name = constant.toString();
|
|
||||||
final Object value = getValueMethod.invoke(constant);
|
|
||||||
this.listOfValues.put(name, value);
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
} catch (final Exception e) {
|
|
||||||
//e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
for (final Object elem : constants) {
|
|
||||||
this.listOfValues.put(elem.toString(), elem.toString());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<String, Object> getListOfValues() {
|
public List<String> getListOfValues() {
|
||||||
return this.listOfValues;
|
return this.listOfValues;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<ClassModel> getAlls() {
|
public Set<ClassModel> getAlls() {
|
||||||
return Set.of(this);
|
return Set.of(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<ClassModel> getDependencyGroupModels() {
|
public Set<ClassModel> getDependencyGroupModels() {
|
||||||
return Set.of(this);
|
return Set.of(this);
|
||||||
|
@@ -7,39 +7,39 @@ import java.util.Set;
|
|||||||
|
|
||||||
public class ClassListModel extends ClassModel {
|
public class ClassListModel extends ClassModel {
|
||||||
public ClassModel valueModel;
|
public ClassModel valueModel;
|
||||||
|
|
||||||
public ClassListModel(final ClassModel valueModel) {
|
public ClassListModel(final ClassModel valueModel) {
|
||||||
this.valueModel = valueModel;
|
this.valueModel = valueModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ClassListModel(final Class<?> clazz, final ModelGroup previousModel) throws IOException {
|
public ClassListModel(final Class<?> clazz, final ModelGroup previousModel) throws IOException {
|
||||||
this.valueModel = getModel(clazz, previousModel);
|
this.valueModel = getModel(clazz, previousModel);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ClassListModel(final Type model, final ModelGroup previousModel) throws IOException {
|
public ClassListModel(final Type model, final ModelGroup previousModel) throws IOException {
|
||||||
this.valueModel = getModel(model, previousModel);
|
this.valueModel = getModel(model, previousModel);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ClassListModel(final ParameterizedType listType, final ModelGroup previousModel) throws IOException {
|
public ClassListModel(final ParameterizedType listType, final ModelGroup previousModel) throws IOException {
|
||||||
final Type model = listType.getActualTypeArguments()[0];
|
final Type model = listType.getActualTypeArguments()[0];
|
||||||
this.valueModel = getModel(model, previousModel);
|
this.valueModel = getModel(model, previousModel);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "ClassListModel [valueModel=" + this.valueModel + "]";
|
return "ClassListModel [valueModel=" + this.valueModel + "]";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void analyze(final ModelGroup group) throws IOException {
|
public void analyze(final ModelGroup group) throws IOException {
|
||||||
throw new IOException("Analyze can not be done at this phase for List...");
|
throw new IOException("Analyze can not be done at this phase for List...");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<ClassModel> getAlls() {
|
public Set<ClassModel> getAlls() {
|
||||||
return this.valueModel.getAlls();
|
return this.valueModel.getAlls();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<ClassModel> getDependencyGroupModels() {
|
public Set<ClassModel> getDependencyGroupModels() {
|
||||||
return this.valueModel.getDependencyGroupModels();
|
return this.valueModel.getDependencyGroupModels();
|
||||||
|
@@ -9,40 +9,40 @@ import java.util.Set;
|
|||||||
public class ClassMapModel extends ClassModel {
|
public class ClassMapModel extends ClassModel {
|
||||||
public ClassModel keyModel;
|
public ClassModel keyModel;
|
||||||
public ClassModel valueModel;
|
public ClassModel valueModel;
|
||||||
|
|
||||||
public ClassMapModel(final ClassModel keyModel, final ClassModel valueModel) {
|
public ClassMapModel(final ClassModel keyModel, final ClassModel valueModel) {
|
||||||
this.keyModel = keyModel;
|
this.keyModel = keyModel;
|
||||||
this.valueModel = valueModel;
|
this.valueModel = valueModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ClassMapModel(final Type listTypeKey, final Type listTypeValue, final ModelGroup previousModel)
|
public ClassMapModel(final Type listTypeKey, final Type listTypeValue, final ModelGroup previousModel)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
this.keyModel = getModel(listTypeKey, previousModel);
|
this.keyModel = getModel(listTypeKey, previousModel);
|
||||||
this.valueModel = getModel(listTypeValue, previousModel);
|
this.valueModel = getModel(listTypeValue, previousModel);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ClassMapModel(final ParameterizedType listType, final ModelGroup previousModel) throws IOException {
|
public ClassMapModel(final ParameterizedType listType, final ModelGroup previousModel) throws IOException {
|
||||||
this.keyModel = getModel(listType.getActualTypeArguments()[0], previousModel);
|
this.keyModel = getModel(listType.getActualTypeArguments()[0], previousModel);
|
||||||
this.valueModel = getModel(listType.getActualTypeArguments()[1], previousModel);
|
this.valueModel = getModel(listType.getActualTypeArguments()[1], previousModel);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "ClassMapModel [keyModel=" + this.keyModel + ", valueModel=" + this.valueModel + "]";
|
return "ClassMapModel [keyModel=" + this.keyModel + ", valueModel=" + this.valueModel + "]";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void analyze(final ModelGroup group) throws IOException {
|
public void analyze(final ModelGroup group) throws IOException {
|
||||||
throw new IOException("Analyze can not be done at this phase for Map...");
|
throw new IOException("Analyze can not be done at this phase for Map...");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<ClassModel> getAlls() {
|
public Set<ClassModel> getAlls() {
|
||||||
final Set<ClassModel> out = new HashSet<>(this.keyModel.getAlls());
|
final Set<ClassModel> out = new HashSet<>(this.keyModel.getAlls());
|
||||||
out.addAll(this.valueModel.getAlls());
|
out.addAll(this.valueModel.getAlls());
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<ClassModel> getDependencyGroupModels() {
|
public Set<ClassModel> getDependencyGroupModels() {
|
||||||
final Set<ClassModel> out = new HashSet<>(this.valueModel.getDependencyGroupModels());
|
final Set<ClassModel> out = new HashSet<>(this.valueModel.getDependencyGroupModels());
|
||||||
|
@@ -24,7 +24,7 @@ public abstract class ClassModel {
|
|||||||
public List<ClassModel> getDependencyModels() {
|
public List<ClassModel> getDependencyModels() {
|
||||||
return this.dependencyModels;
|
return this.dependencyModels;
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract Set<ClassModel> getDependencyGroupModels();
|
public abstract Set<ClassModel> getDependencyGroupModels();
|
||||||
|
|
||||||
public static ClassModel getModel(final Type type, final ModelGroup previousModel) throws IOException {
|
public static ClassModel getModel(final Type type, final ModelGroup previousModel) throws IOException {
|
||||||
@@ -70,7 +70,7 @@ public abstract class ClassModel {
|
|||||||
public abstract void analyze(final ModelGroup group) throws Exception;
|
public abstract void analyze(final ModelGroup group) throws Exception;
|
||||||
|
|
||||||
public abstract Set<ClassModel> getAlls();
|
public abstract Set<ClassModel> getAlls();
|
||||||
|
|
||||||
public List<String> getReadOnlyField() {
|
public List<String> getReadOnlyField() {
|
||||||
return List.of();
|
return List.of();
|
||||||
}
|
}
|
||||||
|
@@ -15,11 +15,11 @@ import org.slf4j.LoggerFactory;
|
|||||||
|
|
||||||
public class ClassObjectModel extends ClassModel {
|
public class ClassObjectModel extends ClassModel {
|
||||||
static final Logger LOGGER = LoggerFactory.getLogger(ClassObjectModel.class);
|
static final Logger LOGGER = LoggerFactory.getLogger(ClassObjectModel.class);
|
||||||
|
|
||||||
public ClassObjectModel(final Class<?> clazz) {
|
public ClassObjectModel(final Class<?> clazz) {
|
||||||
this.originClasses = clazz;
|
this.originClasses = clazz;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
final StringBuilder out = new StringBuilder();
|
final StringBuilder out = new StringBuilder();
|
||||||
@@ -28,7 +28,7 @@ public class ClassObjectModel extends ClassModel {
|
|||||||
out.append("]");
|
out.append("]");
|
||||||
return out.toString();
|
return out.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isFieldFromSuperClass(final Class<?> model, final String filedName) {
|
private static boolean isFieldFromSuperClass(final Class<?> model, final String filedName) {
|
||||||
final Class<?> superClass = model.getSuperclass();
|
final Class<?> superClass = model.getSuperclass();
|
||||||
if (superClass == null) {
|
if (superClass == null) {
|
||||||
@@ -48,7 +48,7 @@ public class ClassObjectModel extends ClassModel {
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public record FieldProperty(
|
public record FieldProperty(
|
||||||
String name,
|
String name,
|
||||||
ClassModel model,
|
ClassModel model,
|
||||||
@@ -57,7 +57,7 @@ public class ClassObjectModel extends ClassModel {
|
|||||||
boolean readOnly,
|
boolean readOnly,
|
||||||
boolean notNull,
|
boolean notNull,
|
||||||
boolean nullable) {
|
boolean nullable) {
|
||||||
|
|
||||||
public FieldProperty(final String name, final ClassModel model, final String comment, final int limitSize,
|
public FieldProperty(final String name, final ClassModel model, final String comment, final int limitSize,
|
||||||
final boolean readOnly, final boolean notNull, final boolean nullable) {
|
final boolean readOnly, final boolean notNull, final boolean nullable) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
@@ -67,9 +67,9 @@ public class ClassObjectModel extends ClassModel {
|
|||||||
this.readOnly = readOnly;
|
this.readOnly = readOnly;
|
||||||
this.notNull = notNull;
|
this.notNull = notNull;
|
||||||
this.nullable = nullable;
|
this.nullable = nullable;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public FieldProperty(final Field field, final ModelGroup previous) throws Exception {
|
public FieldProperty(final Field field, final ModelGroup previous) throws Exception {
|
||||||
this(field.getName(), //
|
this(field.getName(), //
|
||||||
ClassModel.getModel(field.getGenericType(), previous), //
|
ClassModel.getModel(field.getGenericType(), previous), //
|
||||||
@@ -79,40 +79,40 @@ public class ClassObjectModel extends ClassModel {
|
|||||||
AnnotationTools.getConstraintsNotNull(field), //
|
AnnotationTools.getConstraintsNotNull(field), //
|
||||||
AnnotationTools.getColumnNotNull(field));
|
AnnotationTools.getColumnNotNull(field));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
String name = "";
|
String name = "";
|
||||||
boolean isPrimitive = false;
|
boolean isPrimitive = false;
|
||||||
String description = null;
|
String description = null;
|
||||||
String example = null;
|
String example = null;
|
||||||
ClassModel extendsClass = null;
|
ClassModel extendsClass = null;
|
||||||
List<FieldProperty> fields = new ArrayList<>();
|
List<FieldProperty> fields = new ArrayList<>();
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return this.name;
|
return this.name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isPrimitive() {
|
public boolean isPrimitive() {
|
||||||
return this.isPrimitive;
|
return this.isPrimitive;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getDescription() {
|
public String getDescription() {
|
||||||
return this.description;
|
return this.description;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getExample() {
|
public String getExample() {
|
||||||
return this.example;
|
return this.example;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ClassModel getExtendsClass() {
|
public ClassModel getExtendsClass() {
|
||||||
return this.extendsClass;
|
return this.extendsClass;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<FieldProperty> getFields() {
|
public List<FieldProperty> getFields() {
|
||||||
return this.fields;
|
return this.fields;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void analyze(final ModelGroup previous) throws Exception {
|
public void analyze(final ModelGroup previous) throws Exception {
|
||||||
if (this.analyzeDone) {
|
if (this.analyzeDone) {
|
||||||
@@ -174,17 +174,17 @@ public class ClassObjectModel extends ClassModel {
|
|||||||
this.dependencyModels.add(this.extendsClass);
|
this.dependencyModels.add(this.extendsClass);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<ClassModel> getDependencyGroupModels() {
|
public Set<ClassModel> getDependencyGroupModels() {
|
||||||
return Set.of(this);
|
return Set.of(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<ClassModel> getAlls() {
|
public Set<ClassModel> getAlls() {
|
||||||
return Set.of(this);
|
return Set.of(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<String> getReadOnlyField() {
|
public List<String> getReadOnlyField() {
|
||||||
final List<String> out = new ArrayList<>();
|
final List<String> out = new ArrayList<>();
|
||||||
@@ -198,5 +198,5 @@ public class ClassObjectModel extends ClassModel {
|
|||||||
}
|
}
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -13,13 +13,13 @@ public class ModelGroup {
|
|||||||
public List<ClassModel> models = new ArrayList<>();
|
public List<ClassModel> models = new ArrayList<>();
|
||||||
|
|
||||||
public ModelGroup() {}
|
public ModelGroup() {}
|
||||||
|
|
||||||
public void addAll(final List<Class<?>> classes) {
|
public void addAll(final List<Class<?>> classes) {
|
||||||
for (final Class<?> clazz : classes) {
|
for (final Class<?> clazz : classes) {
|
||||||
add(clazz);
|
add(clazz);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public ClassModel add(Class<?> clazz) {
|
public ClassModel add(Class<?> clazz) {
|
||||||
if (clazz == Response.class) {
|
if (clazz == Response.class) {
|
||||||
clazz = Object.class;
|
clazz = Object.class;
|
||||||
|
@@ -8,13 +8,13 @@ import jakarta.persistence.Column;
|
|||||||
public class GetToken {
|
public class GetToken {
|
||||||
@Column(length = -1, nullable = false)
|
@Column(length = -1, nullable = false)
|
||||||
public String jwt;
|
public String jwt;
|
||||||
|
|
||||||
public GetToken() {
|
public GetToken() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public GetToken(final String jwt) {
|
public GetToken(final String jwt) {
|
||||||
this.jwt = jwt;
|
this.jwt = jwt;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -9,9 +9,9 @@ public class Token {
|
|||||||
public String token;
|
public String token;
|
||||||
public String createTime;
|
public String createTime;
|
||||||
public String endValidityTime;
|
public String endValidityTime;
|
||||||
|
|
||||||
public Token() {}
|
public Token() {}
|
||||||
|
|
||||||
public Token(final long id, final long userId, final String token, final String createTime,
|
public Token(final long id, final long userId, final String token, final String createTime,
|
||||||
final String endValidityTime) {
|
final String endValidityTime) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
@@ -20,7 +20,7 @@ public class Token {
|
|||||||
this.createTime = createTime;
|
this.createTime = createTime;
|
||||||
this.endValidityTime = endValidityTime;
|
this.endValidityTime = endValidityTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Token(final ResultSet rs) {
|
public Token(final ResultSet rs) {
|
||||||
int iii = 1;
|
int iii = 1;
|
||||||
try {
|
try {
|
||||||
@@ -33,7 +33,7 @@ public class Token {
|
|||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "Token{" + "id=" + this.id + ", userId=" + this.userId + ", token='" + this.token + '\''
|
return "Token{" + "id=" + this.id + ", userId=" + this.userId + ", token='" + this.token + '\''
|
||||||
|
@@ -31,15 +31,15 @@ public class TestAnalyzeApiName {
|
|||||||
final AnalyzeApi api = new AnalyzeApi();
|
final AnalyzeApi api = new AnalyzeApi();
|
||||||
api.addAllApi(List.of(ApiName.class));
|
api.addAllApi(List.of(ApiName.class));
|
||||||
|
|
||||||
Assertions.assertEquals(1, api.getAllApi().size());
|
Assertions.assertEquals(1, api.apiModels.size());
|
||||||
Assertions.assertEquals("ApiName", api.getAllApi().get(0).name);
|
Assertions.assertEquals("ApiName", api.apiModels.get(0).name);
|
||||||
Assertions.assertEquals(2, api.getAllApi().get(0).interfaces.size());
|
Assertions.assertEquals(2, api.apiModels.get(0).interfaces.size());
|
||||||
{
|
{
|
||||||
final ApiModel model = api.getAllApi().get(0).getInterfaceNamed("firstName");
|
final ApiModel model = api.apiModels.get(0).getInterfaceNamed("firstName");
|
||||||
Assertions.assertNotNull(model);
|
Assertions.assertNotNull(model);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
final ApiModel model = api.getAllApi().get(0).getInterfaceNamed("SecondName");
|
final ApiModel model = api.apiModels.get(0).getInterfaceNamed("SecondName");
|
||||||
Assertions.assertNotNull(model);
|
Assertions.assertNotNull(model);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,17 @@
|
|||||||
|
package test.kar.archidata.externalRestApi;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Assertions;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
public class TestAnalyzeApiParameterParamQuery {
|
||||||
|
final static private Logger LOGGER = LoggerFactory.getLogger(TestAnalyzeApiParameterParamQuery.class);
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testNotImplemented() throws Exception {
|
||||||
|
Assertions.assertEquals(1, 0);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -49,10 +49,10 @@ public class TestAnalyzeApiParameterType {
|
|||||||
final AnalyzeApi api = new AnalyzeApi();
|
final AnalyzeApi api = new AnalyzeApi();
|
||||||
api.addAllApi(List.of(BasicParameter.class));
|
api.addAllApi(List.of(BasicParameter.class));
|
||||||
|
|
||||||
Assertions.assertEquals(1, api.getAllApi().size());
|
Assertions.assertEquals(1, api.apiModels.size());
|
||||||
Assertions.assertEquals(5, api.getAllApi().get(0).interfaces.size());
|
Assertions.assertEquals(5, api.apiModels.get(0).interfaces.size());
|
||||||
{
|
{
|
||||||
final ApiModel model = api.getAllApi().get(0).getInterfaceNamed("setInteger1");
|
final ApiModel model = api.apiModels.get(0).getInterfaceNamed("setInteger1");
|
||||||
Assertions.assertNotNull(model);
|
Assertions.assertNotNull(model);
|
||||||
Assertions.assertEquals(1, model.unnamedElement.size());
|
Assertions.assertEquals(1, model.unnamedElement.size());
|
||||||
final ClassObjectModel classModel = Assertions.assertInstanceOf(ClassObjectModel.class,
|
final ClassObjectModel classModel = Assertions.assertInstanceOf(ClassObjectModel.class,
|
||||||
@@ -60,7 +60,7 @@ public class TestAnalyzeApiParameterType {
|
|||||||
Assertions.assertEquals(int.class, classModel.getOriginClasses());
|
Assertions.assertEquals(int.class, classModel.getOriginClasses());
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
final ApiModel model = api.getAllApi().get(0).getInterfaceNamed("setInteger2");
|
final ApiModel model = api.apiModels.get(0).getInterfaceNamed("setInteger2");
|
||||||
Assertions.assertNotNull(model);
|
Assertions.assertNotNull(model);
|
||||||
Assertions.assertEquals(1, model.unnamedElement.size());
|
Assertions.assertEquals(1, model.unnamedElement.size());
|
||||||
final ClassObjectModel classModel = Assertions.assertInstanceOf(ClassObjectModel.class,
|
final ClassObjectModel classModel = Assertions.assertInstanceOf(ClassObjectModel.class,
|
||||||
@@ -68,7 +68,7 @@ public class TestAnalyzeApiParameterType {
|
|||||||
Assertions.assertEquals(Integer.class, classModel.getOriginClasses());
|
Assertions.assertEquals(Integer.class, classModel.getOriginClasses());
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
final ApiModel model = api.getAllApi().get(0).getInterfaceNamed("setString");
|
final ApiModel model = api.apiModels.get(0).getInterfaceNamed("setString");
|
||||||
Assertions.assertNotNull(model);
|
Assertions.assertNotNull(model);
|
||||||
Assertions.assertEquals(1, model.unnamedElement.size());
|
Assertions.assertEquals(1, model.unnamedElement.size());
|
||||||
final ClassObjectModel classModel = Assertions.assertInstanceOf(ClassObjectModel.class,
|
final ClassObjectModel classModel = Assertions.assertInstanceOf(ClassObjectModel.class,
|
||||||
@@ -76,7 +76,7 @@ public class TestAnalyzeApiParameterType {
|
|||||||
Assertions.assertEquals(String.class, classModel.getOriginClasses());
|
Assertions.assertEquals(String.class, classModel.getOriginClasses());
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
final ApiModel model = api.getAllApi().get(0).getInterfaceNamed("setObject");
|
final ApiModel model = api.apiModels.get(0).getInterfaceNamed("setObject");
|
||||||
Assertions.assertNotNull(model);
|
Assertions.assertNotNull(model);
|
||||||
Assertions.assertEquals(1, model.unnamedElement.size());
|
Assertions.assertEquals(1, model.unnamedElement.size());
|
||||||
final ClassObjectModel classModel = Assertions.assertInstanceOf(ClassObjectModel.class,
|
final ClassObjectModel classModel = Assertions.assertInstanceOf(ClassObjectModel.class,
|
||||||
@@ -84,7 +84,7 @@ public class TestAnalyzeApiParameterType {
|
|||||||
Assertions.assertEquals(TestObject.class, classModel.getOriginClasses());
|
Assertions.assertEquals(TestObject.class, classModel.getOriginClasses());
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
final ApiModel model = api.getAllApi().get(0).getInterfaceNamed("setEnum");
|
final ApiModel model = api.apiModels.get(0).getInterfaceNamed("setEnum");
|
||||||
Assertions.assertNotNull(model);
|
Assertions.assertNotNull(model);
|
||||||
Assertions.assertEquals(1, model.unnamedElement.size());
|
Assertions.assertEquals(1, model.unnamedElement.size());
|
||||||
final ClassEnumModel classModel = Assertions.assertInstanceOf(ClassEnumModel.class,
|
final ClassEnumModel classModel = Assertions.assertInstanceOf(ClassEnumModel.class,
|
||||||
@@ -104,9 +104,9 @@ public class TestAnalyzeApiParameterType {
|
|||||||
final AnalyzeApi api = new AnalyzeApi();
|
final AnalyzeApi api = new AnalyzeApi();
|
||||||
api.addAllApi(List.of(ListParameter.class));
|
api.addAllApi(List.of(ListParameter.class));
|
||||||
|
|
||||||
Assertions.assertEquals(1, api.getAllApi().size());
|
Assertions.assertEquals(1, api.apiModels.size());
|
||||||
Assertions.assertEquals(1, api.getAllApi().get(0).interfaces.size());
|
Assertions.assertEquals(1, api.apiModels.get(0).interfaces.size());
|
||||||
final ApiModel model = api.getAllApi().get(0).getInterfaceNamed("setList");
|
final ApiModel model = api.apiModels.get(0).getInterfaceNamed("setList");
|
||||||
Assertions.assertNotNull(model);
|
Assertions.assertNotNull(model);
|
||||||
Assertions.assertEquals(1, model.unnamedElement.size());
|
Assertions.assertEquals(1, model.unnamedElement.size());
|
||||||
final ClassListModel classModel = Assertions.assertInstanceOf(ClassListModel.class,
|
final ClassListModel classModel = Assertions.assertInstanceOf(ClassListModel.class,
|
||||||
@@ -127,9 +127,9 @@ public class TestAnalyzeApiParameterType {
|
|||||||
final AnalyzeApi api = new AnalyzeApi();
|
final AnalyzeApi api = new AnalyzeApi();
|
||||||
api.addAllApi(List.of(MapParameter.class));
|
api.addAllApi(List.of(MapParameter.class));
|
||||||
|
|
||||||
Assertions.assertEquals(1, api.getAllApi().size());
|
Assertions.assertEquals(1, api.apiModels.size());
|
||||||
Assertions.assertEquals(1, api.getAllApi().get(0).interfaces.size());
|
Assertions.assertEquals(1, api.apiModels.get(0).interfaces.size());
|
||||||
final ApiModel model = api.getAllApi().get(0).getInterfaceNamed("setMap");
|
final ApiModel model = api.apiModels.get(0).getInterfaceNamed("setMap");
|
||||||
Assertions.assertNotNull(model);
|
Assertions.assertNotNull(model);
|
||||||
Assertions.assertEquals(1, model.unnamedElement.size());
|
Assertions.assertEquals(1, model.unnamedElement.size());
|
||||||
final ClassMapModel classModel = Assertions.assertInstanceOf(ClassMapModel.class, model.unnamedElement.get(0));
|
final ClassMapModel classModel = Assertions.assertInstanceOf(ClassMapModel.class, model.unnamedElement.get(0));
|
||||||
|
@@ -0,0 +1,17 @@
|
|||||||
|
package test.kar.archidata.externalRestApi;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Assertions;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
public class TestAnalyzeApiParameterTypeAsync {
|
||||||
|
final static private Logger LOGGER = LoggerFactory.getLogger(TestAnalyzeApiParameterTypeAsync.class);
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testNotImplemented() throws Exception {
|
||||||
|
Assertions.assertEquals(1, 0);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -39,21 +39,21 @@ public class TestAnalyzeApiPath {
|
|||||||
final AnalyzeApi api = new AnalyzeApi();
|
final AnalyzeApi api = new AnalyzeApi();
|
||||||
api.addAllApi(List.of(NoPath.class));
|
api.addAllApi(List.of(NoPath.class));
|
||||||
|
|
||||||
Assertions.assertEquals(1, api.getAllApi().size());
|
Assertions.assertEquals(1, api.apiModels.size());
|
||||||
Assertions.assertEquals("", api.getAllApi().get(0).restEndPoint);
|
Assertions.assertEquals("", api.apiModels.get(0).restEndPoint);
|
||||||
Assertions.assertEquals(3, api.getAllApi().get(0).interfaces.size());
|
Assertions.assertEquals(3, api.apiModels.get(0).interfaces.size());
|
||||||
{
|
{
|
||||||
final ApiModel model = api.getAllApi().get(0).getInterfaceNamed("noPath");
|
final ApiModel model = api.apiModels.get(0).getInterfaceNamed("noPath");
|
||||||
Assertions.assertNotNull(model);
|
Assertions.assertNotNull(model);
|
||||||
Assertions.assertEquals("/", model.restEndPoint);
|
Assertions.assertEquals("/", model.restEndPoint);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
final ApiModel model = api.getAllApi().get(0).getInterfaceNamed("withPath");
|
final ApiModel model = api.apiModels.get(0).getInterfaceNamed("withPath");
|
||||||
Assertions.assertNotNull(model);
|
Assertions.assertNotNull(model);
|
||||||
Assertions.assertEquals("/plop", model.restEndPoint);
|
Assertions.assertEquals("/plop", model.restEndPoint);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
final ApiModel model = api.getAllApi().get(0).getInterfaceNamed("withPath2");
|
final ApiModel model = api.apiModels.get(0).getInterfaceNamed("withPath2");
|
||||||
Assertions.assertNotNull(model);
|
Assertions.assertNotNull(model);
|
||||||
Assertions.assertEquals("//plop", model.restEndPoint);
|
Assertions.assertEquals("//plop", model.restEndPoint);
|
||||||
}
|
}
|
||||||
@@ -84,21 +84,21 @@ public class TestAnalyzeApiPath {
|
|||||||
final AnalyzeApi api = new AnalyzeApi();
|
final AnalyzeApi api = new AnalyzeApi();
|
||||||
api.addAllApi(List.of(WithPath.class));
|
api.addAllApi(List.of(WithPath.class));
|
||||||
|
|
||||||
Assertions.assertEquals(1, api.getAllApi().size());
|
Assertions.assertEquals(1, api.apiModels.size());
|
||||||
Assertions.assertEquals("/kaboom", api.getAllApi().get(0).restEndPoint);
|
Assertions.assertEquals("/kaboom", api.apiModels.get(0).restEndPoint);
|
||||||
Assertions.assertEquals(3, api.getAllApi().get(0).interfaces.size());
|
Assertions.assertEquals(3, api.apiModels.get(0).interfaces.size());
|
||||||
{
|
{
|
||||||
final ApiModel model = api.getAllApi().get(0).getInterfaceNamed("noPath");
|
final ApiModel model = api.apiModels.get(0).getInterfaceNamed("noPath");
|
||||||
Assertions.assertNotNull(model);
|
Assertions.assertNotNull(model);
|
||||||
Assertions.assertEquals("/kaboom/", model.restEndPoint);
|
Assertions.assertEquals("/kaboom/", model.restEndPoint);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
final ApiModel model = api.getAllApi().get(0).getInterfaceNamed("withPath");
|
final ApiModel model = api.apiModels.get(0).getInterfaceNamed("withPath");
|
||||||
Assertions.assertNotNull(model);
|
Assertions.assertNotNull(model);
|
||||||
Assertions.assertEquals("/kaboom/plop", model.restEndPoint);
|
Assertions.assertEquals("/kaboom/plop", model.restEndPoint);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
final ApiModel model = api.getAllApi().get(0).getInterfaceNamed("withPath2");
|
final ApiModel model = api.apiModels.get(0).getInterfaceNamed("withPath2");
|
||||||
Assertions.assertNotNull(model);
|
Assertions.assertNotNull(model);
|
||||||
Assertions.assertEquals("/kaboom//plop", model.restEndPoint);
|
Assertions.assertEquals("/kaboom//plop", model.restEndPoint);
|
||||||
}
|
}
|
||||||
|
@@ -43,10 +43,10 @@ public class TestAnalyzeApiReturn {
|
|||||||
final AnalyzeApi api = new AnalyzeApi();
|
final AnalyzeApi api = new AnalyzeApi();
|
||||||
api.addAllApi(List.of(ReturnValueVoid.class));
|
api.addAllApi(List.of(ReturnValueVoid.class));
|
||||||
|
|
||||||
Assertions.assertEquals(1, api.getAllApi().size());
|
Assertions.assertEquals(1, api.apiModels.size());
|
||||||
Assertions.assertEquals(2, api.getAllApi().get(0).interfaces.size());
|
Assertions.assertEquals(2, api.apiModels.get(0).interfaces.size());
|
||||||
{
|
{
|
||||||
final ApiModel model = api.getAllApi().get(0).getInterfaceNamed("getVoid1");
|
final ApiModel model = api.apiModels.get(0).getInterfaceNamed("getVoid1");
|
||||||
Assertions.assertNotNull(model);
|
Assertions.assertNotNull(model);
|
||||||
Assertions.assertEquals(1, model.returnTypes.size());
|
Assertions.assertEquals(1, model.returnTypes.size());
|
||||||
final ClassObjectModel classModel = Assertions.assertInstanceOf(ClassObjectModel.class,
|
final ClassObjectModel classModel = Assertions.assertInstanceOf(ClassObjectModel.class,
|
||||||
@@ -54,7 +54,7 @@ public class TestAnalyzeApiReturn {
|
|||||||
Assertions.assertEquals(void.class, classModel.getOriginClasses());
|
Assertions.assertEquals(void.class, classModel.getOriginClasses());
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
final ApiModel model = api.getAllApi().get(0).getInterfaceNamed("getVoid2");
|
final ApiModel model = api.apiModels.get(0).getInterfaceNamed("getVoid2");
|
||||||
Assertions.assertNotNull(model);
|
Assertions.assertNotNull(model);
|
||||||
Assertions.assertEquals(1, model.returnTypes.size());
|
Assertions.assertEquals(1, model.returnTypes.size());
|
||||||
final ClassObjectModel classModel = Assertions.assertInstanceOf(ClassObjectModel.class,
|
final ClassObjectModel classModel = Assertions.assertInstanceOf(ClassObjectModel.class,
|
||||||
@@ -82,11 +82,11 @@ public class TestAnalyzeApiReturn {
|
|||||||
final AnalyzeApi api = new AnalyzeApi();
|
final AnalyzeApi api = new AnalyzeApi();
|
||||||
api.addAllApi(List.of(ReturnValueInteger.class));
|
api.addAllApi(List.of(ReturnValueInteger.class));
|
||||||
|
|
||||||
Assertions.assertEquals(1, api.getAllApi().size());
|
Assertions.assertEquals(1, api.apiModels.size());
|
||||||
Assertions.assertEquals(2, api.getAllApi().get(0).interfaces.size());
|
Assertions.assertEquals(2, api.apiModels.get(0).interfaces.size());
|
||||||
// Check int
|
// Check int
|
||||||
{
|
{
|
||||||
final ApiModel model = api.getAllApi().get(0).getInterfaceNamed("getInteger1");
|
final ApiModel model = api.apiModels.get(0).getInterfaceNamed("getInteger1");
|
||||||
Assertions.assertNotNull(model);
|
Assertions.assertNotNull(model);
|
||||||
Assertions.assertEquals(1, model.returnTypes.size());
|
Assertions.assertEquals(1, model.returnTypes.size());
|
||||||
final ClassObjectModel classModel = Assertions.assertInstanceOf(ClassObjectModel.class,
|
final ClassObjectModel classModel = Assertions.assertInstanceOf(ClassObjectModel.class,
|
||||||
@@ -95,7 +95,7 @@ public class TestAnalyzeApiReturn {
|
|||||||
}
|
}
|
||||||
// Check Integer
|
// Check Integer
|
||||||
{
|
{
|
||||||
final ApiModel model = api.getAllApi().get(0).getInterfaceNamed("getInteger2");
|
final ApiModel model = api.apiModels.get(0).getInterfaceNamed("getInteger2");
|
||||||
Assertions.assertNotNull(model);
|
Assertions.assertNotNull(model);
|
||||||
Assertions.assertEquals(1, model.returnTypes.size());
|
Assertions.assertEquals(1, model.returnTypes.size());
|
||||||
final ClassObjectModel classModel = Assertions.assertInstanceOf(ClassObjectModel.class,
|
final ClassObjectModel classModel = Assertions.assertInstanceOf(ClassObjectModel.class,
|
||||||
@@ -123,11 +123,11 @@ public class TestAnalyzeApiReturn {
|
|||||||
final AnalyzeApi api = new AnalyzeApi();
|
final AnalyzeApi api = new AnalyzeApi();
|
||||||
api.addAllApi(List.of(ReturnValueShort.class));
|
api.addAllApi(List.of(ReturnValueShort.class));
|
||||||
|
|
||||||
Assertions.assertEquals(1, api.getAllApi().size());
|
Assertions.assertEquals(1, api.apiModels.size());
|
||||||
Assertions.assertEquals(2, api.getAllApi().get(0).interfaces.size());
|
Assertions.assertEquals(2, api.apiModels.get(0).interfaces.size());
|
||||||
// Check short
|
// Check short
|
||||||
{
|
{
|
||||||
final ApiModel model = api.getAllApi().get(0).getInterfaceNamed("getShort1");
|
final ApiModel model = api.apiModels.get(0).getInterfaceNamed("getShort1");
|
||||||
Assertions.assertNotNull(model);
|
Assertions.assertNotNull(model);
|
||||||
Assertions.assertEquals(1, model.returnTypes.size());
|
Assertions.assertEquals(1, model.returnTypes.size());
|
||||||
final ClassObjectModel classModel = Assertions.assertInstanceOf(ClassObjectModel.class,
|
final ClassObjectModel classModel = Assertions.assertInstanceOf(ClassObjectModel.class,
|
||||||
@@ -136,7 +136,7 @@ public class TestAnalyzeApiReturn {
|
|||||||
}
|
}
|
||||||
// Check Short
|
// Check Short
|
||||||
{
|
{
|
||||||
final ApiModel model = api.getAllApi().get(0).getInterfaceNamed("getShort2");
|
final ApiModel model = api.apiModels.get(0).getInterfaceNamed("getShort2");
|
||||||
Assertions.assertNotNull(model);
|
Assertions.assertNotNull(model);
|
||||||
Assertions.assertEquals(1, model.returnTypes.size());
|
Assertions.assertEquals(1, model.returnTypes.size());
|
||||||
final ClassObjectModel classModel = Assertions.assertInstanceOf(ClassObjectModel.class,
|
final ClassObjectModel classModel = Assertions.assertInstanceOf(ClassObjectModel.class,
|
||||||
@@ -164,11 +164,11 @@ public class TestAnalyzeApiReturn {
|
|||||||
final AnalyzeApi api = new AnalyzeApi();
|
final AnalyzeApi api = new AnalyzeApi();
|
||||||
api.addAllApi(List.of(ReturnValueLong.class));
|
api.addAllApi(List.of(ReturnValueLong.class));
|
||||||
|
|
||||||
Assertions.assertEquals(1, api.getAllApi().size());
|
Assertions.assertEquals(1, api.apiModels.size());
|
||||||
Assertions.assertEquals(2, api.getAllApi().get(0).interfaces.size());
|
Assertions.assertEquals(2, api.apiModels.get(0).interfaces.size());
|
||||||
// Check long
|
// Check long
|
||||||
{
|
{
|
||||||
final ApiModel model = api.getAllApi().get(0).getInterfaceNamed("getLong1");
|
final ApiModel model = api.apiModels.get(0).getInterfaceNamed("getLong1");
|
||||||
Assertions.assertNotNull(model);
|
Assertions.assertNotNull(model);
|
||||||
Assertions.assertEquals(1, model.returnTypes.size());
|
Assertions.assertEquals(1, model.returnTypes.size());
|
||||||
final ClassObjectModel classModel = Assertions.assertInstanceOf(ClassObjectModel.class,
|
final ClassObjectModel classModel = Assertions.assertInstanceOf(ClassObjectModel.class,
|
||||||
@@ -177,7 +177,7 @@ public class TestAnalyzeApiReturn {
|
|||||||
}
|
}
|
||||||
// Check Long
|
// Check Long
|
||||||
{
|
{
|
||||||
final ApiModel model = api.getAllApi().get(0).getInterfaceNamed("getLong2");
|
final ApiModel model = api.apiModels.get(0).getInterfaceNamed("getLong2");
|
||||||
Assertions.assertNotNull(model);
|
Assertions.assertNotNull(model);
|
||||||
Assertions.assertEquals(1, model.returnTypes.size());
|
Assertions.assertEquals(1, model.returnTypes.size());
|
||||||
Assertions.assertInstanceOf(ClassObjectModel.class, model.returnTypes.get(0));
|
Assertions.assertInstanceOf(ClassObjectModel.class, model.returnTypes.get(0));
|
||||||
@@ -206,11 +206,11 @@ public class TestAnalyzeApiReturn {
|
|||||||
final AnalyzeApi api = new AnalyzeApi();
|
final AnalyzeApi api = new AnalyzeApi();
|
||||||
api.addAllApi(List.of(ReturnValueFloat.class));
|
api.addAllApi(List.of(ReturnValueFloat.class));
|
||||||
|
|
||||||
Assertions.assertEquals(1, api.getAllApi().size());
|
Assertions.assertEquals(1, api.apiModels.size());
|
||||||
Assertions.assertEquals(2, api.getAllApi().get(0).interfaces.size());
|
Assertions.assertEquals(2, api.apiModels.get(0).interfaces.size());
|
||||||
// Check float
|
// Check float
|
||||||
{
|
{
|
||||||
final ApiModel model = api.getAllApi().get(0).getInterfaceNamed("getFloat1");
|
final ApiModel model = api.apiModels.get(0).getInterfaceNamed("getFloat1");
|
||||||
Assertions.assertNotNull(model);
|
Assertions.assertNotNull(model);
|
||||||
Assertions.assertEquals(1, model.returnTypes.size());
|
Assertions.assertEquals(1, model.returnTypes.size());
|
||||||
final ClassObjectModel classModel = Assertions.assertInstanceOf(ClassObjectModel.class,
|
final ClassObjectModel classModel = Assertions.assertInstanceOf(ClassObjectModel.class,
|
||||||
@@ -219,7 +219,7 @@ public class TestAnalyzeApiReturn {
|
|||||||
}
|
}
|
||||||
// Check Float
|
// Check Float
|
||||||
{
|
{
|
||||||
final ApiModel model = api.getAllApi().get(0).getInterfaceNamed("getFloat2");
|
final ApiModel model = api.apiModels.get(0).getInterfaceNamed("getFloat2");
|
||||||
Assertions.assertNotNull(model);
|
Assertions.assertNotNull(model);
|
||||||
Assertions.assertEquals(1, model.returnTypes.size());
|
Assertions.assertEquals(1, model.returnTypes.size());
|
||||||
final ClassObjectModel classModel = Assertions.assertInstanceOf(ClassObjectModel.class,
|
final ClassObjectModel classModel = Assertions.assertInstanceOf(ClassObjectModel.class,
|
||||||
@@ -247,11 +247,11 @@ public class TestAnalyzeApiReturn {
|
|||||||
final AnalyzeApi api = new AnalyzeApi();
|
final AnalyzeApi api = new AnalyzeApi();
|
||||||
api.addAllApi(List.of(ReturnValueDouble.class));
|
api.addAllApi(List.of(ReturnValueDouble.class));
|
||||||
|
|
||||||
Assertions.assertEquals(1, api.getAllApi().size());
|
Assertions.assertEquals(1, api.apiModels.size());
|
||||||
Assertions.assertEquals(2, api.getAllApi().get(0).interfaces.size());
|
Assertions.assertEquals(2, api.apiModels.get(0).interfaces.size());
|
||||||
// Check double
|
// Check double
|
||||||
{
|
{
|
||||||
final ApiModel model = api.getAllApi().get(0).getInterfaceNamed("getDouble1");
|
final ApiModel model = api.apiModels.get(0).getInterfaceNamed("getDouble1");
|
||||||
Assertions.assertNotNull(model);
|
Assertions.assertNotNull(model);
|
||||||
Assertions.assertEquals(1, model.returnTypes.size());
|
Assertions.assertEquals(1, model.returnTypes.size());
|
||||||
final ClassObjectModel classModel = Assertions.assertInstanceOf(ClassObjectModel.class,
|
final ClassObjectModel classModel = Assertions.assertInstanceOf(ClassObjectModel.class,
|
||||||
@@ -260,7 +260,7 @@ public class TestAnalyzeApiReturn {
|
|||||||
}
|
}
|
||||||
// Check Double
|
// Check Double
|
||||||
{
|
{
|
||||||
final ApiModel model = api.getAllApi().get(0).getInterfaceNamed("getDouble2");
|
final ApiModel model = api.apiModels.get(0).getInterfaceNamed("getDouble2");
|
||||||
Assertions.assertNotNull(model);
|
Assertions.assertNotNull(model);
|
||||||
Assertions.assertEquals(1, model.returnTypes.size());
|
Assertions.assertEquals(1, model.returnTypes.size());
|
||||||
final ClassObjectModel classModel = Assertions.assertInstanceOf(ClassObjectModel.class,
|
final ClassObjectModel classModel = Assertions.assertInstanceOf(ClassObjectModel.class,
|
||||||
@@ -283,11 +283,11 @@ public class TestAnalyzeApiReturn {
|
|||||||
final AnalyzeApi api = new AnalyzeApi();
|
final AnalyzeApi api = new AnalyzeApi();
|
||||||
api.addAllApi(List.of(ReturnValueString.class));
|
api.addAllApi(List.of(ReturnValueString.class));
|
||||||
|
|
||||||
Assertions.assertEquals(1, api.getAllApi().size());
|
Assertions.assertEquals(1, api.apiModels.size());
|
||||||
Assertions.assertEquals(1, api.getAllApi().get(0).interfaces.size());
|
Assertions.assertEquals(1, api.apiModels.get(0).interfaces.size());
|
||||||
// Check String
|
// Check String
|
||||||
{
|
{
|
||||||
final ApiModel model = api.getAllApi().get(0).getInterfaceNamed("getString");
|
final ApiModel model = api.apiModels.get(0).getInterfaceNamed("getString");
|
||||||
Assertions.assertNotNull(model);
|
Assertions.assertNotNull(model);
|
||||||
Assertions.assertEquals(1, model.returnTypes.size());
|
Assertions.assertEquals(1, model.returnTypes.size());
|
||||||
final ClassObjectModel classModel = Assertions.assertInstanceOf(ClassObjectModel.class,
|
final ClassObjectModel classModel = Assertions.assertInstanceOf(ClassObjectModel.class,
|
||||||
@@ -314,11 +314,11 @@ public class TestAnalyzeApiReturn {
|
|||||||
final AnalyzeApi api = new AnalyzeApi();
|
final AnalyzeApi api = new AnalyzeApi();
|
||||||
api.addAllApi(List.of(ReturnValueAny.class));
|
api.addAllApi(List.of(ReturnValueAny.class));
|
||||||
|
|
||||||
Assertions.assertEquals(1, api.getAllApi().size());
|
Assertions.assertEquals(1, api.apiModels.size());
|
||||||
Assertions.assertEquals(2, api.getAllApi().get(0).interfaces.size());
|
Assertions.assertEquals(2, api.apiModels.get(0).interfaces.size());
|
||||||
// Check Response ==> represent a Any value then it wrapped as Object
|
// Check Response ==> represent a Any value then it wrapped as Object
|
||||||
{
|
{
|
||||||
final ApiModel model = api.getAllApi().get(0).getInterfaceNamed("getResponse");
|
final ApiModel model = api.apiModels.get(0).getInterfaceNamed("getResponse");
|
||||||
Assertions.assertNotNull(model);
|
Assertions.assertNotNull(model);
|
||||||
Assertions.assertEquals(1, model.returnTypes.size());
|
Assertions.assertEquals(1, model.returnTypes.size());
|
||||||
final ClassObjectModel classModel = Assertions.assertInstanceOf(ClassObjectModel.class,
|
final ClassObjectModel classModel = Assertions.assertInstanceOf(ClassObjectModel.class,
|
||||||
@@ -327,7 +327,7 @@ public class TestAnalyzeApiReturn {
|
|||||||
}
|
}
|
||||||
// Check Object
|
// Check Object
|
||||||
{
|
{
|
||||||
final ApiModel model = api.getAllApi().get(0).getInterfaceNamed("getObject");
|
final ApiModel model = api.apiModels.get(0).getInterfaceNamed("getObject");
|
||||||
Assertions.assertNotNull(model);
|
Assertions.assertNotNull(model);
|
||||||
Assertions.assertEquals(1, model.returnTypes.size());
|
Assertions.assertEquals(1, model.returnTypes.size());
|
||||||
final ClassObjectModel classModel = Assertions.assertInstanceOf(ClassObjectModel.class,
|
final ClassObjectModel classModel = Assertions.assertInstanceOf(ClassObjectModel.class,
|
||||||
@@ -350,11 +350,11 @@ public class TestAnalyzeApiReturn {
|
|||||||
final AnalyzeApi api = new AnalyzeApi();
|
final AnalyzeApi api = new AnalyzeApi();
|
||||||
api.addAllApi(List.of(ReturnValueEnum.class));
|
api.addAllApi(List.of(ReturnValueEnum.class));
|
||||||
|
|
||||||
Assertions.assertEquals(1, api.getAllApi().size());
|
Assertions.assertEquals(1, api.apiModels.size());
|
||||||
Assertions.assertEquals(1, api.getAllApi().get(0).interfaces.size());
|
Assertions.assertEquals(1, api.apiModels.get(0).interfaces.size());
|
||||||
// Check Enum
|
// Check Enum
|
||||||
{
|
{
|
||||||
final ApiModel model = api.getAllApi().get(0).getInterfaceNamed("getEnum");
|
final ApiModel model = api.apiModels.get(0).getInterfaceNamed("getEnum");
|
||||||
Assertions.assertNotNull(model);
|
Assertions.assertNotNull(model);
|
||||||
Assertions.assertEquals(1, model.returnTypes.size());
|
Assertions.assertEquals(1, model.returnTypes.size());
|
||||||
final ClassEnumModel classModel = Assertions.assertInstanceOf(ClassEnumModel.class,
|
final ClassEnumModel classModel = Assertions.assertInstanceOf(ClassEnumModel.class,
|
||||||
@@ -396,11 +396,11 @@ public class TestAnalyzeApiReturn {
|
|||||||
final AnalyzeApi api = new AnalyzeApi();
|
final AnalyzeApi api = new AnalyzeApi();
|
||||||
api.addAllApi(List.of(ReturnValueList.class));
|
api.addAllApi(List.of(ReturnValueList.class));
|
||||||
|
|
||||||
Assertions.assertEquals(1, api.getAllApi().size());
|
Assertions.assertEquals(1, api.apiModels.size());
|
||||||
Assertions.assertEquals(5, api.getAllApi().get(0).interfaces.size());
|
Assertions.assertEquals(5, api.apiModels.get(0).interfaces.size());
|
||||||
// Check List<Integer>
|
// Check List<Integer>
|
||||||
{
|
{
|
||||||
final ApiModel model = api.getAllApi().get(0).getInterfaceNamed("getListInteger");
|
final ApiModel model = api.apiModels.get(0).getInterfaceNamed("getListInteger");
|
||||||
Assertions.assertNotNull(model);
|
Assertions.assertNotNull(model);
|
||||||
Assertions.assertEquals(1, model.returnTypes.size());
|
Assertions.assertEquals(1, model.returnTypes.size());
|
||||||
// Level 0
|
// Level 0
|
||||||
@@ -413,7 +413,7 @@ public class TestAnalyzeApiReturn {
|
|||||||
}
|
}
|
||||||
// Check List<TestEnum>
|
// Check List<TestEnum>
|
||||||
{
|
{
|
||||||
final ApiModel model = api.getAllApi().get(0).getInterfaceNamed("getListEnum");
|
final ApiModel model = api.apiModels.get(0).getInterfaceNamed("getListEnum");
|
||||||
Assertions.assertNotNull(model);
|
Assertions.assertNotNull(model);
|
||||||
Assertions.assertEquals(1, model.returnTypes.size());
|
Assertions.assertEquals(1, model.returnTypes.size());
|
||||||
// Level 0
|
// Level 0
|
||||||
@@ -426,7 +426,7 @@ public class TestAnalyzeApiReturn {
|
|||||||
}
|
}
|
||||||
// Check List<TestObject>
|
// Check List<TestObject>
|
||||||
{
|
{
|
||||||
final ApiModel model = api.getAllApi().get(0).getInterfaceNamed("getListObject");
|
final ApiModel model = api.apiModels.get(0).getInterfaceNamed("getListObject");
|
||||||
Assertions.assertNotNull(model);
|
Assertions.assertNotNull(model);
|
||||||
Assertions.assertEquals(1, model.returnTypes.size());
|
Assertions.assertEquals(1, model.returnTypes.size());
|
||||||
// Level 0
|
// Level 0
|
||||||
@@ -435,11 +435,11 @@ public class TestAnalyzeApiReturn {
|
|||||||
// Level 1
|
// Level 1
|
||||||
final ClassObjectModel classModelOfValue = Assertions.assertInstanceOf(ClassObjectModel.class,
|
final ClassObjectModel classModelOfValue = Assertions.assertInstanceOf(ClassObjectModel.class,
|
||||||
classListModel.valueModel);
|
classListModel.valueModel);
|
||||||
Assertions.assertEquals(TestObject.class, classModelOfValue.getOriginClasses());
|
Assertions.assertEquals(Integer.class, classModelOfValue.getOriginClasses());
|
||||||
}
|
}
|
||||||
// Check List<List<Integer>>
|
// Check List<List<Integer>>
|
||||||
{
|
{
|
||||||
final ApiModel model = api.getAllApi().get(0).getInterfaceNamed("getListListInteger");
|
final ApiModel model = api.apiModels.get(0).getInterfaceNamed("getListListInteger");
|
||||||
Assertions.assertNotNull(model);
|
Assertions.assertNotNull(model);
|
||||||
Assertions.assertEquals(1, model.returnTypes.size());
|
Assertions.assertEquals(1, model.returnTypes.size());
|
||||||
// Level 0
|
// Level 0
|
||||||
@@ -455,7 +455,7 @@ public class TestAnalyzeApiReturn {
|
|||||||
}
|
}
|
||||||
// Check List<Map<String, Integer>>
|
// Check List<Map<String, Integer>>
|
||||||
{
|
{
|
||||||
final ApiModel model = api.getAllApi().get(0).getInterfaceNamed("getListMapInteger");
|
final ApiModel model = api.apiModels.get(0).getInterfaceNamed("getListMapInteger");
|
||||||
Assertions.assertNotNull(model);
|
Assertions.assertNotNull(model);
|
||||||
Assertions.assertEquals(1, model.returnTypes.size());
|
Assertions.assertEquals(1, model.returnTypes.size());
|
||||||
// Level 0
|
// Level 0
|
||||||
@@ -509,11 +509,11 @@ public class TestAnalyzeApiReturn {
|
|||||||
final AnalyzeApi api = new AnalyzeApi();
|
final AnalyzeApi api = new AnalyzeApi();
|
||||||
api.addAllApi(List.of(ReturnValueMap.class));
|
api.addAllApi(List.of(ReturnValueMap.class));
|
||||||
|
|
||||||
Assertions.assertEquals(1, api.getAllApi().size());
|
Assertions.assertEquals(1, api.apiModels.size());
|
||||||
Assertions.assertEquals(5, api.getAllApi().get(0).interfaces.size());
|
Assertions.assertEquals(5, api.apiModels.get(0).interfaces.size());
|
||||||
// Check Map<String, Integer>
|
// Check Map<String, Integer>
|
||||||
{
|
{
|
||||||
final ApiModel model = api.getAllApi().get(0).getInterfaceNamed("getMapInteger");
|
final ApiModel model = api.apiModels.get(0).getInterfaceNamed("getMapInteger");
|
||||||
Assertions.assertNotNull(model);
|
Assertions.assertNotNull(model);
|
||||||
Assertions.assertEquals(1, model.returnTypes.size());
|
Assertions.assertEquals(1, model.returnTypes.size());
|
||||||
// Level 0
|
// Level 0
|
||||||
@@ -529,7 +529,7 @@ public class TestAnalyzeApiReturn {
|
|||||||
}
|
}
|
||||||
// Check Map<String, TestEnum>
|
// Check Map<String, TestEnum>
|
||||||
{
|
{
|
||||||
final ApiModel model = api.getAllApi().get(0).getInterfaceNamed("getMapEnum");
|
final ApiModel model = api.apiModels.get(0).getInterfaceNamed("getMapEnum");
|
||||||
Assertions.assertNotNull(model);
|
Assertions.assertNotNull(model);
|
||||||
Assertions.assertEquals(1, model.returnTypes.size());
|
Assertions.assertEquals(1, model.returnTypes.size());
|
||||||
// Level 0
|
// Level 0
|
||||||
@@ -545,7 +545,7 @@ public class TestAnalyzeApiReturn {
|
|||||||
}
|
}
|
||||||
// Check Map<String, TestObject>
|
// Check Map<String, TestObject>
|
||||||
{
|
{
|
||||||
final ApiModel model = api.getAllApi().get(0).getInterfaceNamed("getMapObject");
|
final ApiModel model = api.apiModels.get(0).getInterfaceNamed("getMapObject");
|
||||||
Assertions.assertNotNull(model);
|
Assertions.assertNotNull(model);
|
||||||
Assertions.assertEquals(1, model.returnTypes.size());
|
Assertions.assertEquals(1, model.returnTypes.size());
|
||||||
// Level 0
|
// Level 0
|
||||||
@@ -561,7 +561,7 @@ public class TestAnalyzeApiReturn {
|
|||||||
}
|
}
|
||||||
// Check Map<String, Map<String, Integer>>
|
// Check Map<String, Map<String, Integer>>
|
||||||
{
|
{
|
||||||
final ApiModel model = api.getAllApi().get(0).getInterfaceNamed("getMapMap");
|
final ApiModel model = api.apiModels.get(0).getInterfaceNamed("getMapMap");
|
||||||
Assertions.assertNotNull(model);
|
Assertions.assertNotNull(model);
|
||||||
Assertions.assertEquals(1, model.returnTypes.size());
|
Assertions.assertEquals(1, model.returnTypes.size());
|
||||||
// Level 0
|
// Level 0
|
||||||
@@ -583,7 +583,7 @@ public class TestAnalyzeApiReturn {
|
|||||||
}
|
}
|
||||||
// Check Map<String, List<Integer>>
|
// Check Map<String, List<Integer>>
|
||||||
{
|
{
|
||||||
final ApiModel model = api.getAllApi().get(0).getInterfaceNamed("getMapList");
|
final ApiModel model = api.apiModels.get(0).getInterfaceNamed("getMapList");
|
||||||
Assertions.assertNotNull(model);
|
Assertions.assertNotNull(model);
|
||||||
Assertions.assertEquals(1, model.returnTypes.size());
|
Assertions.assertEquals(1, model.returnTypes.size());
|
||||||
// Level 0
|
// Level 0
|
||||||
|
@@ -0,0 +1,17 @@
|
|||||||
|
package test.kar.archidata.externalRestApi;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Assertions;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
public class TestAnalyzeApiReturnAsync {
|
||||||
|
final static private Logger LOGGER = LoggerFactory.getLogger(TestAnalyzeApiReturnAsync.class);
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testNotImplemented() throws Exception {
|
||||||
|
Assertions.assertEquals(1, 0);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -1,8 +1,12 @@
|
|||||||
package test.kar.archidata.externalRestApi;
|
package test.kar.archidata.externalRestApi;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Assertions;
|
import org.junit.jupiter.api.Assertions;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.kar.archidata.externalRestApi.AnalyzeApi;
|
import org.kar.archidata.externalRestApi.AnalyzeModel;
|
||||||
|
import org.kar.archidata.externalRestApi.model.ClassModel;
|
||||||
import org.kar.archidata.externalRestApi.model.ClassObjectModel;
|
import org.kar.archidata.externalRestApi.model.ClassObjectModel;
|
||||||
import org.kar.archidata.externalRestApi.model.ClassObjectModel.FieldProperty;
|
import org.kar.archidata.externalRestApi.model.ClassObjectModel.FieldProperty;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
@@ -17,11 +21,10 @@ public class TestAnalyzeModel {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNames() throws Exception {
|
public void testNames() throws Exception {
|
||||||
final AnalyzeApi apiInterface = new AnalyzeApi();
|
final ClassObjectModel model = new ClassObjectModel(TestObject.class);
|
||||||
apiInterface.addModel(TestObject.class);
|
final List<ClassModel> models = new ArrayList<>();
|
||||||
Assertions.assertEquals(2, apiInterface.getAllModel().size());
|
models.add(model);
|
||||||
final ClassObjectModel model = Assertions.assertInstanceOf(ClassObjectModel.class,
|
AnalyzeModel.fillModel(models);
|
||||||
apiInterface.getAllModel().get(0));
|
|
||||||
|
|
||||||
Assertions.assertEquals("TestObject", model.getName());
|
Assertions.assertEquals("TestObject", model.getName());
|
||||||
Assertions.assertEquals(false, model.isPrimitive());
|
Assertions.assertEquals(false, model.isPrimitive());
|
||||||
|
@@ -1 +1 @@
|
|||||||
0.9.0
|
0.8.9
|
||||||
|
Reference in New Issue
Block a user