From 3fe64f0ec44c935b01a44d1a44a567d3c93c1fab Mon Sep 17 00:00:00 2001 From: pkupczyk <piotr.kupczyk@id.ethz.ch> Date: Mon, 8 Jan 2024 10:51:09 +0100 Subject: [PATCH] BIS-757 : Write Translator to TypeScript - make names of classes with duplicated simple names consistent with the other full names --- api-openbis-java/build.gradle | 16 ++++----- .../empa/tsprocessor/AddMethodsExtension.java | 34 ++++++++++++------- .../AddOpenBISModuleExtension.java | 9 +++-- 3 files changed, 36 insertions(+), 23 deletions(-) diff --git a/api-openbis-java/build.gradle b/api-openbis-java/build.gradle index 18e5cd6c801..3c054ac0216 100644 --- a/api-openbis-java/build.gradle +++ b/api-openbis-java/build.gradle @@ -76,14 +76,14 @@ generateTypeScript { namespace = 'openbis' customTypeNaming = [ "ch.ethz.sis.openbis.generic.OpenBIS:facade", - "ch.ethz.sis.openbis.generic.asapi.v3.dto.pat.search.PersonalAccessTokenSessionNameSearchCriteria:PersonalAccessTokenSessionNameSearchCriteria", - "ch.ethz.sis.openbis.generic.asapi.v3.dto.session.search.PersonalAccessTokenSessionNameSearchCriteria:PersonalAccessTokenSessionNameSearchCriteriaInSession", - "ch.ethz.sis.openbis.generic.asapi.v3.dto.externaldms.search.ExternalDmsSearchCriteria:ExternalDmsSearchCriteria", - "ch.ethz.sis.openbis.generic.asapi.v3.dto.dataset.search.ExternalDmsSearchCriteria:ExternalDmsSearchCriteriaInDataSet", - "ch.ethz.sis.openbis.generic.asapi.v3.dto.service.execute.AbstractExecutionOptionsWithParameters:AbstractExecutionOptionsWithParameters", - "ch.ethz.sis.openbis.generic.dssapi.v3.dto.service.execute.AbstractExecutionOptionsWithParameters:AbstractExecutionOptionsWithParametersInDataStore", - "ch.ethz.sis.openbis.generic.asapi.v3.dto.common.operation.IOperationResult:IOperationResult", - "ch.ethz.sis.openbis.generic.dssapi.v3.dto.common.operation.IOperationResult:IOperationResultInDataStore" + "ch.ethz.sis.openbis.generic.asapi.v3.dto.pat.search.PersonalAccessTokenSessionNameSearchCriteria:as_dto_pat_search_PersonalAccessTokenSessionNameSearchCriteria", + "ch.ethz.sis.openbis.generic.asapi.v3.dto.session.search.PersonalAccessTokenSessionNameSearchCriteria:as_dto_session_search_PersonalAccessTokenSessionNameSearchCriteria", + "ch.ethz.sis.openbis.generic.asapi.v3.dto.externaldms.search.ExternalDmsSearchCriteria:as_dto_externaldms_search_ExternalDmsSearchCriteria", + "ch.ethz.sis.openbis.generic.asapi.v3.dto.dataset.search.ExternalDmsSearchCriteria:as_dto_dataset_search_ExternalDmsSearchCriteria", + "ch.ethz.sis.openbis.generic.asapi.v3.dto.service.execute.AbstractExecutionOptionsWithParameters:as_dto_service_execute_AbstractExecutionOptionsWithParameters", + "ch.ethz.sis.openbis.generic.dssapi.v3.dto.service.execute.AbstractExecutionOptionsWithParameters:dss_dto_service_execute_AbstractExecutionOptionsWithParameters", + "ch.ethz.sis.openbis.generic.asapi.v3.dto.common.operation.IOperationResult:as_dto_common_operation_IOperationResult", + "ch.ethz.sis.openbis.generic.dssapi.v3.dto.common.operation.IOperationResult:dss_dto_common_operation_IOperationResult" ] extensionsWithConfiguration = [ new ConfiguredExtension(className: 'ch.empa.tsprocessor.AddMethodsExtension', configuration: ['asyncClasses': "[\"ch.ethz.sis.openbis.generic.OpenBIS\"]"]), diff --git a/lib-typescriptprocessor/source/java/ch/empa/tsprocessor/AddMethodsExtension.java b/lib-typescriptprocessor/source/java/ch/empa/tsprocessor/AddMethodsExtension.java index 5d54320e04a..8f4b248036d 100644 --- a/lib-typescriptprocessor/source/java/ch/empa/tsprocessor/AddMethodsExtension.java +++ b/lib-typescriptprocessor/source/java/ch/empa/tsprocessor/AddMethodsExtension.java @@ -406,8 +406,13 @@ public class AddMethodsExtension extends Extension if (jsonObjectAnnotation != null) { - writer.writeIndentedLine( - "export const " + jsonObjectAnnotation.value().replaceAll("\\.", "_") + ":" + bean.getName().getSimpleName()); + String jsonName = jsonObjectAnnotation.value().replaceAll("\\.", "_"); + + if(!jsonName.equals(originalBeanName)) + { + writer.writeIndentedLine( + "export const " + jsonName + ":" + bean.getName().getSimpleName()); + } } constructors.add(bean.getName().getSimpleName()); @@ -422,18 +427,21 @@ public class AddMethodsExtension extends Extension if (jsonObjectAnnotation != null) { - if (bean.getTypeParameters() == null || bean.getTypeParameters().isEmpty()) - { - writer.writeIndentedLine( - "type " + jsonObjectAnnotation.value().replaceAll("\\.", "_") + " = " + bean.getName().getSimpleName()); - } else + String jsonName = jsonObjectAnnotation.value().replaceAll("\\.", "_"); + + if(!jsonName.equals(bean.getName().getSimpleName())) { - List<String> typeNames = bean.getTypeParameters().stream().map(p -> p.name.split(" ")[0]).collect(Collectors.toList()); - List<String> typeParameters = bean.getTypeParameters().stream().map(TsType::toString).collect(Collectors.toList()); - writer.writeIndentedLine( - "type " + jsonObjectAnnotation.value().replaceAll("\\.", "_") + "<" + String.join(", ", typeParameters) + "> = " - + bean.getName() - .getSimpleName() + "<" + String.join(", ", typeNames) + ">"); + if (bean.getTypeParameters() == null || bean.getTypeParameters().isEmpty()) + { + writer.writeIndentedLine( + "type " + jsonName + " = " + bean.getName().getSimpleName()); + } else + { + List<String> typeNames = bean.getTypeParameters().stream().map(p -> p.name.split(" ")[0]).collect(Collectors.toList()); + List<String> typeParameters = bean.getTypeParameters().stream().map(TsType::toString).collect(Collectors.toList()); + writer.writeIndentedLine("type " + jsonName + "<" + String.join(", ", typeParameters) + "> = " + + bean.getName().getSimpleName() + "<" + String.join(", ", typeNames) + ">"); + } } } } diff --git a/lib-typescriptprocessor/source/java/ch/empa/tsprocessor/AddOpenBISModuleExtension.java b/lib-typescriptprocessor/source/java/ch/empa/tsprocessor/AddOpenBISModuleExtension.java index 9f324f7bb50..5b37d90c2ec 100644 --- a/lib-typescriptprocessor/source/java/ch/empa/tsprocessor/AddOpenBISModuleExtension.java +++ b/lib-typescriptprocessor/source/java/ch/empa/tsprocessor/AddOpenBISModuleExtension.java @@ -61,8 +61,13 @@ public class AddOpenBISModuleExtension extends Extension if (jsonObjectAnnotation != null) { - properties.add(new TsPropertyModel(jsonObjectAnnotation.value().replaceAll("\\.", "_"), - new TsType.ReferenceType(new Symbol(bean.getName().getSimpleName() + "Constructor")), null, true, null)); + String jsonName = jsonObjectAnnotation.value().replaceAll("\\.", "_"); + + if(!jsonName.equals(bean.getName().getSimpleName())) + { + properties.add(new TsPropertyModel(jsonName, + new TsType.ReferenceType(new Symbol(bean.getName().getSimpleName() + "Constructor")), null, true, null)); + } } } } -- GitLab