Skip to content
Snippets Groups Projects
Commit ddb5e298 authored by piotr.kupczyk@id.ethz.ch's avatar piotr.kupczyk@id.ethz.ch
Browse files

SSDM-14283 : V3 API TS: automated tests for auto-generated TypeScript...

SSDM-14283 : V3 API TS: automated tests for auto-generated TypeScript definition file (d.ts) - fix a bug where abstract classes and interfaces are not exported under full name
parent 853f6fa8
No related branches found
No related tags found
1 merge request!40SSDM-13578 : 2PT : Database and V3 Implementation - include the new AFS "free"...
......@@ -260,6 +260,16 @@ public class OpenBISExtension extends Extension
List<TsType.GenericVariableType> tsBeanTypeParametersWithoutBounds =
resolveTypeParameters(processingContext, tsBean, tsBean.getOrigin().getTypeParameters(), false);
String tsBeanAdditionalName = null;
if (tsBeanJsonObject != null)
{
tsBeanAdditionalName = tsBeanJsonObject.value().replaceAll("\\.", "_");
} else
{
tsBeanAdditionalName = tsBeanTypeScriptObject.value();
}
List<TsMethodModel> tsBeanMethods = new ArrayList<>();
for (Method method : tsBean.getOrigin().getMethods())
......@@ -350,6 +360,26 @@ public class OpenBISExtension extends Extension
}
}
/*
Generate part (if there are constructors):
interface XConstructor {
new <T>(p:string): X<T>
}
bundle {
...
X:XConstructor,
a_b_c_X:XConstructor
...
}
export const X:XConstructor
export const a_b_c_X:XConstructor
*/
if (!tsConstructors.isEmpty())
{
String tsConstructorBeanName = tsBean.getName().getSimpleName() + "Constructor";
......@@ -368,39 +398,37 @@ public class OpenBISExtension extends Extension
new TsHelper(
Collections.singletonList("export const " + tsBean.getName().getSimpleName() + ":" + tsConstructorBeanName)));
String tsBeanName = null;
if (tsBeanJsonObject != null)
{
tsBeanName = tsBeanJsonObject.value().replaceAll("\\.", "_");
} else
if (!Strings.isNullOrEmpty(tsBeanAdditionalName) && !tsBeanAdditionalName.equals(tsBean.getName().getSimpleName()))
{
tsBeanName = tsBeanTypeScriptObject.value();
tsBundleProperties.add(new TsPropertyModel(tsBeanAdditionalName,
new TsType.ReferenceType(new Symbol(tsConstructorBeanName)), null, true, null));
tsHelpers.add(new TsHelper(Collections.singletonList("export const " + tsBeanAdditionalName + ":" + tsConstructorBeanName)));
}
}
if (!Strings.isNullOrEmpty(tsBeanName) && !tsBeanName.equals(tsBean.getName().getSimpleName()))
{
tsBundleProperties.add(new TsPropertyModel(tsBeanName,
new TsType.ReferenceType(new Symbol(tsConstructorBeanName)), null, true, null));
/*
tsHelpers.add(new TsHelper(Collections.singletonList("export const " + tsBeanName + ":" + tsConstructorBeanName)));
Generate part (with or without generic parameters):
if (tsBeanTypeParametersWithBounds.isEmpty())
{
tsHelpers.add(
new TsHelper(Collections.singletonList("type " + tsBeanName + " = " + tsBean.getName().getSimpleName())));
} else
{
String tsBeanTypeParametersWithBoundsString =
tsBeanTypeParametersWithBounds.stream().map(TsType::toString).collect(Collectors.joining(","));
String tsBeanTypeParametersWithoutBoundsString =
tsBeanTypeParametersWithoutBounds.stream().map(TsType::toString).collect(Collectors.joining(","));
tsHelpers.add(new TsHelper(Collections.singletonList(
"type " + tsBeanName + "<" + tsBeanTypeParametersWithBoundsString + "> = " + tsBean.getName()
.getSimpleName() + "<" + tsBeanTypeParametersWithoutBoundsString + ">")));
}
}
type a_b_c_X<T> = X<T>
*/
if (tsBeanTypeParametersWithBounds.isEmpty())
{
tsHelpers.add(
new TsHelper(Collections.singletonList("type " + tsBeanAdditionalName + " = " + tsBean.getName().getSimpleName())));
} else
{
String tsBeanTypeParametersWithBoundsString =
tsBeanTypeParametersWithBounds.stream().map(TsType::toString).collect(Collectors.joining(","));
String tsBeanTypeParametersWithoutBoundsString =
tsBeanTypeParametersWithoutBounds.stream().map(TsType::toString).collect(Collectors.joining(","));
tsHelpers.add(new TsHelper(Collections.singletonList(
"type " + tsBeanAdditionalName + "<" + tsBeanTypeParametersWithBoundsString + "> = " + tsBean.getName()
.getSimpleName() + "<" + tsBeanTypeParametersWithoutBoundsString + ">")));
}
tsBeanMethods.sort(Comparator.comparing(TsMethodModel::getName).thenComparing(m -> m.getParameters().size())
......@@ -487,6 +515,23 @@ public class OpenBISExtension extends Extension
continue;
}
/*
Generate part:
interface XObject {
VALUE1:X,
VALUE2:X
}
bundle {
...
X:XObject,
...
}
*/
String tsEnumObjectBeanName = tsEnum.getName().getSimpleName() + "Object";
List<TsPropertyModel> tsEnumObjectBeanProperties = new ArrayList<>();
List<String> tsEnumConstProperties = new ArrayList<>();
......@@ -511,6 +556,19 @@ public class OpenBISExtension extends Extension
tsBundleProperties.add(new TsPropertyModel(tsEnum.getName().getSimpleName(),
new TsType.ReferenceType(new Symbol(tsEnumObjectBeanName)), null, true, null));
/*
Generate part:
const X = {
VALUE1 : "VALUE1",
VALUE2 : "VALUE2"
} as const
type X = typeof X[keyof typeof X];
*/
tsHelpers.add(new TsHelper(
Collections.singletonList(
"const " + tsEnum.getName().getSimpleName() + " = {\n" + String.join(",\n", tsEnumConstProperties) + "} as const")));
......@@ -518,19 +576,39 @@ public class OpenBISExtension extends Extension
"type " + tsEnum.getName().getSimpleName() + " = typeof " + tsEnum.getName().getSimpleName() + "[keyof typeof "
+ tsEnum.getName().getSimpleName() + "]")));
String tsEnumJsonName = tsEnumJsonObject.value().replaceAll("\\.", "_");
String tsEnumAdditionalName = tsEnumJsonObject.value().replaceAll("\\.", "_");
/*
Generate part:
const a_b_c_X = {
VALUE1 : "VALUE1",
VALUE2 : "VALUE2"
} as const
type a_b_c_X = typeof a_b_c_X[keyof typeof a_b_c_X];
bundle {
...
a_b_c_X:XObject
...
}
*/
if (!tsEnumJsonName.equals(tsEnum.getName().getSimpleName()))
if (!tsEnumAdditionalName.equals(tsEnum.getName().getSimpleName()))
{
tsBundleProperties.add(new TsPropertyModel(tsEnumJsonName,
tsBundleProperties.add(new TsPropertyModel(tsEnumAdditionalName,
new TsType.ReferenceType(new Symbol(tsEnumObjectBeanName)), null, true, null));
tsHelpers.add(
new TsHelper(Collections.singletonList(
"const " + tsEnumJsonName + " = {\n" + String.join(",\n", tsEnumConstProperties) + "} as const")));
"const " + tsEnumAdditionalName + " = {\n" + String.join(",\n", tsEnumConstProperties) + "} as const")));
tsHelpers.add(new TsHelper(Collections.singletonList(
"type " + tsEnumJsonName + " = typeof " + tsEnumJsonName + "[keyof typeof "
+ tsEnumJsonName + "]")));
"type " + tsEnumAdditionalName + " = typeof " + tsEnumAdditionalName + "[keyof typeof "
+ tsEnumAdditionalName + "]")));
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment