[STYLE] format code
This commit is contained in:
parent
0597ba0df3
commit
c33a73a567
@ -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();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -20,13 +20,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 +35,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 +50,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,27 +59,27 @@ 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 ");
|
||||||
@ -141,7 +141,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 +167,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 +188,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 +214,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 +242,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 +262,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 +307,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 +324,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 +374,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 +401,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 +475,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();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -23,7 +23,7 @@ import org.kar.archidata.externalRestApi.model.ApiGroupModel;
|
|||||||
import org.kar.archidata.externalRestApi.model.ClassModel;
|
import org.kar.archidata.externalRestApi.model.ClassModel;
|
||||||
|
|
||||||
public class TsGenerateApi {
|
public class TsGenerateApi {
|
||||||
|
|
||||||
public static void generateApi(final AnalyzeApi api, final String pathPackage) throws Exception {
|
public static void generateApi(final AnalyzeApi api, final String pathPackage) throws Exception {
|
||||||
final List<TsClassElement> localModel = generateApiModel(api);
|
final List<TsClassElement> localModel = generateApiModel(api);
|
||||||
final TsClassElementGroup tsGroup = new TsClassElementGroup(localModel);
|
final TsClassElementGroup tsGroup = new TsClassElementGroup(localModel);
|
||||||
@ -51,13 +51,13 @@ public class TsGenerateApi {
|
|||||||
export * from \"./model\";
|
export * from \"./model\";
|
||||||
export * from \"./api\";
|
export * from \"./api\";
|
||||||
export * from \"./rest-tools\";
|
export * from \"./rest-tools\";
|
||||||
|
|
||||||
""";
|
""";
|
||||||
final FileWriter myWriter = new FileWriter(pathPackage + File.separator + "index.ts");
|
final FileWriter myWriter = new FileWriter(pathPackage + File.separator + "index.ts");
|
||||||
myWriter.write(out);
|
myWriter.write(out);
|
||||||
myWriter.close();
|
myWriter.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void createResourceIndex(final String pathPackage, final List<ApiGroupModel> apiModels)
|
private static void createResourceIndex(final String pathPackage, final List<ApiGroupModel> apiModels)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
final StringBuilder out = new StringBuilder("""
|
final StringBuilder out = new StringBuilder("""
|
||||||
@ -211,7 +211,7 @@ public class TsGenerateApi {
|
|||||||
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 = TsGenerateApi.class.getClassLoader().getResourceAsStream(name);
|
||||||
if (ioStream == null) {
|
if (ioStream == null) {
|
||||||
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,11 +7,11 @@ 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,9 +20,9 @@ public class ClassEnumModel extends ClassModel {
|
|||||||
out.append("]");
|
out.append("]");
|
||||||
return out.toString();
|
return out.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
final Map<String, Object> listOfValues = new HashMap<>();
|
final Map<String, Object> listOfValues = new HashMap<>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void analyze(final ModelGroup group) throws IOException {
|
public void analyze(final ModelGroup group) throws IOException {
|
||||||
if (this.analyzeDone) {
|
if (this.analyzeDone) {
|
||||||
@ -49,16 +49,16 @@ public class ClassEnumModel extends ClassModel {
|
|||||||
this.listOfValues.put(elem.toString(), elem.toString());
|
this.listOfValues.put(elem.toString(), elem.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<String, Object> getListOfValues() {
|
public Map<String, Object> 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 + '\''
|
||||||
|
Loading…
x
Reference in New Issue
Block a user